function newWindow (page, winName) {
	
	var ankText = page.substring(page.indexOf('#') + 1);
	// need to put the new window where i can get to it again
	
	
	
	if (!self.myWin || self.myWin.closed) {
		// Make new window with variable attached to main window
		self.myWin = window.open (page, winName, 'resizable=yes,width=400,height=200');
		self.myWin.document.title = "Glossary: " + ankText;
		// Initialize window
		self.myWin.onload = function () {			
			// Set up initial entry id
			this.document.entryId = ankText;
			var divs = this.document.getElementsByTagName('div');
			// Hide other divs
			for (var i = 1; i < divs.length; i++) {
				// Need to skip both main and content
				if (divs[i].id != "main" && divs[i].id != "content") {
					divs[i].style.display = "none";
				} 
			}
			var paras = this.document.getElementById('content').getElementsByTagName('p');
			// Hide all paragraphs in the content div except for the entry
			for (var i = 0; i < paras.length; i++) {
				// Hide the other paragraphs, because have already gone to the place in the page where the entry is
				paras[i].style.visibility = "hidden";
			}
			
			var headers = this.document.getElementById('content').getElementsByTagName('h2');
			// Hide all headers in the content div 
			for (var i = 0; i < headers.length; i++) {
				headers[i].style.visibility = "hidden";
			}
			
			// Make entry visible and styled
			var entry = self.myWin.document.getElementById(ankText);
			styleEntry(entry);	
			
			
			// Get all the links in the page
			var links = this.document.getElementsByTagName('a');
			//Set it up so all the links in the page toggle visibility
			for ( var i = 0; i < links.length; i++) {	
				if (links[i].className == "glossary") {
					links[i].onclick = function () {
						// Get the anchor without the #
						var newAnk = this.href.substring(this.href.indexOf('#') + 1);
						// Find the new entry 
						var newEntry = myWin.document.getElementById(newAnk);
						// Make it visible
						newEntry.style.visibility = "visible";
						// Style it
						styleEntry(newEntry);
						// Make old entry invisible
						entry.style.visibility = "hidden";
						// Set newEntry to entry, so that when switch up, it should still work
						entry = newEntry;
						
					}
				}
			}	
		}
		
	} else {
		// pass the actual href
		self.myWin.location.hash = ankText;
		// set focus
		self.myWin.focus();
		// Change the window name
		self.myWin.document.title = "Glossary: " + ankText;
		// Find old entry
		var oldEntry = self.myWin.document.getElementById(self.myWin.document.entryId);
		// Hide old entry
		oldEntry.style.visibility = "hidden";
		// Make entry visible and styled
		var entry = self.myWin.document.getElementById(ankText);
		styleEntry(entry);	
		// Set entryId
		self.myWin.document.entryId = ankText;
	}
	
}

function styleEntry(entry) {
	entry.style.visibility = "visible";
	entry.style.width = "320px";
	entry.style.backgroundColor = "white";
	entry.style.margin = "20px";
	entry.style.border = "1px solid #1b4aab";
	entry.style.padding = "20px";
	entry.style.fontSize = "medium";
}

function newWindow2 (page, winName) {
	
	var ankText = page.substring(page.indexOf('#') + 1);
	// need to put the new window where i can get to it again
	if (!self.myWin || self.myWin.closed) {
	// Make new window with variable attached to main window
		self.myWin = window.open (page, winName, 'resizable=yes,width=400,height=200');
	} else {
		// pass the actual href
		self.myWin.location.hash = ankText;
		// set focus
		self.myWin.focus();
		// Change the window name
		self.myWin.document.title = "Glossary: " + ankText;
		// Find old entry
		var oldEntry = self.myWin.document.getElementById(self.myWin.document.entryId);
		// Hide old entry
		oldEntry.style.visibility = "hidden";
		// Make entry visible and styled
		var entry = self.myWin.document.getElementById(ankText);
		styleEntry(entry);	
		// Set entryId
		self.myWin.document.entryId = ankText;
		return false;
	}
}

/* Set all links with the proper classes to open a newWindow */
function resourceLinks () {
	// Get all links in content div
	var container = document.getElementById('content');
	var links = container.getElementsByTagName('a');
	for (var i = 0; i < links.length; i++) {
		// Check to see if class is "glossary"
		if (links[i].className == "glossary") {
			// Make the link open up the term in the new windowis
			links[i].onclick = function() {  
				newWindow2 (this.href, this.className);
			 	return false;
			 }
		} else if (links[i].className == "biblio") {
			// Set the link to open in a new window in new way
			// links[i].onclick = function() { newWindow('<?php echo BASE; ?>/glossary.php', 
		}
	}
}