var SimpleFader = new Class({
	
	Implements: [Options],
	
	options: {
		transition_duration: 0, 				//How long the transition should take
		total_life_duration: 0, 				//duration for the animation
		initial_delay: 0, 						//How long to offset the first lifecycle
		transition: Fx.Transitions.Sine.easeOut 	//transition
	},

	initialize:function(imagesWrapper, options) {
		
		//set options
		this.setOptions(options);
		
		var delay_start = false;
		
		this.ImageWrappers = $(imagesWrapper).getElements('div');
		this.ImageWrappers[0].set("opacity", "1");		
		
		this.Els = [];
	
	
		$$("#" + imagesWrapper + " div").each(function(item) {			
			this.Els.include(new Fx.Morph(item,{duration:this.options.transition_duration, transitions:this.options.transition, link:'cancel'}));
		}.bind(this));            
	
		this.currentEl = this.Els[0];
		this.current = 0;
		
		if(this.options.initial_delay > 0){
			fade_periodical = this.Fade.periodical(this.options.initial_delay, this);			
		} else {
			fade_periodical = this.Fade.periodical(this.options.total_life_duration, this);
		}
	},
	
	Fade:function() {
		this.currentEl.start({"opacity" : [1, 0]});
	
		(this.current != this.Els.length - 1) ? this.current++:this.current=0;

		this.Els[this.current].start({"opacity" : [0, 1]});
		this.currentEl = this.Els[this.current];              
		
		if(this.options.initial_delay > 0){
			$clear(fade_periodical);
						
			this.options.initial_delay = 0;
			
			fade_periodical = this.Fade.periodical(this.options.total_life_duration, this);
		}
	}
}); 



window.addEvent('domready', function() {

	//you should make an instance of the Fader class here:
	var fader_l = new SimpleFader('imagesWrapper_l', {'transition_duration': 3000, 'total_life_duration': 7000});;

	/*
	var myAdvancedFunction = SimpleFader.create({
	    arguments: ['imagesWrapper_r'],	    
	    delay: 2000
	});
	*/
	
	var fader_r = new SimpleFader('imagesWrapper_r', {'initial_delay': 3000, 'transition_duration': 3000, 'total_life_duration': 7000});			
	
});