$(document).ready(function() {
	// load images
	load_image();
	//Load the slideshow
	theRotator();
	return false;
	
});


function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

function load_image() {	
		preload_image_object = new Image();
		// set image 
	      image_icon = new Array();
		  image_icon[0] = "photos/ico_MEBT-30-Steering-Wheel.jpg";
		  image_icon[1] = "photos/ico_MEBT-60-Solar-Components-Box.jpg";
		  image_icon[2] = "photos/ico_MEBT-66-Soccer-Ball.jpg";
		  image_icon[3] = "photos/ico_MEBT-99-Inside-Box.jpg";
		  image_icon[4] = "photos/ico_MEBT-100-Bluetooth-Visor.jpg";
		  image_icon[5] = "photos/ico_MEBT-900-Rear-View.jpg";
		  image_icon[6] = "images/mediano_logo.png";
		  image_icon[7] = "images/btn_view_info.png";
		  image_icon[8] = "photos/featured_img.png";
		  image_icon[9] = "photos/MEBT-30-Steering-Wheel.jpg";
		  image_icon[10] = "photos/MEBT-60-Solar-Components-Box.jpg";
		  image_icon[11] = "photos/MEBT-66-Soccer-Ball.jpg";
		  image_icon[12] = "photos/MEBT-99-Inside-Box.jpg";
		  image_icon[13] = "photos/MEBT-100-Bluetooth-Visor.jpg";
		  image_icon[14] = "photos/MEBT-900-Rear-View.jpg";
		  image_icon[15] = "photos/tn_MEBT-30-Steering-Wheel.jpg";
		  image_icon[16] = "photos/tn_MEBT-60-Solar-Components-Box.jpg";
		  image_icon[17] = "photos/tn_MEBT-66-Soccer-Ball.jpg";
		  image_icon[18] = "photos/tn_MEBT-99-Inside-Box.jpg";
		  image_icon[19] = "photos/tn_MEBT-100-Bluetooth-Visor.jpg";
		  image_icon[20] = "photos/tn_MEBT-900-Rear-View.jpg";
		  		  
		   var i = 0;
		   for(i=0; i<=20; i++) 
		       preload_image_object.src = image_icon[i];
}