/* This script works with slideshow.php to create a simple but cool
slideshow of photos in a particular direcory */

var photo, caption, preload, timer, pbutton;
var count = 0;
var play = false;

function init() {
	photo = document.getElementById("photo");
	caption = document.getElementById("caption_text");
	// Image object doesn't seem to work right, so I preload a hidden img
	preload = document.getElementById("preload");
	pbutton = document.getElementById("play");
	preload.src = photopath+photos[1];
}

function nextPhoto() {
	count += 1;
	if (count == total) count = 0;
	photo.src = photopath+photos[count];
	caption.innerHTML = captions[count];
	if (count == total-1) preload.src = photopath+photos[0];
	else preload.src = photopath+photos[count+1];
	if (play) timer = setTimeout(nextPhoto,5000);
	return;
}

function lastPhoto() {
	// Preload not used here since normally not necessary
	count -= 1;
	if (count < 0) count = total - 1;
	photo.src = photopath+photos[count];
	caption.innerHTML = captions[count];
	if (play) player();
}


function player() {
	// Also works as stop function if playing
	if (play) {
		play = false;
		pbutton.innerHTML = "Play";
		pbutton.style.color = "green";
		timer = false;
	}
	else {
		pbutton.innerHTML = "Stop";
		pbutton.style.color = "red";
		play = true;
		nextPhoto();
	}
}

function zoom() {
	window.open(photopath+photos[count],"zoomwindow","status=0,toolbar=0,menubar=0,width=850,height=640,location=0");
}
