// JavaScript Document

var welcomepanelsTimeoutID = 0;
var next;
var current;
var welcomePanelTimeout = 10;

function initWelcomePanels() {
	//Set the opacity of all images to 0
	jQuery('div#welcomepanels ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	jQuery('div#welcomepanels ul li:first').css({opacity: 1.0});
		
	//Call the welcomepanels function to run the slideshow, 6000 = change to next image after 6 seconds
	//setInterval('rotate()',6000);
	welcomepanelsTimeoutID = setTimeout('showPanel()',welcomePanelTimeout * 1000);
	
}

function showPanel(pindex) {	
	//Get the first image
	current = (jQuery('div#welcomepanels ul li.show')?  jQuery('div#welcomepanels ul li.show') : jQuery('div#welcomepanels ul li:first'));

	if(pindex > 0)
	{
		clearTimeout ( welcomepanelsTimeoutID );
		next = jQuery('div#welcomepanels ul li:eq(' + (pindex - 1) + ')');
	}
	else
	{
		//Get next image, when it reaches the end, rotate it back to the first image
		next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div#welcomepanels ul li:first') :current.next()) : jQuery('div#welcomepanels 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');
	
	welcomepanelsTimeoutID = setTimeout('showPanel()', welcomePanelTimeout * 1000);
	
};

jQuery(document).ready(function() {		
	//Load the slideshow
	initWelcomePanels();
	
	jQuery('div#welcomepanels ul li').each(function(idx, e)
	{
		jQuery("div.panel_buttons").append('<div class="panel_button"></div>');
	});
	
	jQuery('div.panel_button').each(function(idx, e){
			
		jQuery(this).click(function()
		{
			showPanel(idx + 1);
		});
	
	});

});
