window.onload = initAll;

var currImg = 0;

var captionText = new Array();
captionText[0] = "";
captionText[1] = "";
captionText[2] = "";
captionText[3] = "";
captionText[4] = "";
captionText[5] = "";
captionText[6] = "";
captionText[7] = "";
captionText[8] = "";
captionText[9] = "";
captionText[10] = "";
captionText[11] = "";
captionText[12] = "";
captionText[13] = "";
captionText[14] = "";

var images = new Array();
images[0] = "100_4699.jpg";
images[1] = "100_4707.jpg";
images[2] = "100_4709.jpg";
images[3] = "100_4711.jpg";
images[4] = "100_4712.jpg";
images[5] = "100_4713.jpg";
images[6] = "100_4716.jpg";
images[7] = "100_4718.jpg";
images[8] = "DSCN0273.jpg";
images[9] = "DSCN0282.jpg";
images[10] = "DSCN0283.jpg";
images[11] = "DSCN0284.jpg";
images[12] = "DSCN0286.jpg";
images[13] = "DSCN0287.jpg";
images[14] = "DSCN0289.jpg";

var autoRotate = setInterval(processNextAuto, 4000);


function initAll() {
	document.getElementById("imgText").innerHTML = captionText[0];
	document.getElementById("prevLink").onclick = processPrevious;
	document.getElementById("nextLink").onclick = processNext;
}

function processPrevious() {
	newSlide(-1);
	
	//stop and restart auto timer
	clearInterval(autoRotate);
	autoRotate = setInterval(processNextAuto, 4000);
}

function processNext() {
	newSlide(1);
	
	//stop and restart auto timer
	clearInterval(autoRotate);
	autoRotate = setInterval(processNextAuto, 4000);
	
	//preload next image
	nextimage = new Image();
   	nextimage.src = "slideshow/" + images[currImg + 2];
}

function processNextAuto() {
	newSlide(1);
	
	//preload next image
	nextimage = new Image();
   	nextimage.src = "slideshow/" + images[currImg + 2];
}

function newSlide(direction) {
	var imgCt = captionText.length;

	currImg = currImg + direction;
	if (currImg < 0) {
		currImg = imgCt - 1;
	}
	if (currImg == imgCt) {
		currImg = 0;
	}
	document.getElementById("slideshow").src = "slideshow/" + images[currImg];
	document.getElementById("imgText").innerHTML = captionText[currImg];
}					