var mooFading = new Class({
	options: {
		'transitionIn': Fx.Transitions.Sine.easeOut,
		'transitionInDuration': 600,
		'transitionOut': Fx.Transitions.Sine.easeIn,
		'transitionOutDuration': 600,
		'waitDuration': 10000
	},
	
	initialize: function(box, elements, options){
		(this.elements = $$(elements)).each(function(element, index) {
			this.elements[index] = element.clone();
		}, this);
				
		// (this.box = $(box)).setStyle('overflow', 'hidden').empty();
		
		(this.box = $(box)).empty();
		
		this.content = new Element('div', {
			'styles': {
			   'margin': 0,
			   'padding': 0,
			   'border': 'none',
			   'heigth': this.box.getSize().size.y,
			   'width': this.box.getSize().size.x
			}
		}).injectInside(this.box);
		
		this.i = 0;
		this.setOptions(options);
		
		// In
		var fxInOptions = { 
			onStart: function(element){
				this.content.setStyle('display', 'block');
			}.bind(this),
			onComplete: function(element){
				this.hide.delay(this.options.waitDuration, this);
			}.bind(this),
			transition: this.options.transitionIn,
			duration: this.options.transitionInDuration, 
			wait: false,
			fps: 25
		}
		this.fxIn = new Fx.Style(this.content, 'opacity', fxInOptions); 
		
		// Out
		var fxOutOptions = { 
			onStart: Class.empty,
			onComplete: function(element){
				this.content.setStyle('display', 'none');
				this.i++;
				if(this.i >= this.elements.length) this.i = 0;
				this.show();
			}.bind(this),
			transition: this.options.transitionOut,
			duration: this.options.transitionOutDuration, 
			wait: false,
			fps: 25
		}
		this.fxOut = new Fx.Style(this.content, 'opacity', fxOutOptions);  
		
		if(this.elements.length > 0) {
			this.show();
		}
	},
	
	cElement: function(){
		return this.elements[this.i].clone();
	},
	
	show: function(){
		this.content.empty().setStyle('opacity', 0);
		this.cElement().injectInside(this.content);
		this.fxIn.start(1);
	},
	
	hide: function(){
		this.fxOut.start(0);
	}
});
mooFading.implement(new Options);