//created by Alicia Briggs, a slide show for photos from the yearly show
//this creates a slide show with a previous, next and start show button. When clicked the start
//show button becomes the stop show button and vice versa.

var imgFilesList= ["bandr.jpg",
				    "tots11.jpg",
					"green.jpg",
					"pink.jpg",
					"black.jpg",
					"rwb.jpg",
					"blue.jpg",
					"yellow.jpg",
					"red.jpg",
					"bandw.jpg"
					];
var IMGPATH="images/";
	

function getNextIndex(index, listlength) {	
    
    if (index == listlength - 1) {
	index = 0;
    }
    
   else { index = index + 1;}
   return index;
}//this function determines where the slide show is in the picture, it creates the unbreaking 
//cycle of picture

function getPrevIndex(index, listlength) {
    
    if (index == 0) {
	index = listlength - 1;
    }
    
    else { index = index - 1;}
    return index;
 }//gets the previous image


var index=0//place to store what image the show is on




function changePage(imgEl, buttonEl){

   
   
  

   var listlength = imgFilesList.length;
        


   if (buttonEl.value == "Next") {
	   index = getNextIndex(index, listlength);
	}
   else if (buttonEl.value == "Prev") {
	   index = getPrevIndex(index, listlength);
	}
   else if (buttonEl.value == "Start Show" || buttonEl.value == "Stop Show"){	  
	   index = getNextIndex(index, listlength);
	}

  
     
   imgEl.src = IMGPATH + imgFilesList[index];
   
    }	
   //changes the image
	


var timerID = 0;
var SHOWINTERVAL = 1000; //time in milliseconds, between images

function slideShow(imgEl, buttonEl) {

   if (buttonEl.value == "Start Show") {
   	timerID = setInterval(function(){changePage(imgEl, buttonEl)}, SHOWINTERVAL);
	buttonEl.value = "Stop Show";
	
	}
   else { 
	clearInterval(timerID);
	buttonEl.value = "Start Show";
	}

}//the start and stop show button




