﻿/*
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>
    
    All div tags within the container div must be placed side by side, otherwise carriage return/new line characters
    cause the function incorrectly.
    
    Once a div disappears of the screen it is remove from the to of container divs elements collection and appended to 
    the bottom.

SETUP:
    The function initScroller should be called in the body tag's onload event.
    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 chagning the variable intScrollSpeed - Increase to slow down, decrease to speed up.
*/

var intContainerStartTop;
var objContainer;
var intMarginTop = 0;
var colChildDivs;
var childNodes;
var initScrollAmount = 1;
var intScrollSpeed = 40; 
var scrollAmount = initScrollAmount;

function initScoller () {
    objContainer = document.getElementById("container-ticker");
    childNodes = objContainer.childNodes;
    
    // TO DO: Any carriage returns are picked up as child elements within the container div. These need to be stripped
    // out so only div elements are returned.
    
    setInterval ("moveup()", intScrollSpeed);
}

function moveup () {
    reduceMargin();
    
    if ((intMarginTop*-1) > childNodes[0].offsetHeight)
    {
        addNode(childNodes[0].cloneNode(true));
        deleteNode();
        intMarginTop =0;
        reduceMargin();
    }
}

function reduceMargin () {
    intMarginTop = intMarginTop - scrollAmount;
    childNodes[0].style.marginTop = intMarginTop + "px";
}

function deleteNode () {
    objContainer.removeChild(childNodes[0]);
}

function addNode (newDiv) {
    newDiv.style.margin = "0px";
    objContainer.appendChild(newDiv);
}

function startScrolling() {
    scrollAmount = initScrollAmount;
}

function stopScrolling() {
    scrollAmount = 0;
}