/*
Vertical Scroller

Kieran Iles - 9 may 2007
DESCRIPTION: 
    Scrolls a set of div upwards in a container div. 
    The item divs must be contained in the following divs
    
    <div id="hider">
        <div id="container"><!-- ITEM DIVS HERE --></div>
    </div>
  
    Once a div disappears of the screen it is remove from the top of container div's elements collection and 
    appended to the bottom.

SETUP:
    The function initVerticalScroller should be called in the body tag's onload event or at the bottom of the html page.
    The functions startScrolling and stopScrolling should be called in the onmouseout and onmouseover respectively, of the 
    item divs.
    The scroll speed can be set by changing the variable intScrollSpeed - Increase to slow down, decrease to speed up.
*/

var intContainerStartTop;
var objContainer;
var intMarginTop = 0;
var colChildDivs;
var childNodes;
var intScrollSpeed = 50; 
var initScrollAmount = 1;
var scrollAmount = initScrollAmount;

function initVerticalScroller () {
    var intCounter = 0;
    objContainer = document.getElementById("container");
    if (objContainer != null)
    {
        childNodes = objContainer.childNodes;
        
        // Loop through child collection remove any elements that aren't divs.
        for (intCounter=0; intCounter < childNodes.length; intCounter++)
        {
            if (childNodes[intCounter].nodeName != 'div' && childNodes[intCounter].nodeName != 'DIV')
            {
                deleteNode(intCounter);
            }
        }
        
        setInterval ("moveup()", intScrollSpeed);
    }
}

function moveup () {
    reduceMargin();
    
    if ((intMarginTop*-1) > childNodes[0].offsetHeight)
    {
        addNode(childNodes[0].cloneNode(true));
        deleteNode(0);
        intMarginTop = 0;
    }
}

function reduceMargin () {
    intMarginTop = intMarginTop - scrollAmount;
    childNodes[0].style.marginTop = intMarginTop + "px";
}

function deleteNode (_nodePosition) {
    objContainer.removeChild(childNodes[_nodePosition]);
}

function addNode (newDiv) {
    newDiv.style.margin = "";
    objContainer.appendChild(newDiv);
}

function startScrolling() {
    scrollAmount = initScrollAmount;
}

function stopScrolling() {
    scrollAmount = 0;
}