/**
* 
* Copyright 2005, addObject.com. All Rights Reserved
* Author Jack Hermanto, www.addobject.com
*
* By downloading this script means you are agreed on:
* 1 You MUST not delete this header.
* 2.You can use this script (not part of this script) in your non commercial application 
*   or website
* 3.You have to obtain a copy of license if you want to include this scroller in commercial
*   website, or products
*/

var nlsScroller = [];
function NlsScroller() {
  this.contents = [];
  this.intRef = null;
  this.lsTpc = null;
  
  this.scrollerWidth = 188;
  this.scrollerHeight = 150;
  this.scrollerSpeed = 20;
  this.scrollerStep = 1;
  this.stopOnMouseOver = true;
  
  this.setContents = setContents;
  this.render = render;
  this.start = start;
  this.stop= stop;
  this.resume = resume;
  this.runScroll = runScroll;
  
  nlsScroller[nlsScroller.length] = this;
}

function setContents(cnt) {
  cnt = cnt.replace(/<span>nlsscroller-break<\/span>/gi, "<span>nlsscroller-break</span>");
  this.contents = cnt.split("<span>nlsscroller-break</span>");
}

function render(plc) {
  var pos="relative", dsp="none";
  if (window.navigator.appName=="Microsoft Internet Explorer" && window.navigator.appVersion.indexOf("MSIE 4") != -1) {
    pos="absolute";
    dsp="block";
  }  
  var str = "";
  for (var i=0; i<this.contents.length; i++) {
    str += ("<table id='line"+i+"' width='100%' style='display:"+dsp+";position:absolute;top:0px' border='0' cellpadding='0' cellspacing='0'><tr><td class='content'>" + this.contents[i] + "</td></tr></table>");
  }
  str = ("<div class='scroller' style='position:"+pos+";overflow:hidden;clip:rect(0px "+this.scrollerWidth+"px "+this.scrollerHeight+"px 0px);width:"+this.scrollerWidth+"px;height:"+this.scrollerHeight+"px;' onmouseover='if (nlsScroller[0].stopOnMouseOver) nlsScroller[0].stop()' onmouseout='if (nlsScroller[0].stopOnMouseOver) nlsScroller[0].resume()'>" + str + "</div>" );
  if (plc) {
    var tPlc = NlsGetElementById(plc);
    tPlc.innerHTML = str; return str;
  } else {
    document.write(str); return "";
  }  
}

function start() {
  var line, lineNext;
  totHg=0;
  for (var i=0; i<this.contents.length; i++) {
    lineNext= NlsGetElementById("line"+i);
    lineNext.style.display = "";
    lineNext.style.left = 0;
    lineNext.style.top = totHg+"px";
    totHg += lineNext.offsetHeight;
    if (i==0) { continue; }
    line = NlsGetElementById("line"+(i-1));
    lineNext.style.top = line.style.top.replace(/(\d+)px/gi, "$1")*1 + line.offsetHeight;
  }
  this.lsTpc=lineNext;
  this.stop();
  this.intRef = window.setInterval("eval(nlsScroller[0].runScroll())", this.scrollerSpeed);
}

function resume() {
  if (this.intRef==null) {
    this.intRef = window.setInterval("eval(nlsScroller[0].runScroll())", this.scrollerSpeed);
  }
}

function stop() {
  if (this.intRef) {
    window.clearInterval(this.intRef);
    this.intRef = null;
  }
}

function runScroll() {
  var line, pos;
  for (var i=0; i<this.contents.length; i++) {
    line = NlsGetElementById("line"+i);
    pos = parseInt(line.style.top)- this.scrollerStep;
    if (pos <= -line.offsetHeight) {
      var t=parseInt(this.lsTpc.style.top) + parseInt(this.lsTpc.offsetHeight);
      if (t > this.scrollerHeight) {
        line.style.top = (t)+"px";
      } else {
        line.style.top = (this.scrollerHeight) + "px";
      }
      this.lsTpc=line;
    } else {
      line.style.top = pos+"px";
    }
  }
}


function NlsGetElementById(id) {
    if (document.all) {
        return document.all(id);
    } else
    if (document.getElementById) {
        return document.getElementById(id);
    }
}
