/*
Usage:
new SimpleSlideShow(wrapperElement, arrayOfImagesSources [, options]);

Options:
fadeTime: time in ms for the fade between images
stayTime: time between two fades

License:
MIT-Style-License
Copyright: Jan Kassens <janATkassens.net>
*/

var SimpleSlideShow = new Class({

	Implements: Options,

	options: {
		fadeTime: 1000,
		stayTime: 3000
	},

	initialize: function(wrapper, images, options) {
		var params = Array.link(arguments, {wrapper: $defined, images: Array.type, options: Object.type});
		this.wrapper = $(params.wrapper);
		this.setOptions(params.options);

		this.images = (params.images || JSON.decode(this.wrapper.get('images'))).map(function(image){
			return new Element('img', {
				src: image, width: '100%', height: '100%',
				tween: {duration: this.options.fadeTime}
			});
		}, this);
		this.index = 0;
		this.topImage = this.images[0].inject(this.wrapper);
		this.fade.delay(this.options.stayTime, this);
	},

	fade: function() {
		this.index = (this.index + 1) % this.images.length;
		this.bottomImage = this.topImage;
		this.topImage = this.images[this.index]
			.fade('hide')
			.inject(this.wrapper)
			.fade('in');
		this.fade.delay(this.options.stayTime + this.options.fadeTime, this);
	}

});