/* From the technique explained in the March 2006 edition of the SitePoint Design View. */

/* This handy function from Simon Willison allows you to stack up 'window.onload' events without them stepping on each other's toes. */

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* Old pop-up */
function openAWindow( pageToLoad, winName, width, height, center, resize, scroll) {

	xposition=0; yposition=0;

	if (resize==null) { resize=1; }
	if (scroll==null) { scroll=1; }

	if ((parseInt(navigator.appVersion) >= 4 ) && (center)) {
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}

	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=" + resize + ","
	+ "scrollbars=" + scroll + ","
	+ "status=0,"
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + ","  //NN Only
	+ "screeny=" + yposition + ","  //NN Only
	+ "left=" + xposition + ","     //IE Only
	+ "top=" + yposition;           //IE Only

	window.open( pageToLoad,winName,args );
}

/* Accessible, unobtrusive popup code */

function windowLinks() {
	if(!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		var relIndex = anchor.rel;
		if (relIndex){
			var relSplit = relIndex.split("|");
/* XHTML compliant target attribute */
		if (relSplit[0] == "external") {
//			anchor.target = "_blank";
//			anchor.className = "external";
//			anchor.title = "Load in new window: "+ anchor.href;
/* XHTML compliant popup attribute */
		} else if (relSplit[0] == "popup") {
			anchor.className = "popup";
			anchor.title = "Link loads in Popup Window";
			anchor.popupName = relSplit[1];
			anchor.popupWidth = relSplit[2];
			anchor.popupHeight = relSplit[3];
			anchor.popupPos = relSplit[4];
			anchor.onclick = function() {openAWindow(this.href,this.popupName,this.popupWidth,this.popupHeight,this.popupPos);return false;};
			}
		}
	}
}

addLoadEvent(function() {
	windowLinks();
//otherFunctions();
//goHere();
});
