/* Scroll Control */
///////////////////////////////////////////////////////////////////////////
// This script contains all the functions for controlling the news scroller
// Global variables for formatting and scrolling speed or located in the
// document and are required to run the news scroller:
//
// These variable control how the text scrolls across the screen
//      scrollAmount  - num of pixels to move each scrolling iteration
//      scrollSpeed   - num of milliseconds between each scrolling iteration
//      scrollSpace   - num of spaces or carraige returns between messages
//      scrollDir     - direction of scrolling (e.g. right_left or bottom_top)
//      scrollTopPad  - padding in pixels between top side and message
//      scrollLeftPad - padding in pixels between left side and message
//
// These variables determine how the scrolling text appears
//      scrollWidth      - width of scrolling area
//      scrollHeight     - height of scrolling area
//      scrollBGColor    - background color of scrolling area
//      scrollFontColor  - font color of messages
//      scrollFontFace   - font face of messages
//      scrollFontWeight - font weight (bold, plain) of messages
//      scrollFontStyle  - font style (normal, italics) or messages
//      scrollFontSize   - font size in pt. format (8pt 10pt, etc.)
//
// The document must include javascript calls to 2 external files
// The content file must be referenced first
//     <SCRIPT LANGUAGE="JavaScript1.2" SRC="/scroll_content.js">
//     <SCRIPT LANGUAGE="JavaScript1.2" SRC="/scroll_conrol.js">
//
// Include a function call in the ONLOAD event of the document's body
//    ONLOAD="setupScroll();"
//
// Document must contain a layer to contain the scrolling area with
// and ID value of scrollElement
//    <DIV ID="scrollElement">&#160;</DIV>
//
///////////////////////////////////////////////////////////////////////////


var NS4             = (document.layers) ? 1 : 0;
var IE4             = (document.all) ? 1 : 0;
var scrollRepeat    = null;
var styleString     = "";

// Create the style sheet for the document
// This is done dynamically so global variables can be used
styleString  = "<STYLE TYPE='text/css'>\n";
styleString += "<!--\n\n";


// This style positions and formats the scrollElement element
styleString += "#scrollElement {\n";
styleString += "    position:relative;\n";
styleString += "    width:" + scrollWidth + "px;\n";
styleString += "    height:" + scrollHeight + "px;\n";
styleString += "    clip:rect(0 " + scrollWidth + " " + scrollHeight + " 0);\n";
styleString += "    overflow:hidden;\n";
styleString += "    background:" + scrollBGColor + ";\n";
styleString += "    layer-background-color:" + scrollBGColor + ";}\n\n";

// This style positions the scrollContent element in IE
styleString += "#scrollContent {\n";
styleString += "    position:absolute;\n";
styleString += "    visibility: hidden;\n";
styleString += "    width:" + scrollWidth + ";}\n\n";

// This class formats the scrolling messages
styleString += ".scrolling {\n";
styleString += "    font-size:" + scrollFontSize + ";\n";
styleString += "    font-family:" + scrollFontFace + ";\n";
styleString += "    font-weight:" + scrollFontWeight + ";\n";
styleString += "    font-style:" + scrollFontStyle + ";\n";
styleString += "    color:" + scrollFontColor + ";}\n\n";

// Format hyerplinks
styleString += "A:link, A:visited {\n";
styleString += "   color:" + scrollFontColor + ";}\n\n";
styleString += "-->\n";
styleString += "</STYLE>\n\n";

// Write the style sheet to the document
document.writeln(styleString);

// Function: setupScroll
// Purpose:  This function initializes the scrolling messages

function setupScroll() {
    var scrollText, scrollSpacer;
    var i, j;
    var scrollMsg, scrollURL;
    var newLayerSt, jsStr;
    var parentLayer, parentWidth, parentHeight;
     
    // Exit if browser isn't compatible with IE4 or NS4
    if((!IE4) && (!NS4))  {
        return;
    }
 
    // Exit if scrollArray has not been initialized in scroll_content.js
    if(!scrollArray)  {
        return;
    }

    // Use a <PRE> tag for scrolling horizontally.  This keeps the content
    // from wrapping.  Set scrollSpacer to be a space.
    if (scrollDir == 'right_left') {
        scrollText   = "<PRE CLASS=scrolling>";
        scrollSpacer = "&#160;";
    }

    // Use a <SPAN> tag for scrolling vertically.  This allows the content
    // to wrap.  Set scrollSpacer to be a carraige return
    else { 
        scrollText   = "<SPAN CLASS=scrolling>";
        scrollSpacer = "<BR>";
    }

    // Add javascript for hyperlink messages to control scrolling
    jsStr = 'ONMOUSEOVER="stopScroller();" ONMOUSEOUT="startScroller();"';

    // Create text string using values from scroll_content.js
    for(i=0; i<scrollArray.length; i+=2)  {

        scrollMsg = scrollArray[i];
        scrollURL = scrollArray[i+1];

        // Build hyerplink if there is a URL for this message
        if (scrollURL != '') {
            scrollText += buildHyperlink(scrollMsg, scrollURL, jsStr);
        }
        else {
            scrollText += scrollMsg;
        } 
         
        // Add space inbetween each scroll message, except the last one
        if(i < scrollArray.length - 2)  {

            for(j=0; j<scrollSpace; j++)  {
                scrollText += scrollSpacer;
            }
        }
    }

    // Close the appropriate tag
    if (scrollDir == 'right_left') { 
        scrollText += "</PRE>";
    }
    else { 
        scrollText += "</SPAN>";
    }

    // IE4 compatible browsers
    if(IE4)  {

        // Get the width/height of the scrollElement element
        parentWidth = document.all.scrollElement.offsetWidth;
        parentHeight = document.all.scrollElement.offsetHeight;

        // Create a new child element of scrollElement
        newLayerStr = "<SPAN ID='scrollContent'>" + scrollText + "</SPAN>";

        // Insert new scrollContent into scrollElement
        document.all.scrollElement.innerHTML = newLayerStr;

        // Create reference to scroll element
        scrollLayer = document.all.scrollContent;

        // Position scrollContent element
        if (scrollDir == 'right_left') {
            scrollLayer.style.pixelLeft = parentWidth;
            scrollLayer.style.pixelTop  = scrollTopPad;
        }
        else {
            scrollLayer.style.pixelTop = parentHeight;
            scrollLayer.style.pixelLeft = scrollLeftPad;
        }

        // Show scrollContent element
        scrollLayer.style.visibility = "visible";
    }

    // Netscape 4 compatible
    else  {

        // Keep a reference to the scrollElement element 
        parentLayer = document.scrollElement;
        
        // Get the width/height of the scrollElement element
        parentWidth = parentLayer.clip.width;
        parentHeight = parentLayer.clip.height;

        // Create a new child layer of scrollElement
        // scrollLayer is global reference to this layer for NS4
        eval("scrollLayer = new Layer(parentWidth, parentLayer)");

        // Dynamically update contents of new element 
        scrollLayer.document.write(scrollText);
        scrollLayer.document.close();

        // Reposition the the new element 
        if (scrollDir == 'right_left') {
            scrollLayer.left = parentWidth;
            scrollLayer.top  = scrollTopPad; 
        }
        else {
            scrollLayer.top  = parentHeight;
            scrollLayer.left = scrollLeftPad;
        }

        // show the new element
        scrollLayer.visibility = "show";        
    }

    // Start scrolling text
    startScroller();
}

// Function: buildHyperlink
// Purpose:  creates a hyperlink string

function buildHyperlink(text, url, js) {
 
    var linkStr = '<A HREF="' + url + '" ' + js + '>' + text + '</A>';

    return linkStr;
}

// Function: scroll
// Purpose:  Moves the scrollContent element (is called repeatedly) 

function scroll() {

    // IE4 compatible browsers
    if(IE4)  {
        
        if (scrollDir == 'right_left') {

            // Move scroll element
            scrollLayer.style.pixelLeft -= scrollAmount;

            // When text is finished, restart
            if (-scrollLayer.style.pixelLeft >= scrollLayer.offsetWidth)  {
                scrollLayer.style.pixelLeft = scrollLayer.offsetParent.offsetWidth;
            } 
        }
        else {

            // Move scroll element
            scrollLayer.style.pixelTop -= scrollAmount;

            // When text is finished, restart
            if (-scrollLayer.style.pixelTop >= scrollLayer.offsetHeight)  {
                scrollLayer.style.pixelTop = scrollLayer.offsetParent.offsetHeight;
            } 
        }

    }

    // Netscape 4 compatible browsers
    else  {

        // Keep a reference to the scrollElement element 
        parentLayer = document.scrollElement;
        
        if (scrollDir == 'right_left') {

            // Move scroll element
            scrollLayer.left -= scrollAmount;

            // When text is finished, restart
            if(-scrollLayer.left >= scrollLayer.clip.width)  {
                scrollLayer.left = scrollLayer.parentLayer.clip.width;
            }
        }
        else {

            // Move scroll element
            scrollLayer.top -= scrollAmount;

            // When text is finished, restart
            if(-scrollLayer.top >= scrollLayer.clip.height)  {
                scrollLayer.top = scrollLayer.parentLayer.clip.height;
            }
        }
    }
}

// Function: startScroller
// Purpose:  starts the scrolling process

function startScroller() {

    // Repeat every scrollSpeed milliseconds
    scrollRepeat = setInterval("scroll()", scrollSpeed)
}

// Function: stopScroller
// Purpose:  ends the scrolling process

function stopScroller() {

    clearInterval(scrollRepeat);
}
