var SCROLLING_TEXT_ID = "scrolling_text";

var scroller;

(function()
{
  if (window.addEventListener)
  {
    window.addEventListener("load", setup, false);
  }
  else
  {
    window.attachEvent("onload", setup);
  }

  function setup()
  {	  
    scroller = new Scroller(SCROLLING_TEXT_ID);
  }
})();

//Scroller class
function Scroller(id)
{
  this.element = document.getElementById(id);
  var obj = this;
  this.element.onmouseover = function(){obj.stop_scroll();};
  this.element.onmouseout = function(){obj.scroll();};
  
  this.timer = null;
  
  this.speed = 100;	//1000 = 1 second
                      
  this.scroll();
}

Scroller.prototype.scroll = function()
{	  	  	  
  var text = this.element.firstChild.nodeValue;
  if (text.length > 0)
  {
    //Remove the first character and add it to the end
    text = text.substring(1) + text.substring(0, 1);
    this.element.firstChild.nodeValue = text;
    
    var obj = this;
    this.timer = setTimeout(function(){obj.scroll();}, this.speed);      
  }
}

Scroller.prototype.stop_scroll = function()
{
  if (this.timer)
  {
    clearTimeout(this.timer);
  }
}
