
/*
 * This scripts serves the MijnZorg website
 * Several functions are used to position elements or calculate layout measures.
 *
 * @author Bob Bremmer
 */


/* 
 * Detects the height of the users browserwindow
 */ 
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}


/*
 * Sets the height of the contentarea
 *
 * @param topHeight The (total)height of the elements, positioned on top of the contentarea
 * @param bottomHeight The (total)height of the elements, positioned below the contentarea
 */
function setContentHeight(topHeight, bottomHeight){
    var contentArea = document.getElementById('content_wrapper');
    var windowheight = getWindowHeight();
    var contentAreaHeight = windowheight - topHeight - bottomHeight;
    
    if(contentAreaHeight > contentArea.clientHeight){
        contentArea.style.height = contentAreaHeight + 'px';
    }
}

/*
 * Transforms list items into menu items 
 */
function setMenu() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById('nav');
		for (var i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == 'LI') {
				node.onmouseover = function() {
					this.className += ' over';
				}
				node.onmouseout = function() {
					this.className = this.className.replace(' over', '');
				}
			}
		}
	}
}

/*
 * Keeps sponsorsbanner always on sight
 */
function doSponsorScroll() {
    var sponsors = document.getElementById('scrolling_sponsors');
    
    
    if(sponsors){
        var dScrollClient = document.body.scrollHeight - document.body.clientHeight;
        if(dScrollClient > 45){
            sponsors.style.position = "absolute";
            if(document.body.scrollTop == 0){
                sponsors.style.top = '220px';
            } else {
                if(((document.body.scrollTop + 62) < dScrollClient)){
                    var newTop = document.body.scrollTop + 220;
                    sponsors.style.top = newTop + 'px';
                }
            }
        }
    }
}

/*
 * Loads all necessary stuff on window load
 */
window.onload = function () {
    setMenu();
    doSponsorScroll();
}

/*
 * Scroll sponsorsbanners in sight
 */
window.onscroll = function () {
    doSponsorScroll();
}



