var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]
};
BrowserDetect.init();

var myBVersion = BrowserDetect.version;
var myB = BrowserDetect.browser;
var myBOS = BrowserDetect.OS;
var myBVersion = parseInt(myBVersion);
var wnOpenTop = 158;
var wnOpenBottom = 425;


function detectBrowser() {
	if(myB == 'Explorer') {
		switch(myBVersion) {
			case 6:
				wnOpenTop = 148;
				wnOpenBottom = 415;
				break;
				
			case 7:
				wnOpenTop = 148;
				wnOpenBottom = 415;
				break;
			default:
				wnOpenTop = 158;
				wnOpenBottom = 425;
			break;
		}
	}
}


function getTableHeight() {
	alert(document.getElementById('center_content').offsetHeight);
}



function setPageSize() {
	 var browserHeight;
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerHeight != 'undefined') {
		  browserHeight = window.innerHeight
 	 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0) {
		   browserHeight = document.documentElement.clientHeight
	 // older versions of IE
	 } else {
		   browserHeight = document.getElementsByTagName('body')[0].clientHeight
	 }
	browserHeight = browserHeight + 8;
	//alert(browserHeight);
	
	if(document.getElementById('l2_content_block')) {
		contentHeight = document.getElementById('l2_content_block').offsetHeight;
		//alert(contentHeight);
		if(contentHeight < 570) {
			contentHeight = 570;
		}
		contentHeight = contentHeight + 376;
		if(contentHeight < browserHeight) {
			contentHeight = browserHeight;	
		}
		//alert(contentHeight);
		document.getElementById('center_content').style.height = contentHeight + 'px';
	}
	//var setFooterTop = (document.getElementById('center_content').offsetHeight - 93) + 'px';
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if(sPage == 'what_we_do.php') {
		//alert(browserHeight);
	}

/*	if(sPage == 'index.php' || sPage == '') {
		if(browserHeight > 1088) {
			document.getElementById('center_content').style.height = browserHeight + 'px';
		}
	}
*/

	if(sPage == 'index.php' || sPage == '') {
		bottom_stroke_height = browserHeight - 1086;
		if(browserHeight > 1088) {
			document.getElementById('bottom_stroke').style.height = bottom_stroke_height + 'px';
			document.getElementById('center_content').style.height = browserHeight + 'px';
		} else {
			document.getElementById('bottom_stroke').style.height = '114px';
		}
	}


	if(sPage == 'legacy_house_application.php') {
		if(myB == 'Firefox') {
			if(myBOS == 'Mac') {
				document.getElementById('la_top_pager').style.paddingTop = '6px';
				document.getElementById('la_top_pager').style.paddingBottom = '4px';
			}
		}
		if(myB == 'Safari') {
			if(myBOS == 'Mac') {
				document.getElementById('la_top_pager').style.paddingTop = '4px';
				document.getElementById('la_top_pager').style.paddingBottom = '6px';
			}
		}
	}
}

var timeOutId;
var currentMenu = "";
var ome = false;

function navButton(theBtn, theEvt) {
	if (currentMenu != theBtn) {
		clearTimeout(timeOutId);
		if(currentMenu != '') {
			document.getElementById(currentMenu).style.display = 'none';
//			theArrow = currentMenu + '_arrow';
//			if(document.images[theArrow]) {
//				document.images[theArrow].src = 'images/clear.gif';
//			}
		}
		currentMenu = theBtn;
	} else {
		clearTimeout(timeOutId);
	}
	
	if(theEvt =='mouseover') {
		document.getElementById(theBtn).style.display = 'block';
//		theArrow = theBtn + '_arrow';
//		if(document.images[theArrow]) {
//			document.images[theArrow].src = 'images/top_nav_arrow.gif';
//		}
	}
	if(theEvt =='mouseout') {
		timeOutId = setTimeout("hideMenu('" + theBtn + "')", 500);
	}
}

function hideMenu(theMenu) {
	document.getElementById(theMenu).style.display = 'none';
//	theArrow = theMenu + '_arrow';
//	if(document.images[theArrow]) {
//		document.images[theArrow].src = 'images/clear.gif';
//	}
}

function checkTimeOut(theDiv) {
	if(theDiv==currentMenu) {
		clearTimeout(timeOutId);
		timeOutId = '';
	}
}

function hideNavDiv(theDiv) {
	timeOutId = setTimeout("hideMenu('" + theDiv + "')", 200);
}

function show_whats_new() {
	detectBrowser();
	document.getElementById('whats_new').style.height = '297px';
	document.getElementById('whats_new').style.top = wnOpenTop + 'px';
}

function hide_whats_new() {
	document.getElementById('whats_new').style.height = '30px';
	document.getElementById('whats_new').style.top = wnOpenBottom + 'px';
}


function btn_swap(theBtn, theAction) {
	theExt = document.images[theBtn].src;
	theExt = theExt.substring(theExt.lastIndexOf("."), theExt.length);
	if(theAction == "over") {
		 document.images[theBtn].src = "images/" + theBtn + "_on" + theExt;	
	}
	if(theAction == "out") {
		 document.images[theBtn].src = "images/" + theBtn + "_off" + theExt;	
	}
}

window.onresize = setPageSize;


