// ************************************************************************************************
// *
// *  Name:               scroll_to_element.js
// *
// *  Created by:         Paul McKlveen
// *          on:         15-APR-2010
// *
// *  Updated by:         Paul McKlveen
// *          on:         15-APR-2010
// *
// *  Purpose:            This javascript contains the following functions: 
// *
// *                      initScrollToElement - is to be called during the window.onload event. 
// *                         The function invokes the scrollToElement function, passing a special
// *                         id value that designates the element that is to be displayed at the
// *                         top of the page.
// * 
// *                      performScroll - this function determines how much distance (in pixels) 
// *                         it will take to reposition the display to the passed element, and
// *                         then invokes the scrollTo method on the window to display the element
// *                         at the top of the page.  
// *
// *                      scrollToElement - this function takes the passed id of an element and 
// *                         attempts to find it.  If found, a call is made to the scrollToElement
// *                         function.  Also, the id is removed from the element.  
// *
// ************************************************************************************************

function scrollToElement(elementId)
{

    var topElement = document.getElementById(elementId);

    if (topElement) {
    	topElement.removeAttribute("id");
        performScroll(topElement);
    }

}

function performScroll(elementObj)
{

    var selectedPosX = 0;
    var selectedPosY = 0;

    while (elementObj != null) {
        selectedPosX += elementObj.offsetLeft;
        selectedPosY += elementObj.offsetTop;
        elementObj = elementObj.offsetParent;
    }
                                      
    window.scrollTo(selectedPosX, selectedPosY);

}

function initScrollToElement()
{
    scrollToElement('scrollToTop');
}