jQuery(document).ready(function ()
{	
	jQuery('img.roundy').roundy();
	
	var menushow = false;
	var menutimeout;
	
	jQuery('ul#mainnav li a.enginebase').hover(function()
	{
		
		clearTimeout(menutimeout);
		
		if(!menushow)
		{
			jQuery('ul#enginebase').stop().css(
			{
				'top' 		: 125 + 'px',
				'opacity' : 0,
				'height' 	: 100 + 'px'
			});
			jQuery('ul#enginebase').stop().animate(
			{
				'top' 		: 65 + 'px',
				'opacity' : 1,
				'height' 	: 270 + 'px'
			},
			{
				easing 		: 'easeOutBack',
				duration 	: 400
			});
			menushow = true;
		}
	}, function()
	{
		menutimeout = setTimeout(function()
		{
			jQuery('ul#enginebase').stop().animate(
			{
				'top' 		: 125 + 'px',
				'opacity' : 0,
				'height' 	: 100 + 'px'
			},
			{
				easing 		: 'easeInExpo',
				duration 	: 250,
				complete 	: removeDisplay
			});
			menushow = false;
		}, 500);
	});
	
	jQuery('ul#enginebase').hover(function()
	{
		clearTimeout(menutimeout);
	}, function()
	{
		menutimeout = setTimeout(function()
		{
			jQuery('ul#enginebase').stop().animate(
			{
				'top' 		: 125 + 'px',
				'opacity' : 0,
				'height' 	: 100 + 'px'
			},
			{
				easing 		: 'easeOutExpo',
				duration 	: 250,
				complete 	: removeDisplay
			});
			menushow = false;
		}, 500);
	});
	
	function removeDisplay()
	{
		jQuery('ul#enginebase').css('display', 'none');
	}
			
	setTimeout(function()
	{
		jQuery('div.promotion').slideDown(
		{
			duration	: 600,
			'easing'	: 'easeOutExpo'
		});
	}, 500);
	
	jQuery('#newentries').accordion(
	{
		active: false,
		alwaysOpen: false,
		header: '.head',
		autoheight: false
	});
	
	jQuery("#filter_keyword").keyup(function()
	{
		var filter = jQuery(this).val(), count = 0;
		jQuery(".models:first li").each(function()
		{
			if(jQuery(this).text().search(new RegExp(filter, "i")) < 0)
			{
				jQuery(this).addClass("hidden");
			}
				else
			{
				jQuery(this).removeClass("hidden");
				count++;
			}
		});
	});
	
	jQuery('#paypal').click(function()
	{
		jQuery('#place_order').attr('disabled', 'disabled');
		
		jQuery.post("http://www.kochtuning.com/enginebase/enginebase.html",
		{
			func: 'place_order',
			token: jQuery('#token').val(),
			secret: jQuery('#secret').val()
		},
		function(data)
		{
			jQuery('#paypal').submit();
		})
		return false;
	});
	
});

function setFilter()
{
	var filter = jQuery("#filter_keyword").val(), count = 0;
	
	jQuery(".models:first li").each(function()
	{
		if(jQuery(this).text().search(new RegExp(filter, "i")) < 0)
		{
			jQuery(this).addClass("hidden");
		}
			else
		{
			jQuery(this).removeClass("hidden");
			count++;
		}
	});
};
	
function blockEnter(evt)
{
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13)
	{
		return false;
	}
}

