function Ticker(name, id, shiftBy, interval)
{
  this.name = name;
  this.id = id;
  this.shiftBy = shiftBy ? shiftBy : 1;
  this.interval = interval ? interval : 100;
  this.runId = null;
  this.div = document.getElementById(id);

  var node = this.div.firstChild;

  var next;
  while (node)
  {
    next = node.nextSibling;
    if (node.nodeType == 3)
    {
      this.div.removeChild(node);
    }
    node = next;
  }

  this.left = 0;
  this.shiftleftAt = this.div.firstChild.offsetWidth;
  this.div.style.height = this.div.firstChild.offsetHeight;
  this.div.style.width = 2 * screen.availWidth;
  this.div.style.visibility = "visible";
}

function startTicker()
{
  this.stop();
  this.left -= this.shiftBy;

  if (this.left <= -this.shiftleftAt)
  {
    this.left = 0;
    this.div.appendChild(this.div.firstChild);
    this.shiftleftAt = this.div.firstChild.offsetWidth;
  }
  
  this.div.style.left = (this.left + "px");
  this.runId = setTimeout(this.name + ".start()", this.interval);
}

function stopTicker()
{
  if (this.runId)
  {
    clearTimeout(this.runId);
  }
  
  this.runId = null;
}

function hideTicker()
{
  this.stop();
  this.div.style.visibility = "hidden";
}

function showTicker()
{
  this.div.style.visibility = "visible";
  this.start();
}

function changeTickerInterval(newinterval)
{
  if (typeof(newinterval) == "string")
  {
    newinterval = parseInt("0" + newinterval, 10);
  }
  if (typeof(newinterval) == "number" && newinterval > 0)
  {
    this.interval = newinterval;
  }

  this.stop();
  this.start();
}

Ticker.prototype.start = startTicker;
Ticker.prototype.stop = stopTicker;
Ticker.prototype.hide = hideTicker;
Ticker.prototype.show = showTicker;
Ticker.prototype.changeInterval = changeTickerInterval;

var color = "background-color: #ffffff;";
if (window.background)
{
  var color = "background-color: " + background + ";";
}

if (window.transparent && transparent == true)
{
  var color = "";
}

if (window.underline && underline == true)
{
  var text_underline = "underline";
}
else
{
  var text_underline = "none";
}

if (window.fontbold && fontbold == true)
{
  var fontbold = "bold";
}
else
{
  var fontbold = "normal";
}

document.open();
document.write('<style type="text/css">');

document.write('.item         {vertical-align: middle; color: ' + fontcolor + '; text-decoration: none; font-weight: ' + fontbold + '; font-family: ' + font + '; font-size: ' + fontsize + 'px;}');
document.write('.item:link    {}');
document.write('.item:visited {text-decoration: none;}');
document.write('.item:active  {text-decoration: none;}');
document.write('.item:hover   {color: ' + highlightcolor + '; text-decoration: ' + text_underline + ';}');
document.write('.trenner      {vertical-align: middle; color: ' + sepcolor + '; font-weight: ' + fontbold + '; text-decoration: none; font-family: ' + font + '; font-size: ' + fontsize + 'px;}');
document.write('.container    {position: relative; height: 20px; width: ' + width + 'px; overflow: hidden; ' + color + '}');
document.write('.ticker       {position: relative; visibility: hidden; left: 0px; top: 0px; border: 0px none #a00000; width: ' + width + 'px; height: 20px; vertical-align: middle; cursor: default;}');

document.write('</style>');
document.close();

var textcontent = "";
var idx;

for (idx = 0; idx < items.length; idx++)
{
  if (items[idx] == null)
  {
    break;
  }

  textcontent += '<span class="banner">&nbsp;&nbsp;' + items[idx] + '<span class="trenner">&nbsp;&nbsp; +++ &nbsp;</span></span>';
}

var ticker = null;
var ts = speed * 6;

function init()
{
  ticker = new Ticker('ticker', 'tickerId', 1, ts);
  ticker.start();
}

document.open();
document.write('<div align="left" class="container">');
document.write('<div class="ticker" id="tickerId" onMouseover="ticker.stop();" onMouseout="ticker.start();">');
document.write('<nobr>');
document.write(textcontent + textcontent + textcontent);
document.write('</nobr>');
document.write('</div>');
document.write('</div>');
document.close();

init();
