//This variable will be used by the pop-up window to locate an image to display
var imageToDisplay = "";

//this function changes src of an image file  
//for a specified image object (imgName)
function change(imgName, newImage) {
	document[imgName].src = newImage;
}

var timerID = null;
var timerRunning = false;
var imgsrcArray = new Array ('1.jpg', '2.jpg','3.jpg','4.jpg','5.jpg');
var imgNameArray = new Array('imageOne', 'imageTwo', 'imageThree');

function stopTimer (){
	if(timerRunning)
	   clearTimeout(timerID);
	timerRunning = false;
}
function showAnimatedJPG () {
              var i, j;
	//change image src for every image defined in the image name array
	for (i=0;i<imgNameArray.length;i++){
                 //if the image src is the last image in the src array, then change it to be first
	   if (document[imgNameArray[i]].src.indexOf(imgsrcArray[imgsrcArray.length-1]) != -1){
	      document[imgNameArray[i]].src = imgsrcArray[0];
                 }//if
                 //otherwise make it the image src to be the next image src in the src array
	   else{
	     //find what the position of the current image src in the src array
                   for (j=0;j<imgsrcArray.length;j++){
                      if (document[imgNameArray[i]].src.indexOf(imgsrcArray[j]) != -1){
	           //now make the image src of the image to be the next one in the src array
                         document[imgNameArray[i]].src = imgsrcArray[j+1];
                         break;
                      }//if
	     }//for
	   }//else                    
	}//for	
	//rotate images every three seconds
	timerID = setTimeout("showAnimatedJPG()",3000);
	timerRunning = true;
}
function startTimer() {
	stopTimer();
	showAnimatedJPG();
}


//this function opens a pop-up window with specified width and height
//it also sets a value for a variable imageToDisplay. This variable will be used 
//by the pop-up window to locate an image to display
function openWindow(windowWidth, windowHeight, imageLocation){
	imageToDisplay = imageLocation;
	var xCoordinate = (screen.width - windowWidth) / 2;
	var yCoordinate = (screen.height - windowHeight) /2;
	var windowParameters = 'width=' + windowWidth + ',height=' + windowHeight + ',left=' + xCoordinate + ',top=' + yCoordinate + ',scrollbars=yes';
	newWindow = window.open("LargeImage.htm","",windowParameters).focus();
}