/*** Workaround to set target="_blank" - inspired by Alan Kelsey's JS - http://javascripttutorialonline.info/ ***/
function adjustATags() {
	var aTags = document.getElementsByTagName("a"); // Gets all of the a tag elements on page
	for (var i = 0; i < aTags.length; i++) {
		if (aTags[i].getAttribute("href") && aTags[i].getAttribute("rel") == "external") { // If rel is set to external and tag has href attribute
			aTags[i].setAttribute("target", "_blank"); // Set target to _blank
		}
	}
}

/****************************************************************************************************************/

/************** Workaround to set table alignment to center if using IE6 - margin: auto doesn't work ************/
function adjustTableTags() {
	if (document.all) { // Applies to IE
		if (navigator.appVersion.indexOf("MSIE 7") == -1) { // If it's not IE7
			var tableTags = document.getElementsByTagName("table"); // Get all table elements on page
			for (var i = 0; i < tableTags.length; i++) {
				tableTags[i].setAttribute("align", "center"); // Set align to center
			}
		}
	}
}
/****************************************************************************************************************/

/******************************** Function to adjust the navigation layer height ********************************/
function adjustNavHgt() {
	var nav = document.getElementById('nav');
	var ftrHgt = document.getElementById('footer').offsetHeight;
	var hdrHgt = document.getElementById('header').offsetHeight;
	var contHgt = document.getElementById('content').offsetHeight;
	var navHgt;

	if (document.all) {
		var navVersion = navigator.appVersion;
		if (navVersion.charAt(navVersion.indexOf("MSIE") + 5) >= 7) { // If IE7 or later, do the following
			navHgt = Math.max(document.documentElement.clientHeight - ftrHgt - hdrHgt, contHgt); // Sets height to larger of: body - footer - header or content
		} else {
			navHgt = Math.max(document.body.clientHeight - ftrHgt - hdrHgt, contHgt);
		}
		if (document.getElementById('sidebar')) {
			navHgt = Math.max(document.getElementById('sidebar').offsetHeight, navHgt); // If there's a sidebar, store the taller of that or the nav as nav height
			document.styleSheets[0].addRule("#sidebar", "height:" + navHgt + "px;"); // Set sidebar height to nav height
		}
		document.styleSheets[0].addRule("#nav", "height:" + navHgt + "px;"); // Sets new nav height for IE
	} else {
		navHgt = Math.max(document.documentElement.offsetHeight - hdrHgt - ftrHgt, document.documentElement.clientHeight - hdrHgt - ftrHgt); // Sets based on which is greatest - content layer height, body height, or window height
		if (document.getElementById('sidebar')) {
			navHgt = Math.max(document.getElementById('sidebar').offsetHeight, navHgt); // Nav height is greater of nav, sidebar height
			document.getElementById('sidebar').style.height = navHgt + "px"; // Sets sidebar height
		}
		nav.style.height = navHgt + "px";
	}
}
/****************************************************************************************************************/

/************************** Function to rotate images for slideshow pix *****************************************/
function displayImage() {
	if (document.getElementById('slideshow')) { // If there is an element with an id of slideshow on the page
		var ss = document.getElementById('slideshow');
		if (image > slideArray.length - 1) {
			image = 0;
		}
			ss.src = slideArray[image].src;

			image++;
			setTimeout("displayImage()", 5000);
	}
}
/****************************************************************************************************************/

/************************************* Function to add images to the ssArray ************************************/
function addImage(src, alt) {
	ssArray[totImg] = new Image(); // Set the element to an Image object
	ssArray[totImg].src = src; // Location of the image
	ssArray[totImg].alt = alt; // Alt text for the image

	totImg++; // Increment totImg
}
/****************************************************************************************************************/

/********************************* Function to call other functions on page load ********************************/
function init() {
	adjustNavHgt(); // Calls adjustNavHgt function
	adjustTableTags(); // Calls adjustTableTags function
	adjustATags(); // Calls adjustATags function
}
/****************************************************************************************************************/

/*************************************** Function to hide email addresses ***************************************/
function emailByJS(d, u) { // d = domain; u = username
	var email = "<a href=\"mailto:" + u + "@" + d + "\">" + u + "@" + d + "</a>";
	document.write(email);
}
/****************************************************************************************************************/

window.onload = init;