/**
* 
* 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 = new Array();
function NlsScroller(index)
{
    this.contents = [];
    this.intRef = null;
    this.lsTpc = null;

    this.scrollerWidth = 150;
    this.scrollerHeight = 80;
    this.scrollerSpeed = 40;
    this.scrollerStep = 1;
    this.stopOnMouseOver = true;

    this.setContents = setContents;
    this.render = render;
    this.start = start;
    this.stop = stop;
    this.resume = resume;
    this.runScroll = runScroll;
    this.index = index;

    nlsScroller[index] = 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" + this.index + 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[" + this.index + "].stopOnMouseOver) nlsScroller[" + this.index + "].stop()' onmouseout='if (nlsScroller[" + this.index + "].stopOnMouseOver) nlsScroller[" + this.index + "].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" + this.index + i);
        lineNext.style.display = "";
        lineNext.style.left = 0;
        lineNext.style.top = totHg + "px";
        totHg += lineNext.offsetHeight;
        if (i == 0) { continue; }
        line = NlsGetElementById("line" + this.index + (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[" + this.index + "].runScroll())", this.scrollerSpeed);
}

function resume()
{
    if (this.lsTpc == null)
        return;
    if (this.intRef == null)
    {
        this.intRef = window.setInterval("eval(nlsScroller[" + this.index + "].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" + this.index + i);
        pos = parseInt(line.style.top) - this.scrollerStep;
        if (pos <= -line.offsetHeight)
        {
            var t = parseInt(this.lsTpc.style.top) + parseInt(this.lsTpc.offsetHeight);
            line.style.top = (t) + "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);
    }
}