sPath = "http://pamm.wustl.edu/slideshows/"+slideshowName+"/";

totalImages = cutlines.length;

//this bit of code preloads the images for better results
i = 1;
while (i <= totalImages){
	(new Image()).src = sPath+"images/"+i+".jpg";
	i++;
}
(new Image()).src = "http://pamm.wustl.edu/slideshows/images/right-play.gif";

onImage = 1;

function changeImage(how){
	//change image
	if (how == "previous"){
		if (onImage == 1){
			onImage = totalImages;
			document.getElementById("dynImg").src = sPath+"images/"+onImage+".jpg";
		}
		else {
			onImage--;
			document.getElementById("dynImg").src = sPath+"images/"+onImage+".jpg";
		}
	}
	else if (how == "next"){
		if (onImage == totalImages){
			onImage = 1;
			document.getElementById("dynImg").src = sPath+"images/1.jpg";
		}
		else {
			onImage++;
			document.getElementById("dynImg").src = sPath+"images/"+onImage+".jpg";
		}
	}

	//update cutline
	n = onImage-1;
	document.getElementById("cutline").innerHTML = cutlines[n];
	
	//show or hide downlaod button
	if (allHires){
		document.getElementById("download").style.color = "#990000";
		document.getElementById("download").style.cursor = "pointer";
		document.getElementById("download").innerHTML = "DOWNLOAD IMAGE";
		document.getElementById("download").onmouseup = hiresLink;
	}
	else {
		ckHires = false;
		for (j=0; j<hiresImages.length;j++){
			if (onImage == hiresImages[j]){
				ckHires = true;
			}
		}
		if (ckHires){
			document.getElementById("download").style.color = "#990000";
			document.getElementById("download").style.cursor = "pointer";
			document.getElementById("download").innerHTML = "DOWNLOAD IMAGE";
			document.getElementById("download").onmouseup = hiresLink;
		}
		else {
			document.getElementById("download").style.color = "#cccccc";
			document.getElementById("download").style.cursor = "auto";
			document.getElementById("download").innerHTML = "DOWNLOAD NOT AVAILABLE";
			document.getElementById("download").onmouseup = "return false;";
		}
	}
	
	if (how != "start"){
		fadeIn();
	}
	else {
		document.getElementById("dynImg").src = sPath+"images/"+onImage+".jpg";
	}
}

function hiresLink(){
	//stopSlideshow();
	location.href= sPath+"hiresImages/"+onImage+".jpg";
}

autoplaying = false;

function startSlideshow(){
	if (!autoplaying){
		autoplaying = true;
		document.getElementById("playButton").src = "http://pamm.wustl.edu/slideshows/images/right-play.gif";
		fadeOut('next');
		autoPlay = setInterval("fadeOut('next')",6000);
	}
}

function stopSlideshow(){
	document.getElementById("playButton").src = "http://pamm.wustl.edu/slideshows/images/right.gif";
	if (autoplaying){
		clearInterval(autoPlay);
	}
	autoplaying = false;
}

fadingOut = false;
IEop = 100;

function fadeOut(dir){
	if (!fadingOut){
		if (navigator.appName == "Microsoft Internet Explorer"){
			document.getElementById("dynImg").style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+IEop+")";
		}
		else {
			document.getElementById("dynImg").style.opacity = "1";
		}
		
		if (dir == "next"){
			fadingOut = setInterval("fadeOut('next')",50);
		}
		else {
			fadingOut = setInterval("fadeOut('previous')",50);
		}
	}
	else {
		if (navigator.appName == "Microsoft Internet Explorer"){
			IEop -= 10;
			opacity = IEop;
		}
		else {
			opacity = parseFloat(document.getElementById("dynImg").style.opacity);
			opacity -= .1;
		}
		
		if (opacity >= 0){
			if (navigator.appName == "Microsoft Internet Explorer"){
				document.getElementById("dynImg").style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+IEop+")";
			}
			else {
				document.getElementById("dynImg").style.opacity = opacity;
			}
		}
		else {
			IEop = 0;
			clearInterval(fadingOut);
			fadingOut = false;
			if (dir == "next"){
				changeImage("next");
			}
			else {
				changeImage("previous");
			}
		}	
	}
}

fadingIn = false;

function fadeIn(){
	if (!fadingIn){
		if (navigator.appName == "Microsoft Internet Explorer"){
			document.getElementById("dynImg").style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+IEop+")";
		}
		else {
			document.getElementById("dynImg").style.opacity = "0";
		}
		
		fadingIn = setInterval("fadeIn()",50);
	}
	else {
		if (navigator.appName == "Microsoft Internet Explorer"){
			IEop += 10;
			
			if (IEop <= 100){
				document.getElementById("dynImg").style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+IEop+")";
			}
			else {
				IEop = 100;
				clearInterval(fadingIn);
				fadingIn = false;
			}	
		}
		else {
			opacity = parseFloat(document.getElementById("dynImg").style.opacity);
			opacity += .1;
			
			if (opacity <= 1){
				document.getElementById("dynImg").style.opacity = opacity;
			}
			else {
				clearInterval(fadingIn);
				fadingIn = false;
			}	
		}
	}
}

changeImage("start");