/***************************
*
*	Top Car JS
*   KELLER & KOLLEGEN 2008
*
* *************************/
	
	/*
	* jQuery.delay
	*
	* Custom Delay Function
	*		
	*/
	(function($){$.delay={queue:[],timer:null,pause:function(){if(!$.delay.timer)return;
	clearInterval($.delay.timer);$.delay.timer=null;}};$.resume=function(interval){$.delay.pause();
	$.delay.timer=setInterval(function(){var fn=$.delay.queue.shift();fn?fn():$.delay.pause();},interval||10);};
	$.fn.delay=function(fn){var self=this;$.delay.queue.push(function(){self.each(fn);});return self;};})(jQuery);
		
	
	$(function() {
	
		delaySpeed = 150; // 

	/***************************
	*
	*	Top Car JS
	*
	* *************************/
	


	// hover function
	$(".small-list-box").livequery(function() {
		$(this).hoverIntent({
				sensitivity: 5, 
				interval: 30,   
				over: function () {	
									$(".big-list-box").hide();
									zIndexWorkaround();	
									$(this).parent().parent().css({zIndex:"1000"});
									$(this).next().fadeIn('slow'); 									
									
				},   
				timeout: 100,    
				out: function() { $(this).next().fadeOut('slow');}    
		 });
	});

	 // first init
	$(".top-car-box-list").html(TopMotos.GenerateTopMotosHTML().value);
	fadeInit();
	zIndexWorkaround();

	// magic function for crossbrowser z-Index functionality
	function zIndexWorkaround()	 {
		var blocks = $(".top-car-box-list li");
		 var zi = 999;		
		 if(blocks) {
			  blocks.each(function(i, block) {            
				 $(block).css({zIndex:""+zi+""});
			  });
		 }      
	}

	/*
	* fadeInit()
	*
	* FadeIn for each small list box
	*		
	*/
	function fadeInit() {
		
		$(".small-list-box").each(function() {				
				$(this).delay(function() {	$(this).fadeIn();	});
				$.resume(delaySpeed);		
		});
	}
	
		
	/*
	*	
	*	TopCar Refresh Event binds to .refresh-icon
	*
	*/
		$(".refresh-icon").click(function() {
				$(".top-car-box-list").html(TopMotos.GenerateTopMotosHTML().value);
				zIndexWorkaround();
				fadeInit(); // show results
				return false;
		});
	});	
