var displayTime = 5000;		// Duration of each slide in milliseconds; 1000 milliseconds = 1 second.
var transTime = 1000;		// Duration of transition in milliseconds; 1000 milliseconds = 1 second.


// Don't mess with anything below this point unless you
// intend to modify the functionality of the script.

$(function()
{
	// Get all the slides in #slideBox.
	var slides = $('#slideBox .slide');
	
	// fadeOut all slides except the first one.
	for (i = 1; i < slides.length; i++)
	{
		$(slides[i]).fadeOut(0);
	}
	
	// This function is called in the variable "int" below.
	function slideShow()
	{
		// If we haven't reached the last slide,
		if (j < slides.length)
		{
			// then fadeIn the next slide,
			$(slides[j]).fadeIn(transTime);
			
			// and increase the counter for the next go-round.
			j++;
		}
		
		// If we have reached the last slide,
		else
		{
			// then get all of the slides EXCEPT the first and last ones,
			for (k = 1; k < slides.length-1; k++)
			{
				// and fade them out.
				$(slides[k]).fadeOut(0);
			}
			
			// Then fadeOut the last slide, revealing the first slide underneath.
			$(slides[slides.length-1]).fadeOut(transTime);
			
			// Reset the counter.
			j = 1;
		}
	}
	
	// Set the initial counter value for slideShow() function.
	var j = 1;
	
	// Call slideShow() at the interval set in displayTime.
	var int = setInterval(slideShow, displayTime);
});