var AutoSlideshow = new Class({

	Implements: [Events, Options],
	
	options: {
		onClickView: $empty
	},
	
	initialize: function(element, options){
		if (element != null){
			this.AutoSlideshow = element;
			this.setOptions(options);
			this.getElements(this.AutoSlideshow);
			this.photos.each(function(el){
				el.setStyle("opacity", 0);
			});
			this.photos[0].setStyle("opacity", 1);
			this.currentPhoto = 0;
			
			var MyDiapo = this;
		  setInterval(function(){ MyDiapo.faders(); }, 5000);
	  }
	},
	
	clearInit: function(){
		this.fireEvent('emptyinit');
	},
	
	getElements: function(el){
		this.photos = [];
		var els = el.getChildren();
		if(!els.length) {this.clearInit(); return;}
		$$(els).each(function(el){
			this.photos.push(el);
		}, this);
	},
	
	faders : function(){
		
		effect = new Fx.Tween(this.photos[this.currentPhoto]);
		effect.start('opacity', 0);
		
		if(this.currentPhoto>=this.photos.length-1) {	
		  this.currentPhoto = 0;
		} else {
		  this.currentPhoto++; 
		}
		
		effect = new Fx.Tween(this.photos[this.currentPhoto]);
		effect.start('opacity', 1);
	}
	
});


