/*
	Object that handles the slideshow.
*/
var SlideshowObject = Class.create();

SlideshowObject.prototype = 
{
	initialize: function( container_object, images )
	{
		this.container = container_object;
		this.slides = [];
		this.index = 0;
		this.fade_duration = 3;
		this.display_for = 5;
		this.executer = null;

		images.each( function( image_url )
		{
			var image = document.createElement( 'img' ); // new Image() does not create a proper HTML element in Safari 2.
			image.src = image_url;
			image.style.position = "absolute";
			image.style.display = "none";

			this.slides.push( image );

			this.container.appendChild( image );
		}.bind(this) );

		Effect.Appear( this.slides[0], { duration: this.fade_duration, from: 0.0, to: 0.999 } );

		this.start();
	},

	start: function()
	{
		this.executer = new PeriodicalExecuter( this.cycle.bind(this), this.display_for );
	},

	cycle: function()
	{
		Effect.Fade( this.slides[this.index], { duration: this.fade_duration, from: 0.999, to: 0.0 } );

		this.index++;

		if( this.index === this.slides.length )
		{
			this.index = 0;
		}

		Effect.Appear( this.slides[this.index], { duration: this.fade_duration, from: 0.0, to: 0.999 } );
	},

	stop: function()
	{
		if( this.executer )
		{
			this.executer.stop();
		}
	}
};


