function LoadTickerRelation()
{
  if (!document.getElementsByTagName) return;
  var divs = document.getElementsByTagName('div');
  for (var i = 0; i < divs.length; i++) 
  {
    div = divs[i];
    if (div.getAttribute("rel") == 'ticker')
    {
      new TickerObject(div);
    }
  }
  start();
}

tickerObjs = {};
tickerObjs.count = 0;

function TickerObject(div)
{
  this.id = div.id;
  this.speed = div.getAttribute("speed");
  this.width = div.getAttribute("width");
  this.height = div.getAttribute("height");
  this.clipwidth = div.getAttribute("clipwidth");
  
  div.style.position = 'relative';
  div.style.width = this.clipwidth + 'px';
  div.style.height = this.height + 'px';
  div.style.overflow = 'hidden';
     
  c1 = '<div id="' + div.id + '_1" style="overflow:hidden;position:absolute;left:0px;top:0px;width:'+ this.width + 'px;">' + div.innerHTML + '</div>';
  c2 = '<div id="' + div.id + '_2" style="overflow:hidden;position:absolute;left:' + this.width + 'px;top:0px;width:'+ this.width + 'px;">' + div.innerHTML + '</div>';
  div.innerHTML = c1 + c2;
  
  if (this.speed >= 0)
  {
    this.oSlide1 = document.getElementById(this.id + "_1");
    this.oSlide2 = document.getElementById(this.id + "_2");
  }
  else
  {
    this.oSlide1 = document.getElementById(this.id + "_2");
    this.oSlide2 = document.getElementById(this.id + "_1");
  }
  tickerObjs[tickerObjs.count] = this;
  tickerObjs.count = tickerObjs.count + 1;
};

TickerObject.prototype.moveSlide = function()
{
  if (document.getElementById)
  {
    if (this.speed > 0)
    {
      if (parseInt(this.oSlide1.style.left) < this.width * (-1))
      {
        var temp = this.oSlide1;
        this.oSlide1 = this.oSlide2;
        this.oSlide2 = temp;
        this.oSlide2.style.left = (this.width > this.clipwidth) ? this.width + 'px' : this.clipwidth + 'px';
      }
      this.oSlide1.style.left = parseInt(this.oSlide1.style.left) - this.speed + 'px';
      this.oSlide2.style.left = parseInt(this.oSlide2.style.left) - this.speed + 'px';
    }
    if (this.speed < 0)
    {
      if (parseInt(this.oSlide1.style.left) > this.clipwidth)
      {
        var temp = this.oSlide1;
        this.oSlide1 = this.oSlide2;
        this.oSlide2 = temp;
        this.oSlide2.style.left = - this.width + 'px';
      }
      this.oSlide1.style.left = parseInt(this.oSlide1.style.left) - this.speed + 'px';
      this.oSlide2.style.left = parseInt(this.oSlide2.style.left) - this.speed + 'px';
    }    
  }
}

function start()
{
  for (var i=0; i < tickerObjs.count; i++)
  {
    if (tickerObjs[i])
    {
      tickerObjs[i].moveSlide();
    }
  }
  temp = setTimeout("start()",100);
}

//////////////////////////////////////////////////////////////////////
// LOADER
//////////////////////////////////////////////////////////////////////

addLoadEvent(LoadTickerRelation);

function addLoadEvent(func)
{
  if (window.addEventListener) //run onload in DOM2 browsers
  {
    window.addEventListener("load", function(){ func(); }, false);
  }
  else if (window.attachEvent) //run onload in IE5.5+
  {
    window.attachEvent("onload", function(){ func(); });
  }
  else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
  {
    setTimeout(function(){ func(); }, 500);
  }
}