
(function()
{
    var timer, scroller, update, distance, $;

    update = 20;        // Milliseconds between scroll updates
    distance = 4;       // Pixels to scroll contents with each update

    function stopScrollUp()
    {
        clearInterval( timer );
    }

    function scrollUp()
    {
        scroller.scrollTop -= distance;
    }

    function stopScrollDown()
    {
        clearInterval( timer );
    }

    function scrollDown()
    {
        scroller.scrollTop += distance;
    }

    function startScrollDown()
    {
        timer = setInterval( scrollDown, update );
    }

    function startScrollUp()
    {
        timer = setInterval( scrollUp, update );
    }

    /**
    Setup, install event handlers, etc...
    */
    function init()
    {
        var up, down;

        // Area to scroll
        scroller = document.getElementById('scroller');
        if( ! scroller )
        {
            alert('Scroller warning: Area to scroll not found.\n'+
                'A block element with an id of "scroller" is required.');
        }

        // Up Arrow
        up = document.getElementById('scroller-up');
        if( ! up )
        {
            alert('Scroller warning: Up button not found.\n'+
                'An element with an id of "scroller-up" is required.');
        }
        up.onmouseover = startScrollUp;
        up.onmouseout  = stopScrollUp;

        // Down arrow
        down = document.getElementById('scroller-down');
        if( ! down )
        {
            alert('Scroller warning: Down button not found.\n'+
                'An element with an id of "scroller-down" is required.');
        }
        down.onmouseover = startScrollDown;
        down.onmouseout  = stopScrollDown;
    }

    // Initialisation -- have init() run once page has finished loading
    if( $ && $(document).ready )        // jQuery
    {
        $(document).ready( init );
    }
    else if( window.addEventListener)   // DOM Level-2
    {
        window.addEventListener('load', init, false);
    }
    else if( window.attachEvent)        // Sigh... Internet Explorer
    {
        window.attachEvent('onload', init);
    }

})();

