
SlideShow = new Class({
	Implements: [Options],
	options: {
		delay: 5000,
		duration: 1000
	},
	initialize: function(container, slides, options) {

		this.container = $(container);
		if(!this.container) return;

		this.setOptions(options);

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

		// preload slides

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

		this.timer = null;
		this.curIndex = 0;

		this.startTimer();
	},

	startTimer: function() {
		clearTimeout(this.timer);

		var n = (this.slides[this.curIndex+1]) ? this.curIndex+1 : 0;
		var i = new Image(); i.src = this.slides[n];

		this.timer = setTimeout(function() {
			this.slideNext();
		}.bind(this), this.options.delay);

	},

	slideNext: function() {
		clearTimeout(this.timer);

		++this.curIndex;
		if(this.curIndex >= this.slides.length) this.curIndex = 0;

		var tmp = this.container.clone();

		tmp.setStyles({
			position: 'absolute',
			left: (navigator.appName.indexOf('Microsoft') > -1) ? this.container.getLeft() -2 : this.container.getLeft(),
			top: (navigator.appName.indexOf('Microsoft') > -1) ? this.container.getTop() -2 : this.container.getTop(),
			'z-index': 20
		});
		tmp.inject($(document.body));

		this.container.src = this.slides[this.curIndex];
		new Fx.Tween(tmp, {
			duration: this.options.duration,
			onComplete: function() {
				this.startTimer();
				tmp.destroy();
			}.bind(this)
		}).start('opacity', 0);
	}


});











