 /* Begin global variables for pages */
var page_label = "None";
var inFrame = (typeof parent.navigation != "undefined" || typeof top.navigation != "undefined");
/* End global variables for pages */

/*** Start of Code to run at startup ***/
show_hide_topMenu();
setPageLabel();

/* Using conditional comments instead
if (browser.isMSIE){
	loadIEStyles();
} */
if (browser.isKHTML) {
	loadKHTMLStyles();
}
if (browser.isOpera) {
	loadOperaStyles();
}
//window.onload = atLoad;
addEvent(window, "load", atLoad);

function atLoad () {
	if (inFrame) {
		tellpage();
	}
}//eof atLoad
addEvent(window, "load", checkVertical);
/*** End of startup code ***/

/*** Start of Load Browser specific styles ***/
function loadIEStyles(){
	var cssPath = rootPath('inet') + "css/";
	document.write('<link rel="stylesheet" type="text/css" href="'+ cssPath + 'ie-fixes.css">');

	if (!inFrame) {
		if (browser.version >= 6) {
			document.write('<link rel="stylesheet" type="text/css" href="'+ cssPath + 'ie6-fixes.css">');
		}
		else {
			document.write('<link rel="stylesheet" type="text/css" href="'+ cssPath + 'ie5-fixes.css">');
		}
	}
}//eof loadIEStyles

function loadKHTMLStyles() {
	var cssFile = rootPath('inet') + "css/khtml-fixes.css";
	document.write('<link rel="stylesheet" type="text/css" href="' + cssFile + '">');
}//eof loadKHTMLStyles

function loadOperaStyles() {
	var loc = window.location.pathname;
	var css = "css/opera-fixes.css";
	var cssFile = rootPath('inet') + css;
	if (browser.version < 7) {
		document.write('<link rel="stylesheet" type="text/css" href="' + cssFile + '">');
	}
	if (/home\/index/.test(loc)) {
		cssFile = rootPath('home') + css;
		document.write('<link rel="stylesheet" type="text/css" href="' + cssFile + '">');
	} else if (/hobbies/.test(loc)) {
		cssFile = rootPath('hobbies') + css;
		document.write('<link rel="stylesheet" type="text/css" href="' + cssFile + '">');
	} else if (/recreation\/index/.test(loc)) {
		cssFile = rootPath('recreation') + css;
		document.write('<link rel="stylesheet" type="text/css" href="' + cssFile + '">');
	}

}//eof loadOperaStyles
/*** End of Load Browser specific styles ***/

/*** Start Utility functions ***/
function rootPath(folder) {
	/* Returns the left part of path from
	 * and including the specified directory.
	 * To adjust to different directory structures.
	 * e.g. run as file or server.
	 */
	var end = window.location.href.indexOf(folder) + folder.length + 1;
	return  window.location.href.slice(0, end);
}//eof rootPath

function fileName(url){
	/* Return file name no extention */
	var m = url.match(/(.*)\/([^\/\\]+)\.\w+$/);
	return m[2]
}

function isDefined(property) {
	/* Return if a feature is defined */
	return (typeof property != 'undefined');
}

function linkSaveInst() {
	/* Browser specific download instructions */
	var text = "Right click link and select Save target as...";
	if(os.isMac) {
		text = 'Option+Click the link.';
	}
	else if (browser.isFirefox) {
		text = "Right click link and select Save Link As...";
   }

   return text;
} //eof linkSaveInst

function setPageLabel() {
	/* Set page label for side menu effects
	   based on directory name
	*/
	var dir = window.location.pathname.match(/inet[\/\\]([^\/\\]+)[\/\\]/);

	if (dir) {
		if (dir[1] !=  ".cgi-bin") 
			page_label = dir[1];
		else
			page_label = "gb";
	}
}//eof setPageLabel

/*** Start fx to Adjust position due to menu ***/
function checkVertical() {
	if (location.hash != "") {
		fixScroll(location.href);
	}
}
function fixScroll(url) {
	var re = null;

	/* Make separate url path & file from  hash */
	var p = (/([^\/]+)#(.+)/).exec(url);

	/* Make RegExp of url without hash */
	if (p) re = new RegExp(p[1], 'i');

	/* If is current page scroll or let new page load */
	if (re && re.test(location.pathname)) {
		return showElement(p[2]);
	}
	else {
		return true;
	}
}//eof fixScroll

function showElement(elem) {
	/* Adjust position scrolled when href="#id"
	 * to account for fixed menu.
	 *
	 * elem is id
	 */
	if (elem == "top") {
		window.scrollTo(0,0);
	}
	else {
		if (inFrame || browser.isMSIE && browser.version < 7) {
			/* No position fix is needed */
			location.replace("#" + elem);
		}
		else {
			try {
				var e = document.getElementById(elem);
				var x = document.getElementById("main-menu-div").offsetHeight;
				e.scrollIntoView(true); //bring to top
				scrollBy(0, -x); //backup below menu
			}
			catch (e) {
				//Just use default position
				return true;
			}
		}
	}
	return false; //Stop link default action
}//eof showElement

function getWindowWidthHeight(){
	var nWidth = 0;
	var nHeight = 0;

	if (window.innerWidth ) {
		nWidth = window.innerWidth;
		nHeight = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth){
		nWidth = document.documentElement.clientWidth;
		nHeight = document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientWidth) {
		nWidth = document.body.clientWidth;
		nHeight = document.body.clientHeight;
	}
	else if (typeof window.pageXOffset != "undefined") {
		nWidth = window.pageXOffset;
		nHeight = window.pageYOffset;
	}
	return {width: nWidth, height: nHeight};
}//eof getWindowWidthHeight

function cstmGetElementsByClassName(class_name) {
	/* returns array of elements with class_name */
	var docList = this.getElementsByTagName('*');
	var elementList = new Array();
	var re1 = new RegExp("\\b"+class_name+"\\b");
	var re2 = new RegExp("[^\s]" + class_name + "|" + class_name + "[^\s]");

	for (var i = 0; i < docList.length; i++){
		if (re1.test(docList[i].className) && !re2.test(docList[i].className) ) {
			elementList.push(docList[i]);
		}
	}
	return elementList;
}//eof
document.getElementsByClassName = cstmGetElementsByClassName;
/*** End Utility functions ***/

/*** Start menu functions ***/
function setMainMenu() {
	/*Alternate attempt to fix menu before displayed */
	if (inFrame) {
		if (typeof document.styleSheets == "undefined") {
			/* otherwise adjusted in show_hide_topMenu */
			document.getElementById("main-menu-div").style.display =  "none";
		}
		if (document.getElementById("maintenance"))
			document.getElementById("maintenance").style.display = "none";
	}
	else if (top.name == "chromefree") {
		setUpFoldingMenu();
	}
	else  {
		if (typeof document.styleSheets == "undefined" && !scrn.isLowRes) {
			/* otherwise adjusted in show_hide_topMenu */
			document.getElementById("side-menu").style.display = "none"; // "inline";
		}

		if (top != self) setMenuTargets();

		addEvent(window, "load", setPadding4Menu);
	}
} //eof setMainMenu

function show_hide_topMenu() {
	/* Adjust Main Menu CSS by editing the stylesheets
	 * before body HTML elements are created.
	 * This stops the appearance and then removal of menu.
	 */
	if (typeof document.styleSheets != "undefined") {
		var i, j, k, rList

		if (inFrame) {
			/* Hide menu by changing style sheet */
			outerloop:
			for (i = 0; i < document.styleSheets.length; i++) {
				rList = document.styleSheets[i].cssRules || document.styleSheets[i].rules;
				for (j = 0; j < rList.length; j++) {
					/*konqueror selectorText *[id"main-menu-div"] others #main-menu-div */
					if (rList[j].selectorText.match(/#main-menu-div|\*\[id"main-menu-div"\]/)) {
						rList[j].style.display = "none";
						break outerloop;
					}
				}//innerloop
			}//outerloop
		} else {
			/* Show link to side menu by changing styleSheet.
			 * The Side menu option is not shown when noscript
			 * so it has to be made visible if script is enabled
			 */
			var oBody_adjusted = false;
			var sideMenu_adjusted = false;
			outerloop:
			for (i = 0; i < document.styleSheets.length; i++) {

				rList = document.styleSheets[i].cssRules || document.styleSheets[i].rules;

				for (j = 0, k = 0; j < rList.length; j++) {
					/*konqueror selectorText *[id"side-menu"] others #side-menu */

					if (!sideMenu_adjusted && rList[j].selectorText.match(/#side-menu|\*\[id"side-menu"\]/)) {
						if (!scrn.isLowRes) rList[j].style.display = "inline";
						sideMenu_adjusted = true;
					}

					if (!oBody_adjusted && rList[j].selectorText.match(/oBody|\*\[oBody\]/)) {
						rList[j].style.paddingTop = "1.9em";
						oBody_adjusted = true;
					}

					if (oBody_adjusted && sideMenu_adjusted) break outerloop;
				} //innerloop
			} //outerloop
		} //endif inFrame
	} //endif document.styleSheets
} //eof show_hide_topMenu

function setPadding4Menu() {
	/* Set padding to make space for top menu */
	var menuHeight = document.getElementById("main-menu-div").offsetHeight;

	if (typeof menuHeight != "undefined") {
		/* In some browers (e.g. IE5) marginTop colapses so paddingTop is used */
		document.getElementById("oBody").style.paddingTop = menuHeight + "px";
	}
}//eof setPadding4Menu

function setMenuTargets(sTarg) {
	/* Assign menu target properties to "_top" when not in frame */
	var linkList = document.getElementById("main-menu-div").getElementsByTagName("a");
	for (var i = 0; i < linkList.length; i++) {
		linkList[i].target = "_top";
	}
}//eof setMenuTargets
/*** End of Menu Functions ***/

/*** Communicate page name between frames.***/
function say_page(){
	/* is called by navlib.js getpage()
	 * to let navigation frame know current
	 * page
	 */
	return page_label;
}//eof saypage

function tellpage(){
	/* Passes page label to Nav frame */
	if (typeof parent.navigation != "undefined" &&
		typeof parent.navigation.my_page == "function" ) {
		parent.navigation.my_page(page_label);
	}
} //eof tellpage
/** End of page label functions **/

/*** Begin Modified Date Functions not used anymore ***/
function formatSysDate(sDate) {
	/* MS returns mm/dd/yyyy (12/27/2003) all others
	 * return DDD, dd MMM yyyy (Fri, 27 Dec 2003).
	 * The time follows the date.
	 */
	if (browser.isMSIE && sDate.substr(3,1) != ","){
		// Just drop off time from date string if really IE
		sDate = sDate.substring(0, sDate.indexOf(" ", 1));
	}
	else {
		// Combine elements we want 2,3,4 skip 0
		var aDates = sDate.split(" ", 4);
		sDate = aDates[1] + " " + aDates[2] + " " + aDates[3];
	}
	return sDate;
} //eof -- lastModifiedDate

function modified_date(){
	/* write page modified date into HTML */
	var sDate = document.lastModified;
	//sDate = formatSysDate(sDate);
	//document.write("<span class='modified-date'>Updated: " + sDate + "</span>");
} //eof -- modified_date
/*** End Modified Date Functions ***/

/*** Start IE fixes not used anymore ***/
function moveIt(tag, classFilter){
	/* Fx to move "to Top" links to the right edge
	   Replaced by CSS methods
	*/
	tag = tag.toUpperCase();
	var tagList = document.getElementsByTagName(tag);
	for (var i = 0; i < tagList.length; i++){
		if (tagList[i].className == classFilter) {
			var x = tagList[i].parentNode.offsetWidth  - tagList[i].offsetLeft - tagList[i].offsetWidth;
			tagList[i].style.left = x + "px";
		}
	}
}//eof moveIt
/*** End IE fixes ***/
/* End of Library */
