
var interval = 1; 
var increment = 6; 
var pause = 2000; 
var leftPadding = 2; 
var topPadding = 1; 

var bannerLeft = holdspace.offsetLeft; 
var bannerTop = holdspace.offsetTop; 
var bannerWidth = holdspace.width; 
var bannerHeight = holdspace.height; 


function reCalculate()
{
    interval = 1; 
    increment = 6; 
    pause = 10000; 
    leftPadding = 2; 
    topPadding = 1; 

    bannerLeft = holdspace.offsetLeft; 
    bannerTop = holdspace.offsetTop; 
    bannerWidth = holdspace.width; 
    bannerHeight = holdspace.height; 
}


if ( typeof window.addEventListener != "undefined" ){
    window.addEventListener( "load", startBanner, false );
    window.addEventListener( "resize", reStartBanner, false );
    }
else if ( typeof window.attachEvent != "undefined" ) {
        window.attachEvent( "onload", startBanner );
        window.attachEvent( "onresize", reStartBanner );
}
else {
    if ( window.onload != null ) {
        var oldOnload = window.onload;
        window.onload = function (e) { oldOnload(e); startBanner(); };
    }
    else
        window.onload = startBanner;
        
    if ( window.onresize != null ) {
        var oldOnresize = window.onresize;
        window.onresize = function (e) { oldOnresize(e); reStartBanner(); };
    }
    else
        window.onresize = reStartBanner;
}


function showMessage(n, show) {
    var whichEl = eval("message" + n + ".style");
    whichEl.visibility = (show) ? "visible" : "hidden";
}

function nextMessage() {
    var fromInd = current;
    current = (fromInd == ar.length - 2) ? 0 : fromInd + 1;
    scrollBanner(fromInd, current);
}

function getnumpix(num)
{
    return num.replace("px","");
}

function moveUp() {
    fromEl.top = (getnumpix(fromEl.top) - increment) + "px";
    if ((getnumpix(toEl.top) - increment) <= toElTarget) {
      toEl.top = toElTarget + "px";
      clearInterval(intervalID);
      fromEl.visibility = "hidden";
      timeoutID = setTimeout("nextMessage()", pause);
    } else {
      toEl.top = (getnumpix(toEl.top) - increment) + "px";
    }
}

function scrollBanner(from, to) {
    fromEl = eval("message" + from + ".style");
    toEl = eval("message" + to + ".style");
    toEl.top = (getnumpix(fromEl.top) + bannerHeight) + "px";
    toElTarget = getnumpix(fromEl.top);
    showMessage(to, true); 
    intervalID = setInterval("moveUp()", interval);
}

function makeBanner() {
    node = document.createElement("div");  
    node.setAttribute("id", "banner");            
    node.style.position = "absolute";
    node.style.clip = "rect(0 " + bannerWidth + " " + bannerHeight + " 0)";
    node.style.width = bannerWidth;
    node.style.height = bannerHeight;
    node.style.left = bannerLeft;
    node.style.top = bannerTop;
                
    for (var i = ar.length - 2; i >= 0; i--) {
        subnode = document.createElement("div");
        subnode.setAttribute("id", "message" + i);
        subnode.style.visibility = "hidden";
        subnode.style.position = "absolute";
        subnode.style.width = bannerWidth - leftPadding;
        subnode.style.left = leftPadding;
        subnode.style.top = topPadding;

        subnode.innerHTML = unescape(ar[i]);
        node.appendChild(subnode);
    }
    //alert(node.outerHTML)
    document.body.appendChild(node);
}



function startBanner() {
    window.setTimeout(trulyStartBanner,1000)
}
function trulyStartBanner() {
    reCalculate();
    if (ar.length > 1)
    {
        makeBanner()
        showMessage(0, true);
        current = 0;
        timeoutID = setTimeout("nextMessage()", pause);
    }
}

function reStartBanner()
{
    if (ar.length > 1)
    {
        bannerLeft = holdspace.offsetLeft; 
        bannerTop = holdspace.offsetTop; 
        banner.style.left = bannerLeft;
        banner.style.top = bannerTop;
    }
}


