// JavaScript Document

// ================= INITIALIZATION FUNCTION ================== // 
function init() {
	addEvent(window, 'load', getAnchors, false);	
}

// add event function
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;
	}
}







// =========== DYNAMIC POPUP SCRIPT ================ //
function getAnchors() {
	var anchors = document.getElementsByTagName("a");
	
	for(i=0; i<anchors.length; i++) {
		// set anchor vars
		var a = anchors[i];
		var aHref = a.getAttribute('href');
		// create an array of the options
		if(a.getAttribute('rel')) {
			var aRel = a.getAttribute('rel');
			// split the rel into attributes
			var aRelArr = aRel.split('|');
			// make sure the link is a popup
			if(aRelArr[0] == 'popup') {
				// if the noicon flag is not set, style the link
				if(aRelArr[1] != 'noicon') {
					a.style.backgroundImage = "url(images/popup.gif)";
					a.style.backgroundPosition = "top right";
					a.style.backgroundRepeat = "no-repeat";
					a.style.paddingRight = "15px";
					a.style.marginRight = "3px";
				}
				// append to the title attribute
				a.title += ' [Opens in new window]';
				
				// add an onclick handler to trigger the popup
				a.setAttribute('href',"javascript:popUp('" + aHref + "','newWin','')");
			}
		}	
	}
}

function popUp(url) {
	window.open(url,'newWin','');
	
	if(window.event) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	}
}







window.onload = init();
