window.onload = windowOnload;

function windowOnload() {
	AddGlossary();
}

sfHover = function() {
	var sfEls = document.getElementById("nav_main_wrapper").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


//	AddGlossary - created 31/10/2006 by Matt Stow
//	Cycles through all links in a particular element (default is content)
//	and grabs all "nice" links and appends a Glossary to the foot of the page.
//	Use CSS show and hide where required. Its intended use is for printouts.
//	Call the function onload.

function AddGlossary(contentElement) {
	if ((document.getElementById) && (document.getElementsByTagName)) {
		// If an id of an element is provided, search it for links
		if (contentElement) {
			contentElement = document.getElementById(contentElement);
		}
		else {
			contentElement = document.getElementById("content");
		}
		links = contentElement.getElementsByTagName("a");
		// If there are links within the element...
		if (links.length > 0) {
			linksGlossary = new Array();
			// Store the current domain. Remove any #s
			domain = "" + window.location;
			if (domain.indexOf("#") != -1) {
				domainSplit = domain.split("#");
				domain = domainSplit[0];
			}
			for (a=0; a<links.length; a++) {
				// If the href doesn't contain a #, javascript or have zero length (ie <a name="#anchor"></a>)
				if ((links[a].href.indexOf("#") != domain.length) && (links[a].href.length > 0) && (links[a].href.indexOf("javascript") == -1)) {
					if (a == 0) {
						b = a+1;
					}
					else {
						b++;
					}
					// Add the link text and href to the Glossary array
					linksGlossary[a] = new Array(links[a].innerHTML,links[a].href);
					// Create a numbered superscript element and append it to the link
					superscript = document.createElement("sup");
					superscript.className = "glossary";
					superscript.innerHTML = "[" + b + "]";
					links[a].appendChild(superscript);
				}
			}
			bodyElement = document.getElementsByTagName("body");
			// Create Glossary div and ordered list
			glossaryElement = document.createElement("div");
			glossaryElement.className = "glossary";
			htmlString = "<hr /><h2>Glossary of Links<\/h2>\n<ol>\n";
			for (c=0; c<linksGlossary.length; c++) {
				// If the array is not null...
				if (linksGlossary[c]) {
					htmlString += "<li>\n";
					// ... create the li, which includes the link text and the href
					for (d=0; d<linksGlossary[c].length; d++) {
						if (d == 0) {
							htmlString += "<strong>" + linksGlossary[c][d] + "<\/strong> - ";
						}
						else {
							htmlString += "<a href=\"" + linksGlossary[c][d] + "\">" + linksGlossary[c][d] + "<\/a>\n";
						}
					}
					htmlString += "<\/li>\n";
				}
				
			}
			htmlString += "</ol>\n";
			// Set the Glossary's html and append it to the body
			glossaryElement.innerHTML = htmlString;
			bodyElement[0].appendChild(glossaryElement);
		}
	}
}