// slideshow params 
var currentSlide = 1;
var numSlides = 4;
var pause = false;
var tspeed = 4000;

function pause_show(bool){
	pause = bool;
}

// transitions the slides 
function update_slideshow(slide){
	if(slide > numSlides){ 
		slide = 1;
		tspeed = 8000; //if the show has cycled once, slow down the transition speed
	}
	
	//is user tyring to pause/play this slide
	if(currentSlide == slide){
		if(pause){
			$("#ssbut" + slide.toString()).removeClass('play').addClass('pause');
			pause = false;
		}else{
			$("#ssbut" + slide.toString()).removeClass('pause').addClass('play');
			pause = true;
		}
	}else{ //user clicked on a button other than the current slide's
		clearTimeout(slideTimer);
		function complete() {
			$("#slide" + slide.toString()).fadeIn(500, "linear");
			if(!pause)	
				$("#ssbut" + slide.toString()).removeClass('inactive').addClass('pause');
			else
				$("#ssbut" + slide.toString()).removeClass('inactive').addClass('play');
		}	
		$("#ssbut" + currentSlide.toString()).removeClass('play').addClass('inactive');
		$("#slide" + currentSlide.toString()).fadeOut(300, "linear", complete);
		
		currentSlide = slide;
		if (typeof(slideTimer) != 'undefined') clearTimeout(slideTimer);
		slideTimer = setTimeout("slideshow()",tspeed);
	}
}

function slideshow(){
	if (typeof(slideTimer) != 'undefined') clearTimeout(slideTimer);
	
	if(!pause)
		update_slideshow(currentSlide + 1);
}
var slideTimer = setTimeout("slideshow()",tspeed);
