/**
 * onDOMLoad Javascript Function
 * Author: Ross Illingworth
 * URL: www.techmale.com
 * License: GPL.
 * This takes the work from Dean Edwards,Matthias Miller & John Resig, 
 * at http://dean.edwards.name/weblog/2006/06/again/#comment5338 and 
 * makes it into a useable function for all browsers.
 */
	
	// SafariTimer: holds the id of the timer for safari browser
	window.sFT = false;
	//DOMLoadFunctions: Array of functions to run when DOM is loaded
	window.onDLFs = [];
	// Function to call when onDOMload activates
	window.callDLFs = function(){
		// check if we have already been here.
		if (arguments.callee.done) {
			//alert("onDOMLoad Functions already run");
			return;
		}
		arguments.callee.done = true;
		// Stop safariTimer if Active
		if (sFT) {
			clearInterval(sFT);
		}
		//Now loop through functions and call them
		var func;
		for(i in  onDLFs){
			if(typeof (func = onDLFs[i]) == "function"){
				//alert(func +" = "+ typeof func);
				//alert(document.getElementById("fbContentsMenu"));
				func.apply(document);
			}
			
		}
	};
	
	// MAIN Function
	function onDOMLoad(func){
		// add your function to the function array
		onDLFs.push(func);
		// check if we have already done the setup
		if (arguments.callee.done) {
			//alert("Already setup doOnDOMLoaded");
			return;
		}
		arguments.callee.done = true;
		
		//this will work on Firefox or IE
		if (document.addEventListener){
			//FOR FIREFOX
			//alert("Using addEventListener");
			document.addEventListener("DOMContentLoaded",callDLFs, false);
		}else if (document.all && !window.opera){
			//FOR IE
			document.write('<script type="text/javascript" id="contentloadtag" defer src="javascript:void(0);"><\/script>');
			//alert('This is IE');
			var contentloadtag=document.getElementById("contentloadtag");
			contentloadtag.onreadystatechange=function(){
				if (this.readyState=="complete"){
					//alert("Using readystate");
					callDLFs.apply(document);
				}
			};
		}
		
		// THIS WORKS on SAFARI
		if(/Safari/i.test(navigator.userAgent)){
		  sFT = setInterval(function(){
		  	if(/loaded|complete/.test(document.readyState)){
		    	clearInterval(sFT);
				//alert("Using Safari");
		    	// call target function
				callDLFs.apply(document);
		  	}
		  }, 10);
		}
		
		//and finally if all else fails, use onload
		// first check if anything has been set up previously
		var old = (window.onload) ? window.onload : function () {};
		window.onload = function(e) {
			//alert("Now calling onLoad"); 
			old(e); 
			callDLFs();
		};
	}







if( document.documentElement )
	bodyStyle = document.documentElement.style;
else if( document.body )
	bodyStyle = document.body.style;

bodyStyle.visibility = "hidden";

function sizeContent(){
	var windowHeight = getWindowHeight();
	var footerHeight = document.getElementById("fbFooter").offsetHeight;

	var contentHeight = windowHeight - footerHeight;
	document.getElementById("fbContainer").style.height = contentHeight + "px";
	
	var altDiv = document.getElementById("altmsg");
	
	if( altDiv ){		
		var altH = altDiv.offsetHeight;
		var altW = altDiv.offsetWidth;
		altDiv.style.top = (contentHeight / 2 - altH /2)+ "px";
		altDiv.style.left = (getWindowWidth() / 2 - altW /2)+ "px";
	}
	
	if( bodyStyle )
		bodyStyle.visibility = "visible";
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj.attachEvent( "on"+type, function() { obj["e"+type+fn](); } );
	}
}

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 getWindowWidth() {
	var ww = 0;
	if (self.innerWidth)
		ww = self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		ww = document.documentElement.clientWidth;
	else if (document.body)
		ww = document.body.clientWidth;
	return ww;
}

addEvent( window, "load", sizeContent );
addEvent( window, "resize", sizeContent );