
// Check Browser CSS Compatibility
	
// alert(document.compatMode);
	
// Supress BOM Script Errors	
	
function errorsuppressor(){
return true;
}

if(location.href.indexOf("localhost") == -1){
	
	window.onerror = errorsuppressor;

}

// Multiple Onload Utility

function addLoadEvent(func) {

	var oldonload = window.onload;

	if (typeof window.onload != 'function') {

		window.onload = func;

	} else {

		window.onload = function() {
		oldonload();
		func();

		}

	}

}

// Insert-after Function

function insertAfter(newElement, targetElement) {

var parent = targetElement.parentNode;

if (parent.lastChild == targetElement) {

	parent.appendChild(newElement);

} else {

	parent.insertBefore(newElement, targetElement.nextSibling);

	}

}

// Global Pop-up (parse through DOM, if particular class exists, append event)

function newWinLinks() {

	for (var i=0; i < document.links.length; i++) {

		if (document.links[i].className == "newwindow") {
		
			document.links[i].setAttribute("target", "_blank");
			
			
			}
		
		if (document.links[i].className == "viewvideo") {
		
			document.links[i].setAttribute("target", "_blank");
		
		}		
								
	}
	
}

addLoadEvent(newWinLinks);

// Primary Nav (IE 6 only)

primarynavhover = function() {

	if (!document.getElementById) return false;
	if (!document.getElementById("primarynav")) return false;

	var listElements = document.getElementById("primarynav").getElementsByTagName("li");

	for (var i=0; i < listElements.length; i++) {

		listElements[i].onmouseover = function() {
				
			this.className+=" iehover";
			
		}

		listElements[i].onmouseout = function() {
				
			this.className-= this.className.replace(new RegExp(" iehover\\b"));
			
		}

	}

}

if (window.attachEvent) window.attachEvent("onload", primarynavhover);
	
function setlastnode() {

// Set Last node - This is only a quick hack and will need to 
// be re-written to apply to every last node of parent node...maybe. Just an FYI. - Spell
			
	var the_node = document.getElementById("pn-about").getElementsByTagName("li")[1];
	
	the_node.setAttribute("id", "sustainability");
	
}

// Not necessary on this site (yet)	
// addLoadEvent(setlastnode);

function addOptionTitle() { 

// Add title attribute to all select boxes for usability
	
if (!document.getElementsByTagName("select")) return false;

var list = document.getElementsByTagName("select");
	
for(var i = 0; i < list.length; i++) {
	
	var option = list[i].getElementsByTagName("option")

		for(var j = 0; j < option.length; j++) {
			option[j].setAttribute("title", option[j].text);

		}

	}

}
	
addLoadEvent(addOptionTitle);

function randomBackground() {

	if (!document.getElementById) return false;

	var container = document.getElementById("aboutbg"); // This should be the id of the div that needs the bg image

	var bgsArray = ["tile-a", "tile-b", "tile-c", "tile-d", "tile-e", "tile-f"]; // Add your CSS classes here for each different image

	container.className = bgsArray[Math.floor(Math.random()*bgsArray.length)]; // This will randomly insert class name
}

// No longer being used 
// addLoadEvent(randomBackground);






