// find which anchor tags need popups, and attach openWindow to those that do
function findPopups() {

	// make a container array for all anchor tags
	var allAnchorTags = document.getElementsByTagName("a");
	
	// loop through the anchor tags, and assign openWindow to the popups
	for (i=0; i<allAnchorTags.length; i++) {
		var thisClassName = allAnchorTags[i].className;
		if (thisClassName.indexOf("windowpop") != -1) {
			// var thisUrl = allAnchorTags[i].href;
			allAnchorTags[i].onclick = openWindow;
		}
	}
	
}

// opens a new, centered window
function openWindow(e) {
	// Get the event object
	if (!e) var e = window.event;
	
	// check to see if we clicked on an image
	var thisTagName = (e.target) ? e.target.tagName : e.srcElement.tagName;
	if (thisTagName != "IMG") {
		// what's the href and class name of this link?
		var thisUrl = (e.target) ? e.target.href : e.srcElement.href;
		var thisClass = (e.target) ? e.target.className : e.srcElement.className;
	} else {
		// what's the href and class name of this link?
		var thisUrl = (e.target) ? e.target.parentNode.href : e.srcElement.parentNode.href;
		var thisClass = (e.target) ? e.target.parentNode.className : e.srcElement.parentNode.className;
	}
	
	// what are the width and height values given to the class?
	var thisClassSplit2 = thisClass.split(" ");
	var thisClassSplit = thisClassSplit2[0].split("_");
	var thisWidth = thisClassSplit[1];
	var thisHeight = thisClassSplit[2];
	
	// for window positioning
	var posX;
	var posY;

	// window positioning calculations
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - thisWidth) / 2;
		var yc = (ah - thisHeight) / 2;

		posX = xc;
		posY = yc;
	}

	// is this a scrollable pop-up window?
	if (thisClassSplit[3]) {
		// features for the popup window
		var features = "left=" + posX + ",top=" + posY + ",width=" + thisWidth + ",height=" + thisHeight + "toolbar=no,scrollbars=yes";
	} else {
		// features for the popup window
		var features = "left=" + posX + ",top=" + posY + ",width=" + thisWidth + ",height=" + thisHeight + "toolbar=no,scrollbars=no";
	}
	
	// open the new window, and give it focus
	var theWindow = window.open(thisUrl, "WindowPop", features);
	theWindow.focus();
	
	// don't do anything else
	if (window.addEventListener) //DOM method
		return false;
	else if (window.attachEvent) //IE exclusive method
		e.returnValue = false;
}

if (window.addEventListener) //DOM method for binding an event
window.addEventListener("load", findPopups, false);
else if (window.attachEvent) //IE exclusive method for binding an event
window.attachEvent("onload", findPopups);
else if (document.getElementById) //support older modern browsers
window.onload=findPopups;