// in this version of the popup manager, all popup source files (html) need to be stored underneath the current page
// in a folder called "glossary"

var openPopups = 0; //number of popup windows in use
//var preloadFlag = false; //not sure I need this
//var left_to_load = 12; 
var popups = new Array(); //array that will hold all the glossary item objects as they open

//define the glossary Item object
function glossitem (glname,glwindow) {
this.glname = glname;
this.glwindow= glwindow;
}
new glossitem();

// main popup function
// goes through all open windows in a for loop and checks to see if there is already
// a popup with the given window name (x)
// if it finds one, and it is closed, it recreates it. If it's open, it simply restores focus to it

function popup(x,wdth) {

for (itm =0;itm<popups.length;itm++) {
	if (popups[itm].glname==x) {
		if (popups[itm].glwindow.closed) {
		popups[itm] = new glossitem(	"glossary/"+x+".html",window.open(x,x,"left=2,top=2,screenX=2,screenY=2,scrollbars=yes,width="+wdth+",toolbar=yes,menubar=yes"));
		}
		
		popups[itm].glwindow.focus();
		return //break out of the function since window has been called before
		
	}
}
// if not broken out (i.e., if this is a new window being called), then create a new 
// popup window in the popups array at the last index number, "openPopups".

popups[openPopups] = new glossitem(x,window.open("Glossary/"+x+".html",x,"left=2,top=2,screenX=2,screenY=2,scrollbars=yes,width="+wdth+"toolbar=yes,menubar=yes"));

popups[openPopups].glwindow.focus();//focus on this new window

openPopups ++; //update the counter
return;// go back

}

function cleanUp() {
for (itm =0;itm<popups.length;itm++) {

if (!popups[itm].glwindow.closed){popups[itm].glwindow.close()}
}

}
// -->

