/**
 * @author Daniele Corti - GESTWEB Research s.r.l.
 * All the contents of this file belog to GESTWEB Research s.r.l. - Italy
 */

Fx.MooCycler = new Class({
	Implements: Options,
	options: {
		pause: 1000,
		startElement: 0
	},
	initialize: function(wrp, elms, opts){
		this.wrapper = $(wrp);
		this.elements = $A(elms);
		this.current = this.options.startElement.toInt();
		this.setOptions(opts);
		
		this.wrapper.setStyle('overflow', 'hidden');
		
		this.elements.each(function(item, index){
			item.set('tween', opts);
			if (this.current != index) 
				item.setStyle('display', 'none');
		}.bind(this))
		this.start.delay(this.options.pause, this);
	},
	start: function(){
		next = this.current < this.elements.length - 1 ? this.current + 1 : 0;
		this.elements[next].setStyle('display', 'block');
		this.elements[this.current].get('tween').start('margin-top', 0 - this.wrapper.getStyle('height').toInt()).chain(function(){
			this.elements[this.current].dispose().inject(this.wrapper).setStyles({
				'margin-top': 0,
				'display': 'none'
			});
			this.current = next;
			this.start.delay(this.options.pause, this);
		}.bind(this))
	}
});