var mooMarquee = new Class({
	Implements: [ Events, Options ],
	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.content = new Element('div', {
			'styles': {
			   'margin': 0,
			   'padding': 0,
			   'border': 'none'
			}
		}).injectInside(this.box);
		
		this.i = 0;
		this.setOptions(options);
		this.cTimer = null;
		
		// In
		var fxInOptions = { 
			onStart: function(element){
				this.content.setStyle('display', 'block');
			}.bind(this),
			onComplete: function(element){
				this.cTimer = this.hide.delay(this.options.waitDuration, this);
			}.bind(this),
			transition: this.options.transitionIn,
			duration: this.options.transitionInDuration, 
			link: 'cancel',
			property: 'margin-top'
		}
		this.fxIn = new Fx.Tween(this.content, 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, 
			link: 'cancel',
			property: 'margin-top'
		}
		this.fxOut = new Fx.Tween(this.content, fxOutOptions);  
		
		if(this.elements.length > 0) {
			this.show();
		}
	},
	
	cElement: function(){
		return this.elements[this.i].clone();
	},
	
	show: function(){           
		this.content.empty().setStyles({
		   'margin-top': this.box.getSize().y
		});
		this.cElement().injectInside(this.content);
		this.fxIn.start(0);
	},
	
	hide: function(){
		this.fxOut.start(Math.max(this.box.getSize().y, this.content.getSize().y)*-1);
	}
});
