﻿        // Higher = Faster, Lower = slower and more smoothly   (equates to pixels per move on the screen)
        var marqueeSteps = 1;
        // Lower value = Faster  (# equates to Milleseconds - ms between moves.  Watch out for CPU usage if too low)
        var marqueeSpeed = 25;
        // Make the marquee stop moving when user moves his mouse over it, set to 'true' to enable, 'false' to disable.
        var marqueeStopOnMouseOver = true;
        // "top" or "bottom" position set here
        var marqueePosition = 'top';

        /* Don't change anything below here */
        var marqueeObj;
        var marqueeTextObj;
        var marqueeTmpStep;
        var marqueeTextObjects = new Array();
        var marqueeHiddenSpans = new Array();
        var marqueeIndex = 0;

        var hScrollRefreshIntervalId;

        function PositionScrollingMarquee(e, timeout) {
            if (document.all) e = event;
            if (marqueePosition.toLowerCase() == 'top') {
                //Place the marquee at the top of the page
                marqueeObj.style.top = '0px';
            }
            else {
                //Place the arquee at the bottom of the page
                marqueeObj.style.bottom = '-1px';
            }
            if (document.all && !timeout) setTimeout('PositionScrollingMarquee(false,true)', 500)
        }


        function MoveScrollingMarquee() {

            //Get left-side position of the marquee
            var leftPos = marqueeTextObj.offsetLeft;

            //Subtract step count set at global level and kept track of in InitMarquee (Move DIV left)
            leftPos = leftPos - marqueeTmpStep;

            //Left position of DIV + [array value] + width of a single 'marqueeTextObj'
            var rightEdge = leftPos + marqueeHiddenSpans[marqueeIndex].offsetLeft + marqueeTextObj.offsetWidth;

            //If the right edge calculated above is less than 0, this means the ENTIRE marquee is off
            //the left side of the page.  At this point reset the scrolling marquee to the right side of the page to re-scroll.
            if (rightEdge < 0) {


                //Reset the marquee to be just off the right side of the page which is done
                //by making its left position the width of the page
                leftPos = document.documentElement.offsetWidth;
                marqueeTextObj.style.left = leftPos + 'px';

                //Set marquee properties
                marqueeTextObj.style.display = 'none';

                marqueeIndex++;
                if (marqueeIndex >= marqueeTextObjects.length) marqueeIndex = 0;
                marqueeObj = marqueeTextObjects[marqueeIndex];

                marqueeTextObj.style.display = 'block';

            }

            //Move the DIV to the left position calculated above.  This is where the 'magic' happens
            //and the 'scrolling' occurs.
            marqueeTextObj.style.left = leftPos + 'px';

        }

        function Stop_MoveScrollingMarquee() {
            if (marqueeStopOnMouseOver) marqueeTmpStep = 0;
        }


        function Resume_MoveScrollingMarquee() {
            marqueeTmpStep = marqueeSteps;
        }

        function InitHorizontalScrollMarquee(MarqueeDivControlID) {

            //Get the marquee object properties using the ID passed in from the calling code:
            marqueeObj = document.getElementById(MarqueeDivControlID);


            var spans = marqueeObj.getElementsByTagName('DIV');
            for (var no = 0; no < spans.length; no++) {

                //Find the 'MarqueeTextObj' class and set its properties
                if (spans[no].className == 'MarqueeTextObj') {
                    marqueeTextObj = spans[no];
                    spans[no].style.display = 'block';

                    marqueeTextObjects.push(spans[no]);
                    var hiddenSpan = document.createElement('SPAN');
                    hiddenSpan.innerHTML = ' '
                    spans[no].appendChild(hiddenSpan);
                    marqueeHiddenSpans.push(hiddenSpan);
                }
            }
            if (marqueePosition.toLowerCase() == 'top') {
                marqueeObj.style.top = '0px';
            }
            else {
                if (document.all) {
                    marqueeObj.style.bottom = '0px';
                }
                else {
                    marqueeObj.style.bottom = '-1px';
                }
            }

            //Set the left position of the marquee = to the width of the page which essentially places 
            //its leftmost part at the right end of the page.
            marqueeTextObj.style.left = document.documentElement.offsetWidth + 'px';

            //Define the mouse events; these are wired up to the varibale named 'marqueeStopOnMouseOver' which is false by default.
            marqueeObj.onmouseover = Stop_MoveScrollingMarquee;
            marqueeObj.onmouseout = Resume_MoveScrollingMarquee;
            if (document.all) window.onscroll = PositionScrollingMarquee; else marqueeObj.style.position = 'relative';

            marqueeObj.style.display = 'block';
            marqueeTmpStep = marqueeSteps;

            //setInterval() returns an interval ID, which later can be passed to clearInterval(): to stop repeat calls if desired;
            hScrollRefreshIntervalId = setInterval('MoveScrollingMarquee()', marqueeSpeed);

        }


