function SlideShowImage (images)
{
	this.current = 0;
	this.images = images;
}

SlideShowImage.prototype =
{
	Next : function ()
	{
		++this.current;
		if (this.current >= this.images.length)
		{
			this.current = 0;
		}
	},
	
	Previous : function ()
	{
		--this.current;
		if (0 > this.current)
		{
			this.current = this.images.length - 1;
		}
	},
	
	GetCurrentUrl : function ()
	{
		return this.images[this.current];
	}
}

function SlideShow (slideShowImage, imageId)
{
	this.imageId = imageId;
	this.timeout = 2500;
	this.slideShowImage = slideShowImage;
	this.isStopped = true;
	
	this.LoadSlide();
}

SlideShow.prototype =
{
	Play : function ()
	{
		if (false == this.isStopped)
		{
			return;
		}
		this.isStopped = false;
		this.LoadSlide(this.slideShowImage.GetCurrentUrl());
		setTimeout("Loop()", this.timeout);
	},
	
	Stop : function ()
	{
		if (this.isStopped)
		{
			return;
		}
		this.isStopped = true;
	},
	
	Back : function ()
	{
		this.slideShowImage.Previous();
		this.LoadSlide();
	},
	
	Forward : function ()
	{
		this.slideShowImage.Next();
		this.LoadSlide();
	},
	
	Loop : function ()
	{
		if (this.isStopped)
		{
			return;
		}
		this.slideShowImage.Next();
		this.LoadSlide();
		setTimeout("Loop()", this.timeout);
	},
	
	LoadSlide : function ()
	{
		document.getElementById(this.imageId).setAttribute(
			"src",
			this.slideShowImage.GetCurrentUrl());
	}
};

var slideShowImage = null;
var slideShow = null;

function Init (images, targetImageId)
{
	slideShowImage = new SlideShowImage(images);
	slideShow = new SlideShow(slideShowImage, targetImageId);
}
 
function Play () { slideShow.Play(); }
function Stop () { slideShow.Stop(); }
function Back () { slideShow.Back(); }
function Forward () { slideShow.Forward(); }
function Loop () { slideShow.Loop(); }
