function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function getBodyDims() {
	var pageWidth, pageHeight;

	if(window.innerHeight && window.scrollMaxY) {
		pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY;
	} else if(document.body.scrollHeight > document.body.offsetHeight) {
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	} else {
		pageWidth = document.body.offsetWidth + document.body.offsetLeft;
		pageHeight = document.body.offsetHeight + document.body.offsetTop;
	}

	return [pageWidth, pageHeight];
}

function setHighlights(thisId) {
	if(document.getElementById(thisId)) {
		document.getElementById(thisId).onmouseover = function() {
			this.style.color="#000000";
			colorFade(thisId,'text','000000','FFC600',20,20);
		}

		if ((thisId == 'nl') || (thisId == 'h2_his') || (thisId == 'h2_mis') || (thisId == 'h2_srv')) {
			document.getElementById(thisId).onmouseout = function() {
				colorFade(thisId,'text','FFC600','B2B2B2',20,40);
			}
		} else if ((thisId == 'h2_cat1') || (thisId == 'h2_cat2') || (thisId == 'h2_cat3') || (thisId == 'reset') || (thisId == 'submit') || (thisId == 'blog_h2') || (thisId == 'nav') || (thisId == 'searchsubmit')) {
			document.getElementById(thisId).onmouseout = function() {
				colorFade(thisId,'text','FFC600','5B5B5B',20,40);
			}
		} else {
			document.getElementById(thisId).onmouseout = function() {
				colorFade(thisId,'text','FFC600','FFFFFF',20,40);
			}
		}
	}
}

var pageDims = [];

function launchFunc() {
	pageDims = getBodyDims();

	if(document.getElementById('h2_wel')) {		// If welcome page, fade intro text
		document.getElementById('h2_wel').style.visibility = "hidden";
		document.getElementById('p_wel').style.visibility = "hidden";
		document.getElementById('h2_how').style.visibility = "hidden";

		window.setTimeout(function() {
			document.getElementById('h2_wel').style.visibility = "visible";
			document.getElementById('h2_wel').style.color = "#5B5B5B";
			colorFade('h2_wel','text','000000','FFC600',20,50);
		},500);

		window.setTimeout(function() {
			document.getElementById('p_wel').style.visibility = "visible";
			document.getElementById('p_wel').style.color = "#5B5B5B";
			colorFade('p_wel','text','000000','FFFFFF',20,50);
		},2500);

		window.setTimeout(function() {
			document.getElementById('h2_how').style.visibility = "visible";
			document.getElementById('h2_how').style.color = "#5B5B5B";
			colorFade('h2_how','text','000000','FFC600',20,50);
		},4500);
	}

	if(document.getElementById('menubar')) {		// If page has menu (full content page),
		var idList= ['bg', 'pr', 'cl', 'ls', 'ab', 'ct', 'nl', 'ft'];		// List of IDs to apply JS text color fade

		for (var i = 0; i < idList.length; i++) {
			setHighlights(idList[i]);
		}
	} else {		// Else, it's the home page- so set enter & footer link highlights
		setHighlights('enter');
		setHighlights('ft');
	}

	if(document.getElementById('submit')) {		// If submit button exists then highlight form
		setHighlights('reset');
		setHighlights('submit');
	}

	if(document.getElementById('blog_h2')) {		// If submit button exists then highlight form
		setHighlights('blog_h2');
		setHighlights('nav');
		setHighlights('searchsubmit');

	}

	if(document.getElementById('h2_his')) { setHighlights('h2_his'); }
	if(document.getElementById('h2_mis')) { setHighlights('h2_mis'); }
	if(document.getElementById('h2_srv')) { setHighlights('h2_srv'); }

	if(document.getElementById('h2_cat1')) { setHighlights('h2_cat1'); }
	if(document.getElementById('h2_cat2')) { setHighlights('h2_cat2'); }
	if(document.getElementById('h2_cat3')) { setHighlights('h2_cat3'); }

	//alert(f_clientWidth()+' '+f_clientHeight()+' vs '+pageDims[0]+' '+pageDims[1]);
}

window.onload = launchFunc;
