
function toggle(visible, hidden) {
    document.getElementById(visible).style.display = "";
    document.getElementById(hidden).style.display = "none";
}

var interval = 0;

//preload the images for top
$(".car_item > a:even").each(function() {
	
	$("<img>").attr("src", $(this).attr("href"));
});

function ChangeTop(elt)
{
	 $(".car_item").attr("id","");
	 $(elt).attr("id","car_item_a");
	 var img = $($("#car_item_a > a")[0]).attr("href"); 
	 $("#carimage").attr("src",img);
}

function StartCycle()
{
 //set cycle
	if(!interval)
	{
		interval = setInterval(function() {
				//get index to show
				var n = ($('.car_item').index($('#car_item_a')[0]) + 1) % 5; 
				ChangeTop($(".car_item").get(n));
			},4000);
	}
}

function StopCycle()
{
		if(interval)
		{
			clearInterval(interval);
			interval = 0;
		}
}
//make cycle stop on mouseover car_item 
//and change the image
$(".car_item").mouseover(function() {
	  //stop animation
	  StopCycle();
		ChangeTop(this);
});

//make cycle run again on mouseout car_item
$(".car_item").mouseout(function() {
	  //stop animation
	  StartCycle();
});


//start cycling only if on homepage
//if($(".car_item").length > 0)
	StartCycle();



