// Window size variables

// Toolbars on or off
var toolOn = "toolbar=yes, menubar=yes, location=yes,";
var toolOff = "toolbar=no, menubar=no, location=no,";

// Find the center of the screen
var left800 = (screen.width-600)/2;
var top800 = (screen.height-(800 + 110))/2;
var left640 = (screen.width-480)/2;
var top640 = (screen.height-(640 + 110))/2;

// Set the screen positioning parameters
var screenPos800 = " left="+left800+", top="+top800;
var screenPos640 = " left="+left640+", top="+top640;

// Set the open popup parameters
var width800 = " scrollbars=yes, status=no, resizable=yes, width=800, height=600,";
var width640 = " scrollbars=yes, status=no, resizable=yes, width=640, height=480,";

// Find all elements by classname
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// Run through all popWin classes, add access text and click events
function setOpen() {	
	var myEls = getElementsByClass("popWin", document, "a");
	for (i=0; i < myEls.length; i++) {
		winArr = myEls[i];
		// Add the hidden text to each popWin class	
		var addText = "<span class='access'> - opens new window</span>"
		var orgnText = winArr.innerHTML;
		myEls[i].innerHTML = orgnText+addText;
		
		
		// Add the click event to the link
		winArr.onclick = function()	{
			var windowSize = this.attributes.getNamedItem("rel").value;
			var destination = this.attributes.getNamedItem("href").value;
			switch (windowSize) {	
				case "width800":
					window.open(destination, 'NewWindow', toolOn+width800+screenPos800);
				break;
				case "width640":
					window.open(destination, 'NewWindow', toolOn+width640+screenPos640);
				break;
				case "width800_ntb":
					window.open(destination, 'NewWindow', toolOff+width800+screenPos800);
				break;
				case "width640_ntb":
					window.open(destination, 'NewWindow', toolOff+width640+screenPos640);
				break;
			}
			return false;
		}
	}
}
	
plusEvent(window, 'load', setOpen);