var MENU_ANIMATE_HEIGHT = null;
var MENU_BACKGROUND_POS = null;
$(function(){
	Cufon.replace('#menu-top a', {hover: true, fontFamily: 'Futura', fontWeight: 'normal'});
	Cufon.replace('.futura-light, .futura', {fontFamily: 'Futura', fontWeight: 'normal'});
	Cufon.replace('.futura-bold', {fontFamily: 'Futura', fontWeight: 'bold'});
	Cufon.replace('.futura strong', {fontFamily: 'Futura', fontWeight: 'bold'});
	Cufon.now();
	$('a.sprite.hover').mouseover(
		function(){
			height = parseInt($(this).css('height'));
			background = $(this).css('backgroundPosition');
			if(background == undefined){
				background = $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
			}
			background_y = background.match(/(-?[0-9]{1,6})px (-?[0-9]{1,6})px/);
			if(background_y[2] != undefined){
				MENU_BACKGROUND_POS = background;
				x = background_y[1]
				y = background_y[2] - height;
				pos = x + 'px ' + y + 'px';
				$(this).css({backgroundPosition: pos});
				//$(this).stop().animate({backgroundPosition: pos}, 1);
			}
		}).mouseout(
		function(){
				pos = MENU_BACKGROUND_POS;
				$(this).css({backgroundPosition: pos});
				//$(this).stop().animate({backgroundPosition: pos}, {duration: 100, complete: function(){}});
		}
	);
	
	// menu effect
	/*pos = $('#menu-top a.active').position();
	height = $('#menu-top a.active').css('height');
	width = parseInt($('#menu-top a.active').css('width')) - 9 + 'px';
	$('#menu-top-background').css({
		 height: height,
		 width: width,
		 left: pos.left + 'px',
		 padding: '5px 7px',
		 borderRadius: '4px',
		 zIndex: -10
	});
		
	
	$('#menu-top a').mouseover(function(){
		setMenuBackground($(this));
	});*/
	
	$('.form .input, .form textarea').each(function(){
		val = $(this).val();
		$(this).addClass('unclicked');
	 	//$(this).val('<span>' + val + '</span>');
	});
	
	$('.form .unclicked').click(function(){
		$(this).val('');
	});
	
	$('.form .submit').click(function()
	{
		$(this).val('Waiting ...');
		$(this).attr('disabled','disabled');
		$(this).addClass('disabled');
		lastname = $('#lastname').val();
		firstname = $('#firstname').val();
		phone = $('#phone').val();
		email = $('#email').val();
		message = $('#message').val();
		$.ajax(
		{
			url: "sendcontact.php5",
			type: 'POST',
			dataType: "text",
			data: 
			{
			lastname:		lastname,
			firstname:   firstname,
			phone:    phone,
			email:    email,
			message: message
			},
			success: function(data) 
			{
				$('.form .submit').val('Message sent!');
			}
		});
		return false;
	});
});

function setMenuBackground(elem){
	pos = elem.position();
	height = elem.css('height');
	width = parseInt(elem.css('width')) + 9 + 'px';
	$('#menu-top a.active').removeClass('active');
	$('#menu-top-background').stop().animate({
		 left: pos.left + 'px',
		 top: pos.top + 'px',
		 width: width
	}, 100,'swing', function(){
		elem.addClass('active');
		Cufon.refresh();
	});
}


(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

