/**
 * => Mootools 1.2
 * 	=> Core
 * @classDescription
 * Classe permettant d'afficher un diaporama d'�l�ments
 * @author M@nu/Baphira
 */
var SimpleSlideShow = new Class({
	Implements: [Options],
	
	options: {
		periodical: true,
		delay: 1000,
		effectDelay: 1500,
		startIndex: 0,
		slides: []
	},
	
	initialize: function(slideShow, options){
		this.setOptions(options);
		this.slideShow = slideShow;
		this.slides = this.options.slides;
		this.slides.each(function(el) {
			el.setStyle('display','none');
			if($chk(el.getElement('a'))) {
				el.getElement('a').addEvent('click', function(e) {
					this.show(this.next());
					new Event(e).stop();
				}.bind(this));				
			}
		}.bind(this));
		this.index = this.options.startIndex;
    },
	
	start: function() {
		if (this.slides.length > 0) {
			this.show(this.selected());
		}
	},
	
	selected: function() {
		return this.slides[this.index];
	},
	
	next: function() {
		if(++this.index >= this.slides.length) {
			this.index = 0;
		}
		return this.slides[this.index];
	},
	
	previous: function() {
		if(--this.index < 0) {
			this.index = this.slides.length - 1;
		}
		return this.slides[this.index];
	},
	
	show: function(el) {
		this.slides.each(function(slide) {
			slide.setStyle('display','none');
		});
		if($type(el) == 'number') {
			el = this.slides[el.limit(0, this.slides.length-1)];
		}
		el.setStyle('opacity',0);
		el.setStyle('display','inline');
		
		var effect = new Fx.Morph (el, {
				transition: Fx.Transitions.linear,
				duration: this.options.effectDelay
			});
		effect.start({opacity: [0,1]});
		
		if(this.options.periodical) {
			this.timer = $clear(this.timer);
			this.timer = (function() {
				this.show(this.next());
			}.bind(this)).delay(this.options.delay+this.options.effectDelay);
		}
	}
		
});