/**
 * General JS needed for all pages of FotoFactory
 * By Bramus! - bramus.vandamme@kahosl.be - http://www.ikdoeict.be/
 * ------------------------------------------------
 */


/**
 * addLoadEvent function which allows us to hook multiple functions to window.onload
 * @author Simon Willison
 * @see http://simonwillison.net/2004/May/26/addLoadEvent/
 * ------------------------------------------------
 */

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}


/**
 * function which calculates the window height
 * ------------------------------------------------
 */

	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;
	}


/**
 * Function which sets the height of #content
 * ------------------------------------------------
 */

	function setContentHeight(offset) {
		
		var windowHeight = getWindowHeight();
		
		if (windowHeight > 0) {
			
			// calc the new height of the element: height of the window - height of the other elements
			var newHeight = (windowHeight - offset);
						
			if (newHeight > 100)
				document.getElementById('content').style.height = newHeight + 'px';
			else
				document.getElementById('content').style.height = '100px';
		
		} else {
			
			document.getElementById('content').style.height = '100px';
			
		}
		
	}


/**
 * Function to be hooked onload and onresize (calcs some stuff and then calls the actual setContentHeight)
 * ------------------------------------------------
 */

	function initContentHeight(){
			
		// get the height of some elements
		var headerHeight = document.getElementById('header').offsetHeight;
		var menubarHeight = document.getElementById('menubar').offsetHeight;
		var footerHeight  = document.getElementById('footer').offsetHeight;
		
		// add 'm along with the paddingTop and paddingBottom of #content
		var offset = headerHeight + menubarHeight + footerHeight + 50;
	
		// hook setContentHeight to the resize event with the offset param
		window.onresize = function() {
			setContentHeight(offset);
		}
		
		// call setContentHeight right now
		setContentHeight(offset);
		
	}


/**
 * Hook setContentHeight to the onload event of the window
 * ------------------------------------------------
 */

	addLoadEvent(initContentHeight);
	

// EOF
