

Slideshow = new Class({

	Implements: Options,
	options: {
		timeout: 5000,
		fadeDuration: 1500
	},

	initialize: function(el, slides, options) {
		this.setOptions(options);
		this.el = $(el);
		if(!this.el) return;
		if(!this.el.getElement('img')) return;

		this.slides = $splat(slides);
		if(!this.slides.length) return;

		// preload
		for(var i=0; i<this.slides.length; ++i) {
			var n = new Image();
			n.src = this.slides[i];
		}

		this.curStep = 0;
		this.go();
	},

	go: function() {
		setTimeout(function() {
			this.rotate();
		}.bind(this), this.options.timeout);
	},

	rotate: function() {
		var img = this.el.getElement('img');
		var imgclone = img.clone();
		imgclone.setStyles({
			position: 'absolute',
			top: img.getTop(),
			left: img.getLeft(),
			'z-index': 75
		}).inject(this.el);


		if(++this.curStep >= this.slides.length || !this.slides[this.curStep]) this.curStep = 0;
		img.src = this.slides[this.curStep];

		new Fx.Tween(imgclone, {
			duration: this.options.fadeDuration,
			onComplete: function() {
				imgclone.destroy();
				this.go();
			}.bind(this)
		}).start('opacity', 0);


		test(imgclone);
	}

});



