/* Slideshow.js
 * This script handles the image slideshow in the cemetery database
 * It replaces the source for the image and the link with the next image
 * Image information is pulled from an invisible select box on the cemetery page
 * 
 * Last edited: Tuesday 3rd May, 2011, Joshua Geerlofs
 */

var rotate_delay = 5000; // delay in milliseconds (5000 = 5 secs) - UNUSED
var imagedir = '../sites/default/modules/cemeteries/Images/'; // Directory images are kept in
current = 0;

// Show the next image
function next() {
if (document.slideform.slide[current+1]) {
	var newsrc = imagedir + document.slideform.slide[current+1].value;
	document.images.show.src = newsrc; // Change the image
	document.getElementById('photolink').href = newsrc; // Update the link
	//document.links["photolink"].href = newsrc;
	document.slideform.slide.selectedIndex = ++current; // Remember the current image
   }
else first(); // If the last image in the slideshow, display the first one
}


// Show the previous image
function previous() {
if (current-1 >= 0) {
	var newsrc = imagedir + document.slideform.slide[current-1].value;
	document.images.show.src = newsrc;
	document.getElementById('photolink').href = newsrc;
	//document.links["photolink"].href = newsrc;
	document.slideform.slide.selectedIndex = --current;
   }
else last(); // If the first image, display the last one
}


// Show the first image in the slideshow
function first() {
	current = 0;
	var newsrc = imagedir + document.slideform.slide[0].value;
	document.images.show.src = newsrc;
	document.getElementById('photolink').href = newsrc;
	//document.links["photolink"].href = newsrc;
	document.slideform.slide.selectedIndex = 0;
}


// Show the last image in the slideshow
function last() {
	current = document.slideform.slide.length-1;
	var newsrc = imagedir + document.slideform.slide[current].value;
	document.images.show.src = newsrc;
	document.getElementById('photolink').href = newsrc;
	//document.links["photolink"].href = newsrc;
	document.slideform.slide.selectedIndex = current;
}


// Unused - handles start/stop buttons
function ap(text) {
	document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
	rotate();
}


// Unused - handles changing image on select box change
function change() {
	current = document.slideform.slide.selectedIndex;
	document.images.show.src = imagedir + document.slideform.slide[current].value;
}


// Unused - automatically cycles the images
function rotate() {
	if (document.slideform.slidebutton.value == "Stop") {
		current = (current == document.slideform.slide.length-1) ? 0 : current+1;
		document.images.show.src = document.slideform.slide[current].value;
		document.slideform.slide.selectedIndex = current;
		window.setTimeout("rotate()", rotate_delay);
	   }
}
