var SAFARI_STYLESHEET_REFERENCE = "/_resources/css/styles_safari.css";
var FIREFOX_STYLESHEET_REFERENCE = "/_resources/css/import/styles_firefox_mac.css";
/********************************************************************/
/*START: Fix IE 6 Text Selection Bug & Flickering Background Images */
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat" && !window.XMLHttpRequest) {
	document.onreadystatechange = function fixIE6AbsPos()
	{
		if( !document.body ) {
			return;
		}
		if( document.readyState == "complete" ) {
			document.body.style.height = document.documentElement.scrollHeight + 'px';
		}
	}

	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}
/*END: Fix IE 6 Text Selection Bug & Flickering Background Images   */
/********************************************************************/
/********************************************************************/
/*START: browser detection*/
function BrowserDetection()
{
	var sUserAgent = navigator.userAgent.toLowerCase();
	var sUserPalttform = navigator.platform.toLowerCase();

	// browser name
	this.isIE = (sUserAgent.indexOf('msie') != -1);
	this.isIE7 = (this.isIE && typeof window.XMLHttpRequest != "undefined");
	this.isSafari = (sUserAgent.indexOf('safari') != - 1);
	this.isMozilla = (sUserAgent.indexOf('gecko') != -1 && this.isSafari == false);
	this.isFirefox = (this.isMozilla == true && sUserAgent.indexOf('firefox') != -1);
	this.isFirefoxMac = (this.isMozilla == true && sUserAgent.indexOf('mac') != -1);
	this.isOpera = (sUserAgent.indexOf('opera') != -1 || typeof window.opera != "undefined");
}

var oBrowser = new BrowserDetection();
/*END: browser detection*/
/********************************************************************/
/********************************************************************/
/*START: Safari Browser Detection and Serve Styles */
if (oBrowser.isSafari)
{
	document.write ("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + SAFARI_STYLESHEET_REFERENCE + "\" />");
}
/*END: Safari Browser Detection and Serve Styles */
/********************************************************************/
/********************************************************************/
/*START: Firefox MAC Browser Detection and Serve Styles */
if (oBrowser.isFirefoxMac) 
{
    document.write ("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + FIREFOX_STYLESHEET_REFERENCE + "\" />");
}
/*END: Firefox MAC Browser Detection and Serve Styles */
/********************************************************************/

/********************************************************************/
/*START: Functions to position footer */

function getWindowInnerSize() 
{ 
	
	var objWin = new Object();
	if (self.innerHeight) { 
	// all except Internet Explorer 
		objWin.width = self.innerWidth; 
		objWin.height = self.innerHeight; 
	} else if (document.documentElement && document.documentElement.clientHeight) { 
	// Explorer 6 Strict Mode 
		objWin.width = document.documentElement.clientWidth; 
		objWin.height = document.documentElement.clientHeight; 
	} else if (document.body) { 
	// other Explorers 
		objWin.width = document.body.clientWidth; 
		objWin.height = document.body.clientHeight; 
	} 
	return objWin; 
}

function getPos(id) 
{ 
	var obj = document.getElementById(id); 
	var pos = {left:0, top:0}; 
	if(typeof obj.offsetLeft != 'undefined') { 
		while (obj) { 
			pos.left += obj.offsetLeft; 
			pos.top += obj.offsetTop; 
			obj = obj.offsetParent; 
		} 
	} else { 
		pos.left = obj.left; 
		pos.top = obj.top; 
	} 
	return pos; 
}
function getHeight(element) 
{ 
	element = document.getElementById(element); 
	return element.offsetHeight; 
}
function setHeight(id, height) 
{ 
	var obj = document.getElementById(id); 
	obj.style.height = height + "px"; 
} 

function initLayout() 
{ 
	var iWindowHeight = getWindowInnerSize().height; 
	var iFooterHeight = (document.getElementById("footer")) ? getHeight("footer") : 0; 
	var iFooterTopPosition = (document.getElementById("footer")) ? getPos("footer").top : 0; 
	if (document.getElementById("footer-position-placeholder")) { 
		var iFooterPlaceholderHeight = getHeight("footer-position-placeholder"); 
		if (((iFooterTopPosition - iFooterPlaceholderHeight) + iFooterHeight) < iWindowHeight) { 
			var height = iFooterPlaceholderHeight + (iWindowHeight-(iFooterTopPosition+ iFooterHeight)); 
			setHeight("footer-position-placeholder", height) 
		} else { 
			setHeight("footer-position-placeholder", 0) 
		} 
	} 
} 

window.onload = function () {
	initLayout();
}

window.onresize = function () {
	initLayout();
}

/*END: Functions to position footer */
/********************************************************************/

