
function getNextImage(slot){
	
	var tempArray = new Array();
	var tempVar = false;
	var z = 0;

	/*
	
	The below two FOR loops are used to go through all of the image in the directory
	and compare them to the current image displayed on the screen.  The code then 
	builds an array with the images that are not currently on the screen.
	
	Finally, the code randomly selects one of the images from the new array and the
	function returns this value back to the code snippet that called it.	
	
	*/

	for(x=1; x <= totalImages; x++){
		for(y=1; y <= displayImages; y++){
			tempVar = false;
			var myPic = eval("pic" + x);
			var myCur = eval("document.myForm.cur" + y);	
			if(myCur.value == myPic){
				tempVar = true;
				break;
			}
		}
		if(tempVar == false){
			tempArray[z] = myPic;
			z++;			
		}
	}

	var tempRnd = Math.round((tempArray.length-1) * Math.random());	
	var tempCur = eval("document.myForm.cur" + slot);
	var curImg = tempArray[tempRnd];
	tempCur.value = curImg;
	return curImg;
}

function changeImage1(){
   
   img1 = getNextImage(1);
   
   if (document.all){
      document.images.switchImage1.style.filter="blendTrans(duration=2)";
      document.images.switchImage1.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.switchImage1.filters.blendTrans.Apply();     
   }
   document.images.switchImage1.src = preLoad[img1].src;
   if (document.all){
      document.images.switchImage1.filters.blendTrans.Play();
   }

   var1 = setTimeout('changeImage1()', Math.round(maxSeconds*Math.random())+minSeconds );
}

function changeImage2(){

   img2 = getNextImage(2);
   
   if (document.all){
      document.images.switchImage2.style.filter="blendTrans(duration=2)";
      document.images.switchImage2.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.switchImage2.filters.blendTrans.Apply();     
   }
   document.images.switchImage2.src = preLoad[img2].src;
   if (document.all){
      document.images.switchImage2.filters.blendTrans.Play();
   }

   var2 = setTimeout('changeImage2()', Math.round(maxSeconds*Math.random())+minSeconds );
}

function changeImage3(){
 
   img3 = getNextImage(3);
   
   if (document.all){
      document.images.switchImage3.style.filter="blendTrans(duration=2)";
      document.images.switchImage3.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.switchImage3.filters.blendTrans.Apply();     
   }
   document.images.switchImage3.src = preLoad[img3].src;
   if (document.all){
      document.images.switchImage3.filters.blendTrans.Play();
   }

   var3 = setTimeout('changeImage3()', Math.round(maxSeconds*Math.random())+minSeconds );
}

function changeImage4(){
   
   img4 = getNextImage(4);

   if (document.all){
      document.images.switchImage4.style.filter="blendTrans(duration=2)";
      document.images.switchImage4.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.switchImage4.filters.blendTrans.Apply();     
   }
   document.images.switchImage4.src = preLoad[img4].src;
   if (document.all){
      document.images.switchImage4.filters.blendTrans.Play();
   }

   var4 = setTimeout('changeImage4()', Math.round(maxSeconds*Math.random())+minSeconds );
}

document.write("<form name='myForm' method='post' action=''>");

for (i = 1; i <= displayImages; i++){
	document.write("<IMG SRC='"+ preLoad[i].src +"' NAME='switchImage"+(i)+"' ID='switchImage"+(i)+"'>");
	var tempObj = eval("img"+i);
	tempObj = i;
	document.write("<input name='cur"+i+"' type='hidden' id='cur"+i+"' value='"+i+"'>");	
}

document.write("</form>");

function getRndTime(){
	var time = Math.round(initDelayMax*Math.random())+initDelayMin;
	return time;
}

function startLoops(){
	
	document.getElementById('waitdiv').style.display = 'none';
	
	self.setTimeout('changeImage1()', getRndTime());
	self.setTimeout('changeImage2()', getRndTime());
	self.setTimeout('changeImage3()', getRndTime());
	self.setTimeout('changeImage4()', getRndTime());

}

window.onload = startLoops;
