var MooLin = new Class({
	Implements: [Options],
	
	options: {
		'hauteur':100,
		'pause':2000,
		'vitesse':1500
    },
	
    initialize: function( element , options ){
		this.setOptions(options);
		this.liste = $(element);
		this.fx = {};
		if( this.liste ){
		
			this.lignes = this.liste.getElements('li');
			
		}
	
	},
	activer:function(){
		
		if( this.liste ){
		
			this.liste.setStyles({
				'position':'relative',
				'overflow':'hidden'
			});

			this.redimensionne(this.options.hauteur);

			if( this.lignes.length > 0 ){

				this.lignes.each( function( ligne ){
					ligne.setStyles({
						'position':'absolute',
						'top':'100%'
					});
				});

				this.affiche( 1 );
				
			}
			
		}

	},
	desactiver:function(){
	
		if( this.liste ){
	
			if( this.fx.timeout ){
				clearTimeout(this.fx.timeout);
			}
			if( this.fx.affiche ){
				this.fx.affiche.cancel();
				this.fx.affiche = null;
			}
			if( this.fx.masque ){
				this.fx.masque.cancel();
				this.fx.masque = null;
			}
			
			this.redimensionne('auto');

			this.lignes.setStyles({
				'position':'static',
				'top':'auto'
			});
			
		}
		
	},
	redimensionne:function( taille ){
		if( this.liste ){
			if( taille != 'auto' ){
				this.options.hauteur = taille;
			}
			this.liste.setStyle('height',taille);
		}
	},
	
	affiche:function( numero ){
		
		if( numero > this.lignes.length ){
			numero = 1;
		}
		
		this.fx.affiche = new Fx.Tween( this.lignes[numero-1] ,{
			'duration':this.options.vitesse,
			'link':'cancel',
			'unit':'%',
			'onComplete':function( ligne ){
				this.fx.timeout = this.masque.delay( this.options.pause , this , [numero] );
			}.bind(this)
		}).start( 'top' , 0 );

	},
	masque:function( numero ){
	
		
		this.fx.masque = new Fx.Tween( this.lignes[numero-1] ,{
			'duration':700,
			'link':'cancel',
			'onStart':function( ligne ){
				if( this.lignes.length > 1 ){
					this.affiche( numero+1 );
				}
			}.bind( this ),
			'onComplete':function( ligne ){
				ligne.setStyles({
					'opacity':1,
					'top':'100%'
				});
				if( this.lignes.length == 1 ){
					this.affiche( 1 );
				}
			}.bind(this)
//		}).start( 'top' , -this.lignes[numero-1].getSize().y );
		}).start( 'opacity' , 0 );
	
	}
	
});

