// JavaScript Document

var Slideshow = new Class.create({
	initialize: function(frame) {
		this.layers = $(frame).select('img');
		$(frame).style.position = 'relative';
		for(var i = 0; i < this.layers.length; i++) {
			this.layers[i].style.zIndex = 2000 + this.layers.length - 1 - i;
			this.layers[i].style.position = 'absolute';
			this.layers[i].style.top = '0px';
			this.layers[i].style.left = '0px';
		}
		this.top = this.layers[0];
		this.start();
	},
	slide: function() {
		new Effect.Opacity(this.top, { duration: 0.5, from: 1.0, to: 0.0, afterFinish: function(effect) {
			var faded = this.top;															 
			for(var i = 0; i < this.layers.length; i++) {
				var position = (parseInt(this.layers[i].style.zIndex) - 1999) % this.layers.length;
				this.layers[i].style.zIndex = 2000 + position;
				if(position == this.layers.length - 1)
					this.top = this.layers[i];
			}
			new Effect.Opacity(faded, { duration: 0.0, from: 0.0, to: 1.0});
		}.bind(this)});
	},
	start: function() {
		this.executer = new PeriodicalExecuter(this.slide.bind(this), 5);
	},
	stop: function() {
		this.executor.stop();
	}
});
