/**
Author: Massimo Barilari by Mattioli ISP
Mail: massi@mattioli.com
Description: Rotate a number of div and show one by one show them for a number of second
Library: Mootools 1.2
.toc					{ position:absolute; left:0; bottom:20px; z-index:2; display:block; width:20px; background:#6D84B4; color:#fff; text-align:center; padding:3px; text-decoration:none; }
		.toc-active				{ background:#fff; color:#6D84B4; }

**/
var SimpleSlideshow = new Class({
	options: {
		showDuration: 3000,
    startIndex: 0
	},
	Implements: [Options,Events],
	initialize: function(container,elements,options) {
		//settings
		this.container = $(container);
		this.elements = $$(elements);
		this.currentIndex = options.startIndex;
		this.interval = '';
		
		//assign
		this.elements.each(function(el,i){
			if(i != this.currentIndex) el.set('opacity',0);
		},this);
		
		//next,previous links
/*		if(this.options.showControls) {
			this.createControls();
		}*/
		//events
		this.container.addEvents({
			mouseenter: function() { this.stop(); }.bind(this),
			mouseleave: function() { this.start(); }.bind(this)
		});

	},
	show: function(to) {
		this.elements[this.currentIndex].fade('out');
		this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex + 1 : 0));
		this.elements[this.currentIndex].fade('in');
	},
	start: function() {
		this.interval = this.show.bind(this).periodical(this.options.showDuration);
	},
	stop: function() {
		$clear(this.interval);
	}
});
