//
//
//	This is a slide show which will take a list of images and loop through them
//
//


//
//	This defines an object that will implement a slide show with an array of pictures
//		imageList	: array of picture URLs
//		imageId		: id attribute of the <img> tag that shows the image
//

	var	currentAnim = null ;

function AxySlideShow(imageList,imageId)
{
	this.imageList	= imageList ;
	this.shownIndex	= 0 ;
	this.imageId	= imageId ;
	this.opacity	= 1.0 ;
	this.state		= 'stopped' ;
}

AxySlideShow.prototype.ShowNext = function()
{
	//	get the image
	var img = document.getElementById(this.imageId) ;

	switch (this.state)
	{
	case 'stopped':
		//	Show the image directly and start the slide show
		this.shownIndex = 0 ;
		img.src = this.imageList[this.shownIndex] ;

		this.state = 'fading_out' ;
		currentAnim = this ;
		break ;
	
	case 'fading_out':
		if (this.opacity<=0.0)
		{
			//	End of fade out, start fading in
			this.state = 'fading_in' ;
			
			//	Compute next picture
			this.shownIndex++ ;
			if (this.shownIndex >= this.imageList.length)
			{
				this.shownIndex = 0 ;
			}
			
			//	Change the image
			img.src = this.imageList[this.shownIndex] ;
		}
		else
		{
			//	Decrease opacity
			this.opacity -= 0.2 ;

			img.opacity = this.opacity ;
    		img.style.opacity = this.opacity;
   		 	img.style.MozOpacity = this.opacity;
   			img.style.KHTMLopacity = this.opacity;
    		img.style.filter = 'alpha(opacity=' + (this.opacity*100) + ')';
		}
		setTimeout("ShowNextCallback();",50) ;
		break ;
	
	case 'fading_in':
		if (this.opacity>=1.0)
		{
			//	End of the animation
			this.state = 'fading_out' ;
		}
		else
		{
			//	Increase opacity
			this.opacity += 0.2 ;

			img.opacity = this.opacity ;
    		img.style.opacity = this.opacity;
   		 	img.style.MozOpacity = this.opacity;
   			img.style.KHTMLopacity = this.opacity;
    		img.style.filter = 'alpha(opacity=' + (this.opacity*100) + ')';
			
			setTimeout("ShowNextCallback();",50) ;
		}
		break ;
	}
}

function ShowNextCallback()
{
	currentAnim.ShowNext() ;
}

