rotateInterval = ""
rotationDuration = 7500;
$(document).ready(function() {		
	//Load the slideshow

	$('#rotation div.panel').hover(function(){pauseRotation()},function(){playRotation()})

	//Set the opacity of all images to 0
	//This prevents phantom images from displaying during the transition
	$('div#rotation div.panel').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotation div.panel:first').css({opacity: 1.0});
	
	playRotation()
});

function rotate(count) {	
	//Get the first image
	var current = ($('div#rotation div.show')?  $('div#rotation div.show') : $('div#rotation div.panel:first'));
	
	if(count == 1)
	{
		//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#rotation div.panel:first') :current.next()) : $('div#rotation div.panel:first'));
	} else {
		var next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#rotation div.panel:last') :current.prev()) : $('div#rotation div.panel:last'));
	}
	
	//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');
	pauseRotation()
	playRotation()
};

function pauseRotation()
{
	if($('div#rotation div.panel').length > 1) clearInterval(rotateInterval)
}

function playRotation()
{
	if($('div#rotation div.panel').length > 1) rotateInterval = setInterval('rotate(1)',rotationDuration);
}


