﻿// Set slideShowSpeed (milliseconds)
var speed = 9000;
var j=0;
var tmpInterval; //placeholder var used later

runStatus = new Object();
runStatus.firstRun = "yes";

//preload the images
var preLoad = new Array()
for (i = 0; i < (picArray.length); i++){
   preLoad[i] = new Image();
   preLoad[i].src = picArray[i];
  // alert("preLoading: " + picArray[i]);
}


//fade out our first image, intervaled function
function slideShow() {
	
	//alert(j);
	
	//WHY DO I HAVE THIS HERE? I think it was to solve slideshow memory?
	//TODO - DEBUG
	if (runStatus.firstRun == "yes") {
		runStatus.firstRun = "no";
	}
		
	var thisNode = document.getElementById("SlideShow");
	thisNode.src = picArray[j];   
	//alert("j: " + j + " -- picArray[j]: " + picArray[j] + " -- picArray.length: " + picArray.length);
      
	
	if (j < picArray.length)  {
		j++;
	}
	
   	if (j == picArray.length) {
		j=0;
	}	
	
}

	

function stopSlideshow() {
	delete runStatus;
	delete meInterval;
}	

function startSlideshow() {
	
	var meInterval = setInterval('slideShow()', speed);
	
}

function nextSlide() {
	
	//if we're at the end of our slideshow
	if (j == picArray.length-1) {
		j = 0;
	} else {
		j++;
	}
	
	slideShow();
}

function prevSlide() {	
	
	//if we're at the beginning of our slideshow
	if (j == 0) {
		
		//step back two - allows for iteration forward
		//another 2 to back it up so it'll iterate to the last array position
		
		j = picArray.length-3;
		//alert("ready for last slide: " + j);
		
	} else {
		
		//jump 2 times back b/c slideShow() iterates forward by 1
		if (j == 1) {
		
			j = picArray.length-2;
		} else {
			//alert("j is greater than 1: " + j);
			j--;
			j--;			
		}
		//alert (j);
	}
	
	//alert(j);

	slideShow();
}
	

function randomImageSet () {


	//Change this variable when more homepage images are added
	//Start the first one with 0, not 1 and count 0 in your totals

	var ranNum= Math.floor(Math.random()*picArray.length);
	
	var slideShowNode = document.getElementById("SlideShow");
	
	slideShowNode.src = picArray[ranNum];
	

}
