
var rotations = new Class({

	initialize:function()
	{
		this.start=false;
		this.tempoTrans=700;
		this.tempoTimer=5000;
		this.tempoTrans2=300;
		this.tempoTimer2=1500;
		this.opacity=0.5;
		this.raison=$$('#rotation div.rotation');
		this.miniraison=$$('#rotationCommande a.cmd');
		this.current = 0;
		this.next = (this.current+1 < this.raison.length ? this.current+1 : 0);
		for(i=0;i<this.raison.length;i++) { this.raison[i].setStyles({'opacity' : 0 , 'visibility' : 'hidden'}); }
		for(i=0;i<this.miniraison.length;i++) { this.miniraison[i].setStyles({'opacity' : this.opacity}); }
		fx0=new Fx.Morph(this.raison[0], {duration:this.tempoTrans,wait:false });
		fxm0=new Fx.Morph(this.miniraison[0], {duration:this.tempoTrans,wait:false });
		fx0.start({'opacity':1});
		fxm0.start({'opacity':1});
		if(this.raison.length>1) this.timer=this.showNext.periodical(this.tempoTimer,this);	
		this.uX();
	},
	
	showNext : function()
	{
		var a=this.current;
		var n=(this.current==this.raison.length-1 ? 0 : this.current+1);	
		this.raison[a].setStyles({'z-index':2,'opacity':1});
		this.raison[n].setStyles({'z-index':0,'opacity':0,'visibility':'visible'});
		var fxa=new Fx.Morph(this.raison[a], {duration:this.tempoTrans,wait:false });
		var fxn=new Fx.Morph(this.raison[n], {duration:this.tempoTrans,wait:false });
		var fxma=new Fx.Morph(this.miniraison[a], {duration:this.tempoTrans,wait:false });
		var fxmn=new Fx.Morph(this.miniraison[n], {duration:this.tempoTrans,wait:false });
		fxa.start({'opacity':0});fxma.start({'opacity':this.opacity});
		(function(){this.raison[a].setStyles({'visibility':'hidden'}) } ).delay(this.tempoTrans,this);
		fxn.start({'opacity':1});fxmn.start({'opacity':1});
		this.current=n;	
	},
	
	uX : function()
	{
		$('rotation').addEvents({
				'mouseenter': (function(){
        				$clear(this.timer);this.timer=false;
    			}).bind(this),
    			'mouseout': (function(){
        				if(!this.timer) {  if(this.raison.length>1) this.timer=this.showNext.periodical(this.tempoTimer,this); }
    			}).bind(this)		
		})
		
		for(i=0;i<this.miniraison.length;i++) { 
			this.miniraison[i].addEvents({
					'mouseover': (function(){
								$clear(this.timer);this.timer=false;
						}).bind(this),
					'mouseenter': (function(n){
							$clear(this.timer);this.timer=false;
							var a=this.current;
							this.raison[a].setStyles({'z-index':2,'opacity':1});
							this.raison[n].setStyles({'z-index':0,'opacity':0,'visibility':'visible'});
							var fxa=new Fx.Morph(this.raison[a], {duration:this.tempoTrans2,wait:false });
							var fxn=new Fx.Morph(this.raison[n], {duration:this.tempoTrans2,wait:false });
							var fxma=new Fx.Morph(this.miniraison[a], {duration:this.tempoTrans2,wait:false });
							var fxmn=new Fx.Morph(this.miniraison[n], {duration:this.tempoTrans2,wait:false });
							fxa.start({'opacity':0});fxma.start({'opacity':this.opacity});
							(function(){this.raison[a].setStyles({'visibility':'hidden'}) } ).delay(this.tempoTrans2,this);
							fxn.start({'opacity':1});fxmn.start({'opacity':1});
							this.current=n;	

					}).bind(this,i),
					'mouseout': (function(n){
							if(!this.timer) {  this.timer=this.showNext.periodical(this.tempoTimer,this); }
					}).bind(this,i)		
			})
		}
		
	}

})
