

/***********************************************
* Fading Scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function FadeScroller()
{
    this.id = null;
    this.delay = 4000; //set delay between message change (in miliseconds)
    this.maxsteps=30; // number of steps to take to change from start color to endcolor
    this.stepdelay=40; // time in miliseconds of a single step
    //**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
    this.startcolor= new Array(255,255,255); // start color (red, green, blue)
    this.endcolor=new Array(54,54,54); // end color (red, green, blue)
    this.cont = true;
    this.isrunning = true;

    this.fwidth='150px'; //set scroller width
    this.fheight='150px'; //set scroller height

    this.fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

    ///No need to edit below this line/////////////////

    this.fcontent=new Array();
    this.begintag='<div>'; //set opening tag, such as font declarations

    this.closetag='</div>';

    this.ie4=document.all&&!document.getElementById;
    this.DOM2=document.getElementById;
    this.faderdelay=0;
    this.index=0;


    /*Rafael Raposo edited function*/
    //function to change content
    this.changecontent = function(){
      if (this.cont == false)
      {    
        return;
      }        
      if (this.index>=this.fcontent.length)
        this.index=0
      if (this.DOM2){
        document.getElementById(this.id).style.color="rgb("+ this.startcolor[0]+", "+ this.startcolor[1]+", "+ this.startcolor[2]+")"
        document.getElementById(this.id).innerHTML=this.begintag+this.fcontent[this.index]+this.closetag
        if (this.fadelinks)
          this.linkcolorchange(1);
          
        this.colorfade(1, 15);
      }
      else if (this.ie4)
        document.all.fscroller.innerHTML=this.begintag+this.fcontent[this.index]+this.closetag;
      this.index++
    }

    // colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
    // Modified by Dynamicdrive.com

    this.linkcolorchange = function(step){
      var obj=document.getElementById(this.id).getElementsByTagName("A");
      if (obj.length>0){
        for (i=0;i<obj.length;i++)
          obj[i].style.color=this.getstepcolor(step);
      }
    }

    /*Rafael Raposo edited function*/
    this.fadecounter = null;
    this.changecounter = null;
    
    this.colorfade = function(step) {
      if (this.cont == false)
      {
        clearTimeout(this.fadecounter);
        document.getElementById(this.id).style.color = "rgb("+this.endcolor[0]+", "+this.endcolor[1]+", "+this.endcolor[2]+")"
        return;
      }
      if(step<=this.maxsteps) {	
        document.getElementById(this.id).style.color=this.getstepcolor(step);
        if (this.fadelinks)
          this.linkcolorchange(step);
        step++;
        this.fadecounter=setTimeout(this.id + ".colorfade("+step+")",this.stepdelay);
      }else{
        clearTimeout(this.fadecounter);
        document.getElementById(this.id).style.color="rgb("+this.endcolor[0]+", "+this.endcolor[1]+", "+this.endcolor[2]+")";
        this.changecounter = setTimeout(this.id + ".changecontent()", this.delay);
      }
    }

    /*Rafael Raposo's new function*/
    this.getstepcolor = function(step) {
      var diff
      var newcolor=new Array(3);
      for(var i=0;i<3;i++) {
        diff = (this.startcolor[i]-this.endcolor[i]);
        if(diff > 0) {
          newcolor[i] = this.startcolor[i]-(Math.round((diff/this.maxsteps))*step);
        } else {
          newcolor[i] = this.startcolor[i]+(Math.round((Math.abs(diff)/this.maxsteps))*step);
        }
      }
      return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
    }

    this.onMouseOver = function()
    {
        this.cont = false;
    }

    this.onMouseOut = function()
    {
        if (this.cont == false)
        {
            this.cont = true;
            clearTimeout(this.fadecounter);
            clearTimeout(this.changecounter);
            this.changecontent()
        }
    }
}



