/*
 * randomSlide
 *
 * this function creates a slide show, buy displaying a random slide
 * every ten seconds.  This is accomplished by recursively by having this function
 * call itself every ten seconds.
 * 
 */
function randomSlide() {
	if (random_continue)
	{
		current_slide_id = Math.random()*slide_show_data.length;
		current_slide_id = Math.floor(current_slide_id);
	
		setSlide();
		setTimeout('randomSlide()', 10000);
	}
}

/*
 * nextSlide
 *
 * stops the random slide display, increments the slide show id, and has the 
 * the show updated to the new slide.
 * 
 */
function nextSlide() {
	// turn off the slide show
	random_continue = false;
	
	current_slide_id++;

	// wrap to the first slide, if need be	
	if (current_slide_id >= slide_show_data.length)
	{
		current_slide_id = 0;
	}

	setSlide();
}

/*
 * previousSlide
 *
 * stops the random slide display, decrements the slide show id, and has the 
 * the show updated to the new slide.
 * 
 */
function previousSlide() {
	// turn off the slide show
	random_continue = false;	
	
	current_slide_id--;

	// wrap to the last slide, if need be	
	if (current_slide_id < 0)
	{
		current_slide_id =  slide_show_data.length - 1;
	}

	setSlide();
}

/*
 * setSlide
 *
 * updates the live HTML of the webpage to display a new slide
 * 
 */
function setSlide() {
	// get a reference to the slideshow image
	var slide = document.getElementById("slide");

	// change it to the new slide's image src
	slide.src = slide_show_data[current_slide_id][0];
	
	// get a reference to the text accompanying the image
	var slide_info = document.getElementById("slideshow_info");
	
	// update its contents to the text accompanying the image
	slide_info.innerHTML = slide_show_data[current_slide_id][1] +
							"&nbsp;&nbsp;&nbsp;<a href=" +
							slide_show_data[current_slide_id][2] +
							">more...</a>";
}



/*
 * WINDOW BEHAVIOR ADDING
 * ======================
 * These functions specify the onload behavior for the page.
 */

function slideshowOnLoad() {
	// only load slideshow behaviors if there is a slideshow on the page
	if(document.getElementById("slideshow") != null)
	{
		// display the slide show controls
		var ss_controls = document.getElementById("slide_show_controls");
		ss_controls.style.display = "";

		// start the slide show after ten seconds
		setTimeout('randomSlide()', 10000);
	}
}

window.onload = function() {
	if(document.getElementById("slideshow") != null)
		slideshowOnLoad();
}