// Place a DIV on the page with the ID 'scroller' then call createScroller
// Control the width and appearance of the scrolling text by placing it in a P element and applying CSS
var scrollerwidth = "480px"; // The default width of the scroller content DIV
var scrollerheight = "360px";
var scrollerspeed = 1; // Scrollers speed (larger is faster 1-10)
var scrollercontent = null; // The HTML content to scroll
var backgroundImage = 'images/wide_20.gif'; // image displayed behind the scrolling text
var moreStyle = null;
var pauseit = 1;
var pauseEnabled = false;   // If true then scroller pauses on mouse over
var repeat = false;  // If false then scroll to the top and then stop otherwise continue loop
var iedom = document.all || document.getElementById;
var actualheight = '';
var cross_scroller, ns_scroller;
var copyspeed, pausespeed;

// repeatScroll default = true
// styleCSS = any additional styling to apply to the outer DIV (don't include quotes e.g [ border-width: 1px; ])
function createScroller(width, height, backgroundImageUrl, content, speed, enablePause, repeatScroll, styleCSS) {

    scrollerwidth = (width == null) ? scrollerwidth : parseInt(width) + 'px';
    scrollerheight = (height == null) ? scrollerheight : parseInt(height) + 'px';
    backgroundImage = (backgroundImageUrl == null) ? '' : backgroundImageUrl;
    moreStyle = (styleCSS == null) ? '' : styleCSS;
    scrollercontent = (content == null) ? 'Scroller Error: No Content was specified' : content;
    
    if (scrollercontent.length == 0)
        scrollercontent = 'Scroller Error: No Content was specified';

    repeat = (repeatScroll == null) ? false : repeatScroll;
    pauseEnabled = (enablePause == null) ? false : enablePause;

    speed = ((speed == null) || (isNaN(speed))) ? 1 : speed;
    scrollerspeed = (speed < 1 || speed > 10) ? 1 : speed;
    scrollerspeed = (document.all) ? scrollerspeed : Math.max(1, scrollerspeed - 1) //slow speed down by 1 for NS var 
    copyspeed = scrollerspeed
    pausespeed = (pauseit == 0) ? copyspeed : 0

    if (!pauseEnabled)
        pausespeed = copyspeed;

    createContainer();
    populate();
}
function createContainer() {
    if (iedom || document.layers) {

        var scrollerDiv;

        if (iedom) {
            scrollerDiv = document.getElementById ? document.getElementById('scroller') : document.all.iescroller;
            var ieDivContent = '<div style="position:relative; width:' + scrollerwidth + ';height:' + scrollerheight + '; background-image: url(' + backgroundImage + ');'+ moreStyle+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">' +
                                '<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">' +
                                '</div></div>';
            scrollerDiv.innerHTML = ieDivContent;
        }
        else if (document.layers) {
            scrollerDiv = document.scroller;
            var nsDivContent = '<ilayer width=' + scrollerwidth + ' height=' + scrollerheight + ' name="ns_scroller" background="' + backgroundImage + '"/>' +
                                '<layer name="ns_scroller2" width=' + scrollerwidth + ' height=' + scrollerheight + ' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>' +
                                '</ilayer>';
            scrollerDiv.innerHTML = nsDivContent;
        }
    }
}
function populate() {
    if (iedom) {
        cross_scroller = document.getElementById ? document.getElementById('iescroller') : document.all.iescroller;
        cross_scroller.style.top = parseInt(scrollerheight) + 8 + 'px';
        cross_scroller.innerHTML = scrollercontent;
        actualheight = cross_scroller.offsetHeight;
    } else if (document.layers) {
        ns_scroller = document.ns_scroller.document.ns_scroller2;
        ns_scroller.top = parseInt(scrollerheight) + 8;
        ns_scroller.document.write(scrollercontent);
        ns_scroller.document.close();
        actualheight = ns_scroller.document.height;
    }
    lefttime = setInterval("scrollscroller()", 30);
}

function scrollscroller() {
    if (iedom) {
        if (parseInt(cross_scroller.style.top) > (actualheight * (-1) + 8))
            cross_scroller.style.top = parseInt(cross_scroller.style.top) - copyspeed + "px";
        else
            cross_scroller.style.top = parseInt(scrollerheight) + 8 + "px"
    }
    else
        if (document.layers) {
        if (ns_scroller.top > (actualheight * (-1) + 8))
            ns_scroller.top -= copyspeed;
        else
            ns_scroller.top = parseInt(scrollerheight) + 8
    }

    if (repeat==false) {
        if ((iedom) && (parseInt(cross_scroller.style.top) < 1))
            clearInterval(lefttime);
        else if ((document.layers) && (ns_scroller.top < 1))
            clearInterval(lefttime);
    }
}
