//
// Gestion des textes scroll dans un message
// (c) JL.ATX Nov 2009
//

var textDefScrollingStep=2;
var textDefScrollingTempo=50;

function scrollingText(id,text,lngt,hght,bgClr,textClr,scrollingStep,tempo,textSize,divStyleAdds,textStyleAdds) {
 this.idParent=id;
 this.idChild=id+"c";
 this.text=text;
 this.divStyleAdds="";
 this.divStyleAdds+="width:"+lngt+";";
 this.divStyleAdds+="height:"+hght+";";
 if(bgClr) this.divStyleAdds+="background-color:"+bgClr+";";
 if(divStyleAdds) this.divStyleAdds+=divStyleAdds;
 this.textStyleAdds="";
 if(textSize) this.textStyleAdds+="font-size:"+textSize+"px;";
 if(textClr) this.textStyleAdds+="color:"+textClr+";";
 if(textStyleAdds) this.textStyleAdds+=textStyleAdds;
 if(scrollingStep) this.step=scrollingStep; else this.step=textDefScrollingStep;
 if(tempo) this.temp=tempo; else this.temp=textDefScrollingTempo;
 this.displayScrollText=displayScrollText;
 this.displayScrollText();
 this.lngtParent=getlngtParent;
 this.hghtParent=gethghtParent;
 this.lngtChild=getlngtChild;
 this.hghtChild=gethghtChild;
 this.eltParent=document.getElementById(this.idParent);
 this.eltChild=document.getElementById(this.idChild);
 if(!hght||hght==-1) this.eltParent.style.height="100%";
 this.lngt=this.lngtParent();
 this.hght=this.hghtParent();
 this.eltParent.style.visibility="hidden";
 this.eltParent.style.display="none";
 this.offsetReset=offsetReset;
 this.chgColor=chgColor;
 this.ticker;
 this.scrollBloc=scrollBloc;
 this.start=startTicker;
 this.stop=stopTicker;
 this.startWithParam=startTickerWithTextColor;
 this.blocMove=blocMove;
 this.changetext=changetext;
 this.offsetAdjust=offsetAdjust;
 this.start(); }

function chgColor(bgClr,textClr,textSize) {
 this.eltChild.style.color=textClr;
 this.eltParent.style.backgroundColor=bgClr;
 this.eltChild.style.fontSize=textSize+"px"; }

function changetext(newtext) {
 this.text=newtext;
 s="<nobr>"+this.text+"</nobr>";
 this.eltChild.innerHTML=s; }

function getlngtParent() {
 return this.eltParent.offsetWidth+2; }

function gethghtParent() {
 return this.eltParent.offsetHeight+2; }

function getlngtChild() {
 return this.eltChild.offsetWidth+2; }

function gethghtChild() {
 return this.eltChild.offsetHeight+2; }

function blocMove() {
 with(this.eltChild.style) { left=(this.lngtParent())+"px"; } }

function startTickerWithTextColor(text,textClr,bgClr,textSize) {
 this.changetext(text);
 this.chgColor(bgClr, textClr,textSize);
 this.start(); }

function startTicker() {
 if(this.ticker) this.stop();
 id=this.idParent;
 this.eltParent.style.display="block";
 this.eltParent.style.visibility="visible";
 this.blocMove();
 this.lngt=this.lngtParent();
 this.hght=this.hghtParent();
 this.ticker=setInterval(id+".scrollBloc()",this.temp);
 this.eltParent.onmousedown=function() { return false; }
 this.eltParent.onclick=function() { return true; }
 this.eltParent.onmouseover=function() { clearInterval(eval(id+".ticker")); }
 this.eltParent.onmouseout=function() {
         eval(id+".ticker=setInterval(\""+id+".scrollBloc()\","+id+".temp)"); } }

function stopTicker() {
 clearInterval(eval(this.idParent+".ticker"));
 this.eltParent.style.display="none";
 this.eltParent.style.visibility="hidden";
 this.eltParent.onmousedown=function() { return false; }
 this.eltParent.onclick=function() { return false; }
 this.eltParent.onmouseover=function() { return false; }
 this.eltParent.onmouseout=function() { return false; } }

function offsetReset() {
 flag=false;
 if((this.eltChild.offsetLeft+this.lngtChild())>this.eltParent.offsetLeft) flag=true;
 return flag; }

function offsetAdjust() {
 initPos=this.eltParent.offsetLeft+this.lngt;
 endPos=this.eltParent.offsetLeft+this.lngtParent();
 eltChildPos=this.eltChild.offsetLeft;
 if(initPos!=endPos) {
  i=endPos*eltChildPos/initPos;
  this.lngt=this.lngtParent(); }
 else
  i=eltChildPos;
 return i; }

function displayScrollText() {
 s="<div id=\""+this.idParent+"\""+
   " style=\"vertical-align:middle;overflow:hidden;position:relative;"+this.divStyleAdds+"\">";
 text="<nobr>"+this.text+"</nobr>";
 s+="<span id=\""+this.idChild+"\" style=\"position:absolute;"+this.textStyleAdds+"\">"+text+"</span>";
 s+="</div>";
 document.write(s); }

function scrollBloc() {
 if(this.offsetReset()) this.eltChild.style.left=(parseInt(this.offsetAdjust())-this.step)+"px";
 else this.blocMove(); }
