/**
 * => Mootools 1.2
 * 	=> Core
 * @classDescription
 * Classe permettant d'afficher un diaporama d'éléments
 * @author M@nu/Baphira
 */
var SimpleSlideShow = new Class({
	Implements: [Options, Events],
	
	options: {
		periodical: true,
		delay: 1000,
		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');
		});
		this.index = this.options.startIndex;
    },
	
	hideShow: function() {
		this.show(this.next());
	},
	
	start: function() {
		if (this.slides.length > 0) {
			this.show(this.selected());
			
			if(this.options.periodical) {
				this.intervalID = this.hideShow.delay(this.options.delay, this);
			}
		}
	},
	
	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) {
		if(this.options.periodical) {
			if(this.options.periodical && $chk(this.intervalID)) {
				$clear(this.intervalID);
				this.intervalID = this.hideShow.delay(this.options.delay, this);
			}
		}
		this.slides.each(function(slide) {
			slide.setStyle('display','none');
		});
		if($type(el) == 'number') {
			this.index = el;
			el = this.slides[el.limit(0, this.slides.length-1)];
		}
		el.setStyle('display','block');
		this.fireEvent('onShow', [this.index]);
	}
		
});