// $Header: /e2RM/Registrant/javaScript/donorScroll.js 1     1/08/07 10:29a Plee $
// $Log: /e2RM/Registrant/javaScript/donorScroll.js $
// 
// 1     1/08/07 10:29a Plee
// - moved the javascript into the javascript folder
// - added pageItemPreview.aspx
// 
// 6     1/17/06 12:55p Plee
// recalculate and fixed the clip height and scroll height
// 
// 5     5/26/05 5:34p Gjohnson
// fix push down to use clip height instead of scroll height.
// 
// 4     5/26/05 10:51a Gjohnson
// start list at the bottom so top item stays visibile for a bit.
// 
// 3     5/25/05 3:35p Gjohnson
// changed scroll speed (slowed it down)
// 
// 2     5/16/05 5:04p Gjohnson
// fix it up for Firefox.
// 
// 1     5/13/05 3:09p Gjohnson
// added donorScroll.js to project

var scrollList = 0 // indicates empty list - don't know if new Array(0) works in all browsers
var timerID = 0
var scrollHeight

window.onload = scroll

// build the list of elements to scroll: an array called scrollList
function initializeScrollList() {
    var x = 0 // number of entries in scrollList so far
    
    for (i = 0; i < document.getElementsByTagName("*").length; i++) { 
        var oElement = document.getElementsByTagName("*")[i]

        if (oElement.getAttribute("scrollie")) {
            if (scrollList == 0)
                scrollList = new Array(1)
                
            scrollList[x++] = oElement
            oElement.style.position = "relative" // position must be set for style.top
            oElement.e2_Top = 0 // create attribute to hold numeric value of style.top
        }
    }
}

function stopScroll() {
    clearInterval(timerID)
}

function startScroll() {
    if (scrollList != 4)
        timerID = setInterval("scrollUpOne()", 30)
}

function scroll() {
    initializeScrollList()
    
    if (scrollList == 0)
        return
        
    // Set the position of the parent to "absolute". This does 2 things:
    // Allows clip to work (clip only works on absolutely positioned element.)
    // Takes up no space in the normal flow layout of HTML tags, so the list
    // of donors can be as long as wanted, and it won't affect the layout of the page.

    var oParent = scrollList[0].parentNode;
    oParent.style.position = "absolute"
    
    // For short lists, of 1 or 2 or 3 elements, set the bottom to
    // have a space of 1 extra element to have them scroll nicely.
    // Clip anything over 3 entries.
    
/*
	var clipHeight = scrollList[0].offsetHeight + scrollList[1].offsetHeight * 2
    if (scrollList.length == 3)
        clipHeight = scrollList[0].offsetHeight + scrollList[1].offsetHeight + (scrollList[2].offsetHeight * 2)
    if (scrollList.length == 4)
        clipHeight = scrollList[0].offsetHeight + scrollList[1].offsetHeight + scrollList[2].offsetHeight + (scrollList[3].offsetHeight * 2)
    if (scrollList.length > 4)
        clipHeight = scrollList[0].offsetHeight + scrollList[1].offsetHeight + scrollList[2].offsetHeight + scrollList[3].offsetHeight + scrollList[4].offsetHeight
*/

	// fixing the clip height to 165px
    var clipHeight = 280
    oParent.style.clip = "rect(0px auto " + clipHeight + "px auto)"
    
    if (oParent.offsetHeight < clipHeight)
        scrollHeight = clipHeight
    else
        scrollHeight = oParent.offsetHeight   
    
    // push everything down for start-up so top item starts at the bottom (so it doesn't disappear right away)
    for (i = 0; i < scrollList.length; i++) {
        var scrollElement = scrollList[i]
        
//      scrollElement.e2_Top = clipHeight - scrollList[0].offsetHeight - scrollList[1].offsetHeight
        scrollElement.e2_Top = clipHeight
        scrollElement.style.top = scrollElement.e2_Top + "px"
    }

    timerID = setInterval("scrollUpOne()", 40)
    
    oParent.onmouseover = stopScroll
    oParent.onmouseout = startScroll    
}

function scrollUpOne() {
    for (i = 0; i < scrollList.length; i++) {
        var scrollElement = scrollList[i]
        
        scrollElement.e2_Top -= 1
        scrollElement.style.top = scrollElement.e2_Top + "px"

        // if the scroll item is completely off the top, push it to the bottom
        if (scrollElement.offsetTop + scrollElement.offsetHeight < 0)
            scrollElement.e2_Top += scrollHeight
    }    
}


