// counter helps you know what image on the array you're at; constructionImages is the array of images; i helps fill array; speed is speed of slideshow; t helps loop slideshow; a checks if play or stop is clicked.
var constructionImages=new Image();
var i, t, tempCounter, counter=0;
var speed = 6000;
var a=true;

// Fill array with proper naming convention.
for(i=0; i<=numFiles; i++){
	if(i<10){
		constructionImages[i] = 'http://static.www.colostate-pueblo.edu/Projects/images/' + imgDir + '_0' + i + '.jpg';
	}else{
		constructionImages[i] = 'http://static.www.colostate-pueblo.edu/Projects/images/' + imgDir + '_' + i + '.jpg';
	}
}

// On page load loads first image.
function loadImage(){
  document.Rotating.src = constructionImages[counter];
}

// Checks to see if play slideshow is clicked if so play slideshow visibility is set to hidden and stop slideshow is visible.
function runSlideShow(){
  a=true;
  tempCounter=counter;
  document.getElementById('play').style.visibility="hidden";
  document.getElementById('stop').style.visibility="visible";
  slideShow();
}

// function runs slide show until a is false 
function slideShow(){
  if(a==true){
	 // transition information.
	 if (document.all) {
		document.images.Rotating.style.filter="blendTrans(duration=2)";
		document.images.Rotating.style.filter="blendTrans(duration=3)";
		document.images.Rotating.filters.blendTrans.Apply ();
	 }
	 
	 if (document.all) {
		document.images.Rotating.filters.blendTrans.Play( );
	 }
	 
	 // increments image every time though and loads image.
	 counter=counter+1;
	 document.images.Rotating.src = constructionImages[counter];
	 
	 // checks to see if at the end of images if so stops slide show and displays first slide.
	 if (counter>=numFiles+1){
		 counter=0;
		 document.Rotating.src = constructionImages[counter];
		 t=setTimeout('slideShow()', speed);
		 if (counter==tempCounter){
			document.Rotating.src = constructionImages[counter];
			a=false;
			stopSlideShow();
		 }
	 // if not at the end of the slideshow it loops to the top of function.
	 }else if (counter!=tempCounter){
		t=setTimeout('slideShow()', speed);
		
	 // if slide is equal to where the user started than it shall stop.
	 }else if (counter==tempCounter){
	    document.Rotating.src = constructionImages[counter];
		a=false;
		stopSlideShow();
	 }
  }
}

// When stop is clicked sets play to visible and stop to hidden.
function stopSlideShow(){
  a=false;
  document.getElementById('play').style.visibility="visible";
  document.getElementById('stop').style.visibility="hidden";
}

// When next image is clicked checks to see which image you're at displays the next image.
function changeImgForward(){
  if (counter<numFiles){
	counter++;
    document.Rotating.src = constructionImages[counter];
  }else if (counter==numFiles){
    counter=0;
    document.Rotating.src = constructionImages[counter];
  }
}

// When previous image is clicked checks to see which image you're at displays the previous image.
function changeImgBack() {
  if (counter>0){
	counter--;
    document.Rotating.src = constructionImages[counter];
  }else if (counter==0){
    counter=numFiles;
    document.Rotating.src = constructionImages[counter];
  }
}