/*
This Javascript controls the display of the slideshow on the home page.
*/

$(document).ready(function()
{

	/******************************
		INITIALIZE
	*******************************/
	var numSlides = 5; /* Edit this value as needed */
	var slideNum = 1; /* Display first slide */
	
	$('div#slideshow ul#slideshow-buttons').show();
	
	
	/******************************
		DEFINE FUNCTIONS
	*******************************/
	// Hide all of the slides
	function hideAllSlides()
	{
		for( i=1; i <= numSlides; i++)
		{
			$('#slideshow #slide-'+i).hide();
		}
	}
	
	// Fade all of the slides
	function fadeAllSlides()
	{
		for( i=1; i <= numSlides; i++)
		{
			$('#slideshow #slide-'+i).fadeOut('fast');
		}
	}
	
	// Hide all of the slideshow selector buttons
	function turnButtonsOff()
	{
		for( i=1; i <= numSlides; i++)
		{
			$('div#slideshow ul#slideshow-buttons li#slide-btn-' + i).removeClass('active-slide-btn').addClass('inactive-slide-btn');
		}
	};
	
	
	// Display the slide passed via the function argument 
var slideShow =	function()
	{
		hideAllSlides();
		++slideNum;
		$('#slideshow #slide-' + slideNum).fadeIn('slow');
		
		// When the last slide is displayed, loop to the beginning.
		if(slideNum > numSlides)
		{
			slideNum = 1;
		}
		$('#slideshow #slide-' + slideNum).fadeIn(800);
		
/*		
		if(slideNum == numSlides)
		{
			clearInterval(slideShowTimer);
		}
*/		
		
		turnButtonsOff();
		$('div#slideshow ul#slideshow-buttons li#slide-btn-' + slideNum).addClass('active-slide-btn');
		
	}; // end slideShow()
	

	
/*	
	// Display the active slide button
	function displaySlideButton(btnNum)
	{
		turnButtonsOff();
		$('div#slideshow ul#slideshow-buttons li#slide-btn-' + btnNum).removeClass('inactive-slide-btn').addClass('active-slide-btn');
	}; // end displaySlideButton()
*/

	/*************************************
		USER FIRST ARRIVES AT THE PAGE
	**************************************/
	//hideAllSlides();
	// Display the first slide
	//$('#slideshow #slide-' + slideNum).fadeIn('slow');
	// Start the slideshow
	var slideShowTimer = setInterval(slideShow, 7500);	
	// If user clicks on a slide button, display the associated slide.
	// "slideNum" is passed from slideshow selector buttons
	$('div#slideshow ul#slideshow-buttons li#slide-btn-' + slideNum).addClass('active-slide-btn');
	
	
	/*************************************
		SLIDESHOW BUTTONS
	**************************************/
	// Display the selected slide
	$('div#slideshow ul#slideshow-buttons li#slide-btn-1').click(function()
		 {
			 hideAllSlides();
			 turnButtonsOff();
			 $(this).removeClass('inactive-slide-btn').addClass('active-slide-btn');
			 $('#slideshow #slide-1').fadeIn('slow');
			 clearInterval(slideShowTimer);
		 }
	 );
	
	$('div#slideshow ul#slideshow-buttons li#slide-btn-2').click(function()
		 {
			 hideAllSlides();
			 turnButtonsOff();
			 $(this).removeClass('inactive-slide-btn').addClass('active-slide-btn');
			 $('#slideshow #slide-2').fadeIn('slow');
			 clearInterval(slideShowTimer);
		 }
	 );
	
	$('div#slideshow ul#slideshow-buttons li#slide-btn-3').click(function()
		 {
			 hideAllSlides();
			 turnButtonsOff();
			 $(this).removeClass('inactive-slide-btn').addClass('active-slide-btn');
			 $('#slideshow #slide-3').fadeIn('slow');
			 clearInterval(slideShowTimer);
		 }
	 );
	
	$('div#slideshow ul#slideshow-buttons li#slide-btn-4').click(function()
		 {
			 hideAllSlides();
			 turnButtonsOff();
			 $(this).removeClass('inactive-slide-btn').addClass('active-slide-btn');
			 $('#slideshow #slide-4').fadeIn('slow');
			 clearInterval(slideShowTimer);
		 }
	 );
	 
	 $('div#slideshow ul#slideshow-buttons li#slide-btn-5').click(function()
		 {
			 hideAllSlides();
			 turnButtonsOff();
			 $(this).removeClass('inactive-slide-btn').addClass('active-slide-btn');
			 $('#slideshow #slide-5').fadeIn('slow');
			 clearInterval(slideShowTimer);
		 }
	 );
	

}); // end document.ready
