﻿function FadingScroller(content, divId, delay, maxSteps, stepDelay, startColor, endColor) 
{
    this.content = content;
    this.tickerId = divId;
    this.delay = delay;
    this.maxSteps = maxSteps;
    this.stepDelay = stepDelay;
    this.startColor = startColor;
    this.endColor = endColor;
    this.fadeLinks = 1;
    this.index = -1;    
    this.step = 1;
    this.mouseoverBol = false;
    this.pauseOnMouseOver = true;    
    
    
    this.tmpTimeOutChange;
    this.tmpTimeOutType;
    this.currentChar=20;


    var tickerInstance = this;
    document.getElementById(divId).onmouseover = function(){tickerInstance.mouseoverBol = true;}
    document.getElementById(divId).onmouseout = function(){tickerInstance.mouseoverBol = false;}
    this.ChangeContent();
}

/*FadingScroller.prototype.ChangeContent = function(){    
    if(this.step >= this.maxSteps) {      
        
        if (!this.mouseoverBol) {
            //alert(this.index + "_" + this.mouseoverBol);
            this.step = 1;
            this.index++;  
        }      
        
        if (this.index >= this.content.length)
            this.index = 0        
        
        var scrollerInstance = this;
        setTimeout(function(){scrollerInstance.ChangeContent()}, this.delay);
    }
    else {
        if(this.step == 1)
            document.getElementById(this.tickerId).innerHTML = this.content[this.index];           
        document.getElementById(this.tickerId).style.color = this.GetStepColor(this.step);
        
        if (this.fadeLinks)
            this.LinkColorChange(this.step);
        
        this.step++;
        var scrollerInstance = this;
        setTimeout(function(){scrollerInstance.ChangeContent()}, this.stepDelay);
    }
}

FadingScroller.prototype.LinkColorChange = function(step) {
  var obj = document.getElementById(this.tickerId).getElementsByTagName("A");
  if (obj.length > 0){
    for (i=0; i < obj.length; i++)
      obj[i].style.color = this.GetStepColor(step);
  }
}

FadingScroller.prototype.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] + ")");
}*/


//////////////////Added By We


FadingScroller.prototype.ChangeContent = function()
{    
    this.index++;
    if (this.index >= this.content.length)
        this.index = 0        
    var scrollerInstance = this;    
    this.type();
    clearTimeout(this.tmpTimeOut);
}


FadingScroller.prototype.type=function()
{
    var scrollerInstance = this;
    document.getElementById(this.tickerId).innerHTML = this.content[this.index].substr(0, 20)+this.content[this.index].substr(20, this.currentChar);
    this.currentChar++;
    if (this.currentChar>this.content[this.index].length)
    {
        this.currentChar=20;
        clearTimeout(this.tmpTimeOutType);
        this.tmpTimeOut=setTimeout(function(){scrollerInstance.ChangeContent()}, this.delay);
    }
    else
    {

        this.tmpTimeOutType=setTimeout(function(){scrollerInstance.type()}, this.stepDelay);
    }

}