function glossFix (win) {
	var ankText = win.location.hash.substring(1);
	win.document.title = "Glossary: " + ankText;
	// Set up initial entry id
	win.document.entryId = ankText;
	// Hide the other entries
	hideContent(win);
	// Style the active entry
	var entry = win.document.getElementById(ankText);
	styleEntry (entry);
	// Set up links within the document to toggle visibility
	toggleAnchors(win);
}

function hideContent (win) {
	var divs = win.document.getElementsByTagName('div');

	// Hide non-content divs
	for (var i = 0; i < divs.length; i++) {
		// Need to skip both main and content
		if (divs[i].id != "main" && divs[i].id != "content") {
			divs[i].style.visibility = "hidden";
		} 
	}

	// Hide content - need to do it this way so can make visible
	var paras = win.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 = win.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";
	}
}

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 toggleAnchors (win) {
	// Get all the links in the page
	var links = win.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 = win.document.getElementById(newAnk);
				// Style it
				styleEntry(newEntry);
				// Make old entry invisible
				var entry = win.document.getElementById(win.document.entryId);
				entry.style.visibility = "hidden";
				// Set newEntry to entry, so that when switch up, it should still work
				win.document.entryId = newAnk;
			}
		}
	}
}
