function DXImageSlideShowImage( src, href )
{
	this.Src = src;
	this.Href = href;
}

function DXImageSlideShow( id, interval, autoStart, showControlPanel )
{
	this.Id = id;
	this.Images = new Array();
	this.CurrentImageIndex = 0;
	this.Interval = interval;
	this.IsPlaying = false;
	this.TimeoutId = null;
	this.ShowControlPanel = showControlPanel;
	if( autoStart )
	{
		this.Start();
	}
}

DXImageSlideShow.prototype.ImageCount = function()
{
	return this.Images.length;
}

DXImageSlideShow.prototype.AddImage = function( src, href )
{
	img = new DXImageSlideShowImage( src, href );
	this.Images[ this.Images.length ] = img;
}

DXImageSlideShow.prototype.ChangeImage = function( delta )
{
	var imageObject = document.getElementById( this.Id + "Image" );
	var linkObject = document.getElementById( this.Id + "Link" );
	
	if( !imageObject || !linkObject )
		return;
	
	this.CurrentImageIndex += delta;
	
	if( this.CurrentImageIndex >= this.ImageCount() )
		this.CurrentImageIndex = 0;
	else if( this.CurrentImageIndex < 0 )
		this.CurrentImageIndex = this.ImageCount() - 1;
	
	var img = this.Images[ this.CurrentImageIndex ];
	
	imageObject.src = img.Src;

	linkObject.href = img.Href;
	
	if( this.ShowControlPanel )
	{
		var statusObject = document.getElementById( this.Id + "Status" );
		statusObject.innerHTML =
			dxLocalizedString.GetText( "Bild", "Image" ) + " " +
			(this.CurrentImageIndex+1) + " " +
			dxLocalizedString.GetText( "av", "of" ) + " " +
			this.ImageCount();
	}
}

DXImageSlideShow.prototype.Start = function()
{
	var buttonObject = document.getElementById( this.Id + 'StartButton' );
	if(this.IsPlaying)
	{
		this.IsPlaying = false;
		if( buttonObject )
			buttonObject.value = dxLocalizedString.GetText( "Starta", "Start" );
		window.clearTimeout( this.TimoutId )
	}	
	else
	{			
		this.IsPlaying = true;
		this.StartTimeOut();
		if( buttonObject )
			buttonObject.value = dxLocalizedString.GetText( "Stoppa", "Stop" );
	}
}

DXImageSlideShow.prototype.StartTimeOut = function()
{
	this.TimoutId = window.setTimeout( this.Id + '.Play()', this.Interval );
}

DXImageSlideShow.prototype.Play = function()
{
	if( this.IsPlaying )
		this.ChangeImage( 1 );
		
	this.StartTimeOut();
}

