// JavaScript Document

// begin the slideshow loop
/*function slideshowBegin(slideshow, start, end, delay) {
	
	// set timeout function with specified values
	setTimeout("slideshowEffect(" + slideshow + ", " + start + ", " + start + ", " + end + ", " + delay + ")", delay);
}

// perform the slide transition
function slideshowEffect(slideshow, slide, start, end, delay) {
		
	// fade out the current slide
	new Effect.Fade($("slide_" + slideshow + "_" + slide), { duration:1 });
	
	// determine what the next slide should be
	if(slide == end) slide = start;
	else slide++;
	
	// fade in the next slide
	new Effect.Appear($("slide_" + slideshow + "_" + slide), { duration:1 });
	
	// delay the next transition for the specified interval (the length of the transition must be added to the delay)
	setTimeout("slideshowEffect(" + slideshow + ", " + slide + ", " + start + ", " + end + ", " + delay + ")", delay+1000);
}*/

// declare variables used for the slideshow
var currentSlide = 1;
var slideshowTimer = "";

// begin the slideshow loop
function slideshowBegin(slideshow, start, end, delay) {
	
	// set timeout function with specified values
	if(slideshow == 99999) {
		slideshowTimer = setTimeout("slideshowEffect(" + slideshow + ", " + start + ", " + start + ", " + end + ", " + delay + ")", delay);
	} else {
		setTimeout("slideshowEffect(" + slideshow + ", " + start + ", " + start + ", " + end + ", " + delay + ")", delay);
	}
}

// perform the slide transition
function slideshowEffect(slideshow, slide, start, end, delay) {
		
	// fade out the current slide
	new Effect.Fade($("slide_" + slideshow + "_" + slide), { duration:1 });
	
	// determine what the next slide should be
	if(slide == end) slide = start;
	else slide++;
	
	// fade in the next slide
	new Effect.Appear($("slide_" + slideshow + "_" + slide), { duration:1 });
	
	// delay the next transition for the specified interval (the length of the transition must be added to the delay)
	if(slideshow == 99999) {
		slideshowTimer = setTimeout("slideshowEffect(" + slideshow + ", " + slide + ", " + start + ", " + end + ", " + delay + ")", delay+1000);
	} else {
		setTimeout("slideshowEffect(" + slideshow + ", " + slide + ", " + start + ", " + end + ", " + delay + ")", delay+1000);
	}
	
	// inventory slideshow only
	if(slideshow == 99999) {
	
		// store the current slide in a global variable
		currentSlide = slide;
		
		// update the slide display
		$("slideshowcounter").update("Photo " + slide + " of " + end);
	}
}

// pause the slideshow
function slideshowPause() {
	
	// clear the timer
	clearTimeout(slideshowTimer);
	
	// hide the pause button
	$("pausebutton").hide();
	
	// display the play button
	$("playbutton").show();
}

// resume the slideshow
function slideshowPlay(slideshow, start, end, delay) {
	
	// delay the next transition for the specified interval (the length of the transition must be added to the delay)
	slideshowTimer = setTimeout("slideshowEffect(" + slideshow + ", " + currentSlide + ", " + start + ", " + end + ", " + delay + ")", delay+1000);
	
	// hide the play button
	$("playbutton").hide();
	
	// display the pause button
	$("pausebutton").show();
}

// skip to the next slide
function slideshowNext(slideshow, start, end) {
	
	// pause the slideshow
	slideshowPause()
	
	// store the current slide number
	var slide = currentSlide;
	
	// hide the current slide
	$("slide_" + slideshow + "_" + slide).hide();
	
	// determine what the next slide should be
	if(slide == end) slide = start;
	else slide++;
	
	// show the next slide
	$("slide_" + slideshow + "_" + slide).show();
	
	// update the slide display
	$("slideshowcounter").update("Photo " + slide + " of " + end);
	
	// update the current slide counter
	currentSlide = slide;
}

// skip to the previous slide
function slideshowPrevious(slideshow, start, end) {
	
	// pause the slideshow
	slideshowPause()
	
	// store the current slide number
	var slide = currentSlide;
	
	// hide the current slide
	$("slide_" + slideshow + "_" + slide).hide();
	
	// determine what the next slide should be
	if(slide == start) slide = end;
	else slide--;
	
	// show the next slide
	$("slide_" + slideshow + "_" + slide).show();
	
	// update the slide display
	$("slideshowcounter").update("Photo " + slide + " of " + end);
	
	// update the current slide counter
	currentSlide = slide;
}

