//**************************** random image generation code ********************* //
//Author: Anil Rambabu - Paloma technologies ltd.
//Date: 22-12-2003
//Description: script to generate random images 

var interval = 5; // delay between rotating images (in seconds)
var InxImage = 0; // image index
var imageNo; // total number of images

interval *= 1000;
ArrImages = new Array();

function LoadImages(){
//************ preload the images *******//
	if(document.images){
	//*** enter the full path of the images in place of the URL //
	//*** if using the Ordered images function, place them in the order you want them displayed //
		
		ArrImages[InxImage++] = new imageItem("../images/rotating_images/cottage_2.jpg");
		ArrImages[InxImage++] = new imageItem("../images/rotating_images/cottage_3.jpg");
		
		
		//** total number of images.//
		imageNo = ArrImages.length;		
	}
}

function imageItem(imagePath) {
//*** image object //
this.image_item = new Image();
this.image_item.src = imagePath;
}

function ImageItemLocation(imageObj) {
//** returns the image location of a particular object in the array.//
return(imageObj.image_item.src)
}

function generate(x, y) {
//** generating random numbers//
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}

function getNextImage() {
//** generates a random number //
InxImage = generate(0, imageNo-1);
var NewImage = ImageItemLocation(ArrImages[InxImage]);
return(NewImage);
}

function ImageRotation(place) {
//*** loads random images //
	var NewImage = getNextImage();
		document[place].src = NewImage;
	var recur_call = "ImageRotation('"+place+"')";
	//*** recurring calls to this function, depending on the interval set.//
	setTimeout(recur_call, interval);
		}
		
function IntialiseRandom(place){
//*** Calls the preload function to preload images //
	LoadImages();

	var recur_call = "ImageRotation('"+place+"')";
	//*** First call to ImageRotation fucntion responsible to load random images.//
	setTimeout(recur_call, interval);
}
		
function IntialiseOrdered(place){
//*** Calls the preload function to preload images //
	LoadImages();
	InxImage = 0;
	var recur_call = "ImageRotationNew('"+place+"', '"+InxImage+"')";
	//*** First call to ImageRotation fucntion responsible to load random images.//
	setTimeout(recur_call, interval);
}

function ImageRotationNew(place, InxImage) {
//*** loads random images //
	if (InxImage<(imageNo)) {
		var NewImage = ImageItemLocation(ArrImages[InxImage]);
		document[place].src = NewImage;
		InxImage++;
		var recur_call = "ImageRotationNew('"+place+"', '"+InxImage+"')";
	//*** recurring calls to this function, depending on the interval set.//
		setTimeout(recur_call, interval);
	}
}		
//******************************** random image generation code ends here ****************** //
