var sliderSlider = new Class({
	Implements: [Options,Chain],
	
	options:{
		elementi: new Array(),
		attuale:0,
		esecInterval:'',
		totale:0,
		periodo:6000,
		iniziato:false,
		span_totale:'',
		span_parziale:''
	},
	
	initialize: function(opt){
		this.setOptions(opt);
		
		this.options.elementi = $$('.sliderSlider');
		this.prendi();
		
		div = new Element('div',{'id':'sliderSlider_totali'}).inject('sliderSlider');
		div.set('html','Slider: ');
		this.options.span_parziale = new Element('span').inject(div);
		this.options.span_totale = new Element('span').inject(div);
		this.options.span_totale.set('html','/'+this.options.totale);
		this.gira();
		this.periodico();
	},
	
	prendi: function(){
		this.options.elementi.each(function(item){
			item.fade('hide');
		});
		this.options.totale = this.options.elementi.length;
		this.options.attuale = 0
	},
	
	periodico: function(){
		var prop = this;
		per = function(){
			prop.gira();
		}
		this.options.esecInterval=per.periodical(this.options.periodo);
	},
	
	gira:function(){
		prop = this;
		this.chain(
			function(){
				if(prop.options.iniziato){
					prop.options.elementi[prop.options.attuale].fade('out');
					prop.options.attuale = (prop.options.attuale < (prop.options.totale-1)) ? prop.options.attuale+1 : 0 ;
				}else{
					prop.options.iniziato=true;
				}
				this.callChain();
			},
			function(){
				prop.options.elementi[prop.options.attuale].fade('in');
				this.options.span_parziale.set('html',prop.options.attuale+1);
				this.callChain();
			}
		)
		this.callChain();
	}
});

window.addEvent('domready',function(){
	aport = new sliderSlider();
	var css = new Asset.css('style_din/style_slider.css');
})