// Set up cross-browser event handling (IE5+, NS6+ and Mozilla/Gecko)
// Useage: addEvent(window, 'load', addListeners, false);
function addEvent(elm, evType, fn, useCapture)
{
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
		return true;
	}
}

// open external links in new browser
function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
			anchor.target = "_blank";
		}
	}
}

// Remove anchor outlines from all links in the document
function blurAnchors()
{
	if (!document.getElementsByTagName) return;
 	var a = document.getElementsByTagName('a');
	for (var i = 0; i < a.length; i++) {
		a[i].onfocus = function() {
 			this.blur();
	 	};
	}
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Centered pop-up window
function openWindow (url, width, height, toolbar, scroll, center)
{
	var name = new Date ();
	name = name.getTime ();
	name = name.toString ();
	toolbar = toolbar ? "yes" : "no";
	scroll = scroll ? "yes" : "no";
	var features = "toolbar="+toolbar+",menubar="+toolbar+",location="+toolbar+",status="+toolbar+",scrollbars="+scroll+",resizable="+scroll;
	if (width) features += ",width=" + width;
	if (height) features += ",height=" + height;
	if (center) {
		if (width && window.screen.availWidth) {
			var x = Math.round ((window.screen.availWidth - parseInt (width)) / 2);
			features += ",screenX="+x+",left="+x;
		}
		if (height && window.screen.availHeight) {
			var y = Math.round ((window.screen.availHeight - parseInt (height)) / 2);
			features += ",screenY="+y+",top="+y;
		}
	}
	window.open (url, name, features);
}

// openWindow preset functions
openCenter = function (url, width, height) { openWindow (url, width, height, false, false, true); }
openCenterChrome = function (url, width, height) { openWindow (url, width, height, true, false, true); }
openCenterScroll = function (url, width, height) { openWindow (url, width, height, false, true, true); }
openCenterChromeScroll = function (url, width, height) { openWindow (url, width, height, true, true, true); }

// Menu fix for IE and old versions of Opera
function menuHover()
{
	var d = document;
	if (!d.getElementById) return;
	if (!d.all) return;
	var menuItems = d.getElementById('nav').getElementsByTagName('li');
	for (var i = 0; i < menuItems.length; i++) {
		menuItems[i].onmouseover = function() {
			this.className = 'mnhover';
		}
		menuItems[i].onmouseout = function() {
			this.className = '';
		}
		// Add alpha transparencey in IE 5.5+
		var hasSub = menuItems[i].getElementsByTagName('ul')[0];
		if (hasSub && (typeof hasSub.filters == 'object')) {
			hasSub.style.filter = 'alpha(opacity=90)';
		}
	}
}

// |||||||||||||||||||||||||||||||||||||||||||
// Inititalize listeners and functions
addEvent(window, 'load', blurAnchors, false);
addEvent(window, 'load', externalLinks, false);
addEvent(window, 'load', menuHover, false);