//JS pour le texte défilant

function Defilant(o){

	this.ref=null;
	this.div=$(o.div);
	this.div.defile=this;
	this.div_parent=this.div.parentNode;
	this.up=$(o.up);
	this.up.defile=this;
	this.down=$(o.down);
	this.down.defile=this;
	this.pas=o.pas || 2;
	this.interval=o.interval||20;
	
	this.up.onmouseover=function(){

		this.defile.bouge(1);
	}

	this.down.onmouseover=function(){
		this.defile.bouge(-1);
	}
		this.up.onmouseout=function(){
		
		this.defile.stop();
	}
	this.down.onmouseout=function(){
	
		this.defile.stop();
	}
	this.bouge=function(sens){
		
		this.stop();
		if(sens==-1){
			this.ref=setInterval("$('"+this.div.id+"').monte()",this.interval);
		}else{
			this.ref=setInterval("$('"+this.div.id+"').descend()",this.interval);		
		}
	}
	
	this.stop=function(){
		clearInterval(this.ref);
	}
	this.getTop=function(){
		return parseInt(this.div.style.top);
	}
	this.setTop=function(t){
		this.div.style.top=t+"px";
	}
	this.setTop(0);
	this.div.monte = function(){
		//$("sortie").text+="\n"+this.defile.getTop();
		if(this.defile.getTop()-this.defile.pas>=(this.defile.div_parent.clientHeight-this.clientHeight)){
			this.defile.setTop(this.defile.getTop()-this.defile.pas);
		}else{
			this.defile.setTop(this.defile.div_parent.clientHeight-this.clientHeight);
			this.defile.stop();
		}
		this.defile.MAJ();
	}
	
		
	this.div.descend=function(){
		if(this.defile.getTop()+this.defile.pas<=0){
			this.defile.setTop(this.defile.getTop()+this.defile.pas);
		}else{
			this.defile.setTop(0);
			this.defile.stop();
		}
		this.defile.MAJ();
	}
	
	this.MAJ = function(){
		if(this.getTop() <0){
			this.up.style.visibility="visible";
		}else{
			this.up.style.visibility="hidden";		
		}
		
		if(this.getTop()>this.div_parent.clientHeight -  this.div.clientHeight ){
			this.down.style.visibility="visible";
		}else{
			this.down.style.visibility="hidden";		
		}
	}
	this.MAJ();
}
