// TRIGGER EVENTS ON-LOAD
// addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
// removeEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
function removeEvent( obj, type, fn ) {
	if (obj.removeEventListener) {
		obj.removeEventListener( type, fn, false );
	} else if (obj.detachEvent) {
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

// OPEN A PAGE IN A NEW WINDOW
// Create the new window
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {		
		var newWindow = window.open(this.getAttribute('href'), 'popup');
		if (newWindow) {
			if (newWindow.focus) {
			newWindow.focus();
			}
		return false;
		}
	return true;
	}
}

// CALL THIS FUNCTION TO SCAN LINKS AND LOOK FOR SPECIAL SITUATIONS
function getSpecialLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById) {
		// Find all links
		var link;		
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			link = links[i];			
			// NON-HTML LINKS
			// Find all links with a class name of "non-html" - Use for PDF documents and the like
			if (/\bnon\-html\b/.test(link.className)) {				
				link.onclick = openInNewWindow;				
			}
			// OFF-SITE LINKS
			// Find all links with a class name of "off-site" (Added by GML)
			else if (/\boff\-site\b/.test(link.className)) {				
				link.onclick = openInNewWindow;
			}
			// SITE NAVIGATION
			// Find all links with a class name of "nav-primary" (Added by GML)
			else if (/\bnav\-primary\b/.test(link.className)) {				
				link.onmouseover = showNav;
				// link.onmouseout = hideNav;
			}
			// FOOTER LINKS
			else if (link.parentNode.id == 'footer') {
				link.onclick = openInNewWindow;
			}
		}
	objWarningText = null;	
	}
}

// WRITE E-MAIL ADDRESS TO HIDE IT FROM SPAM SPIDERS
function writeAddress(name,url) {
	document.write('<a href="mailto:' + name + '@' + url + '">' + name + '@' + url + '</a>');
}

// NAVIGATION - CONTROL DROP-DOWN MENUS
// Show menu
function showNav() {
	var subNav = this.getAttribute('id') + 2;	
	if (document.getElementById(subNav)) {
		hideNav();		
		document.getElementById(subNav).style.display = 'block';
		return false;
	}
	else {
		return true;
	}
}
// Hide all menus
function hideNav() {
	subNavItem = new Array(3);
	subNavItem[0] = 'nav-about2';
	subNavItem[1] = 'nav-resourcecenter2';
	subNavItem[2] = 'nav-news2';
//	for (var i = 0; i < subNavItem.length ; i++) {		
//		document.getElementById(subNavItem[i]).style.display = 'none';
//	}
}
// Trigger that hides navigation menus
function getNavTriggers() {
	// Check that the browser is DOM compliant
	if (document.getElementById) {
		var trigger = document.getElementById('content');
		trigger.onmouseover = hideNav;
	}
}

// ON-LOAD EVENTS 
addEvent(window, 'load', getSpecialLinks);
addEvent(window, 'load', getNavTriggers);