//instance of slideShow class - object
var slideShow_obj;

//position of current picture - integer
var number_int;

//total number of slides
var total_int;

function generatePosition()
{
	//generate position for first slide
	number_int = getRandom(total_int-1);
	
	//make sure the position for first slide is an even number	
	if(isOdd(number_int))
	{
		number_int --;
	}
	
	return(number_int);
}

/*
########################################################################################################
########################################################################################################
Type:
				-	JS FUNCTION
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003							
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- function buildSlideShow(imgPrefix, timeLapse)
########################################################################################################
Description:
				- creates new instance of 'slideShow' class
				- generates 'slides' property for new insatnce of 'slideShow' class
				  by creating new instances of the 'slide' object
				- randomly generates position of first slide to be displayed
				- sets time lapse for slide show
########################################################################################################
Parameters:				
				- imgPrefix - image name prefix, string
				- timeLapse - number of seconds between swaps, integer
########################################################################################################
Returns:
				- nothing
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################				
*/
function buildSlideShow(imgPrefix, timeLapse)
{
	//counter for loop
	var i;
	
	//create instance of object and set number and lapse properties
	slideShow_obj = new slideShow();
	slideShow_obj.size = total_int;
	slideShow_obj.speed = timeLapse;
	
	//create instances of slide class and set name and path properties for those
	for(i=0;i<total_int;i++)
	{
		slideShow_obj.slides[i] = new slide();
		slideShow_obj.slides[i].name = "slide"+i;
		slideShow_obj.slides[i].path = imgPrefix + (i+1) + ".jpg";
	}
	
	
		
	//start slide show 
	slideShow_obj.Run();
	
	// set time lapse
	setInterval("slideShow_obj.Run()",1000*slideShow_obj.speed);
}
/*
########################################################################################################
########################################################################################################
*/






/*
########################################################################################################
########################################################################################################
Type:
				-	JS FUNCTION
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003							
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- getRandom(limit)
########################################################################################################
Description:
				- generates a random integer between 0 and 'limit'
########################################################################################################
Parameters:				
				- limit - superior limit of interval used to generate random integer
########################################################################################################
Returns:
				- a random integer between 0 and 'limit'
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
function getRandom(limit)
{
    //calculates random integer
	var ranNum= Math.round(Math.random()*limit);
	//return calculated number
    return ranNum;
}
/*
########################################################################################################
########################################################################################################
*/




/*
########################################################################################################
########################################################################################################
Type:
				-	JS FUNCTION
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003							
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- isOdd(integer_int)
########################################################################################################
Description:
				- tests if an integer is ODD, returns true if it is, false if it's not
########################################################################################################
Parameters:				
				- integer_int - integer to be tested
########################################################################################################
Returns:
				- true or false
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
function isOdd(integer_int) 
{ 
	return (integer_int%2)?true:false; 
}
/*
########################################################################################################
########################################################################################################
*/	



/*
########################################################################################################
########################################################################################################
Type:
				-	JS FUNCTION
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 10/19/2002							
########################################################################################################
Version:
				- 3.0
########################################################################################################
Name:				
				- function changeImage(imgDocID,imgObjName)
########################################################################################################
Description:
				- replaces the image enclosed in the 'imgDocId' location with the image 
				  object instance defined by the 'imgObjName' label
########################################################################################################
Parameters:				
				- imgDocID - id of location where the image will be placed
				- imgObjName - name of image object instance to be displayed
########################################################################################################
Returns:
				- nothing
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
function changeImage(imgDocID,imgObjName)
{
  	document.images[imgDocID].src=eval(imgObjName + ".src");
}
/*
########################################################################################################
########################################################################################################
*/



/*
########################################################################################################
########################################################################################################
Type:
				-	JS CLASS
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003								
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- slideShow
########################################################################################################
Description:
				- class of image slideshows
########################################################################################################
Properties:				
				- size - number of total images to be displayed, integer
				- speed - time lapse between two slides, in seconds, integer
				- slides - array of instances of the 'slide' class
########################################################################################################
Methods:
				- Run() - displays current slide while it preloads the next one
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
function slideShow()
{
	//total number of images
	this.size = "";
	
	//seconds between changing from one image to another
	this.speed = "";
	
	//array that contains images
	this.slides = new Array();
}
/*
########################################################################################################
########################################################################################################
*/	


/*
########################################################################################################
########################################################################################################
Type:
				-	JS CLASS
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003								
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- slide
########################################################################################################
Description:
				- class of image container for slideshow
########################################################################################################
Properties:				
				- name - name of instance - will be used to address image object, string
				- path - path of image, string
				- position - position inside slide show, integer
########################################################################################################
Methods:
				- Load() - loads corresponding image
				- Displays() - displays corresponding image
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
function slide()
{
	//name of image object
	this.name = "";
	
	//path to image
	this.path = "";
	
	//position in slideshow
	this.position = "";
	
	//is false if image not loaded yet
	this.loaded = false;
}


/*
########################################################################################################
########################################################################################################
Type:
				-	METHOD for JS CLASS 'slide'
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003							
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- Run()
########################################################################################################
Description:
				- displays corresponding image
########################################################################################################
Parameters:				
				- none
########################################################################################################
Returns:
				- nothing
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
slide.prototype.Display = function()
{
	changeImage("slideshow",this.name)		
}
/*
########################################################################################################
########################################################################################################
*/	


/*
########################################################################################################
########################################################################################################
Type:
				-	METHOD for JS CLASS 'slide'
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003							
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- Run()
########################################################################################################
Description:
				- preloads corresponding image
				- sets 'loaded' property to true
########################################################################################################
Parameters:				
				- none
########################################################################################################
Returns:
				- nothing
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
slide.prototype.Load = function()
{
	//preload  image
	eval(this.name+' = new Image()');
	eval(this.name+'.src = "'+this.path+'"');
	
	//image is loaded
	this.loaded = true;	
}
/*
########################################################################################################
########################################################################################################
*/	



/*
########################################################################################################
########################################################################################################
Type:
				-	METHOD for JS CLASS 'slideShow'
########################################################################################################
Author:
				- Ovidiu Roatis
########################################################################################################
Date:
				- 05/20/2003							
########################################################################################################
Version:
				- 1.0
########################################################################################################
Name:				
				- Run()
########################################################################################################
Description:
				- loads(if necessary) and shows current slide
				- loads next slide
				- if end of cycle, re-starts cycle
########################################################################################################
Parameters:				
				- total - number of slides in the show, integer
########################################################################################################
Returns:
				- nothing
########################################################################################################								
Notes:

########################################################################################################
########################################################################################################
*/	
slideShow.prototype.Run = function ()
{
	
	//if image not loaded, load
	if(!this.slides[number_int].loaded)
		this.slides[number_int].Load();
		
	//display image	
	this.slides[number_int].Display();
	
	//also load next image
	if(number_int<this.size-1)
	{
		if(!this.slides[number_int+1].loaded)
			this.slides[number_int+1].Load();
	}
		
		
	//go back to first image after last image has been displayed
	if(number_int<this.size-1)
		number_int++	
	else
		number_int = 0;	
}
/*
########################################################################################################
########################################################################################################
*/	