var vCurrentPage = "frontpage";

var isIE = (navigator.userAgent.indexOf("MSIE")    != -1);
var isNS = !isIE && (navigator.userAgent.indexOf("Mozilla")    != -1);

var sCurrent = "";
var bJokesEnabled = false;

var aText;
var aTitle;
var aLinks;
var aIDs;
var aHashes;
var aTargets;
var aClasses;

var len;
var d;


function mouseOver(obj) {

	obj.style.color = "white";
	obj.style.backgroundColor = "#800080";
}

function mouseOutItem(obj) {

	obj.style.color = "blue";
	obj.style.backgroundColor = "white";
}

function mouseOutHeader(obj) {

	obj.style.color = "black";
	obj.style.backgroundColor = "white";
}

function mouseOutToolbar(obj) {
	
	obj.style.color = "white";
	obj.style.backgroundColor = "black";
}

function SetFrontPage(src)
{
	//	Establish current item and avoid reloading the existing 
	//	document
	if (vCurrentPage != src) {

		//	Log the current front page
		vCurrentPage = src;

		if (isIE) {
			parent.frames["frontpage"].navigate(src);
		}
		else if (isNS) {
			open(src, "frontpage");
		}
		else {
			open(src, "frontpage");
		}
	}
}


function doNothing()
{
}

function InitialiseTree() {

	if (isIE) {

		d = parent.frames["contents"].document;
		var bFirst = true;
		var sFirst = "";

		for (var n = 0; n < d.all.length; n++) {
			if ("menuHeader" == d.all[n].className) {

				var s = d.all[n].id;
				s = s.slice(2, s.length);
				var obj = d.all[s];

				if (obj) {
					if (true == bFirst) {
						bFirst = false;
						obj.style.display = "block";
						sFirst = s;
					}
					else {
						obj.style.display = "none";
					}
				}
			}
		}

		sCurrent = "";
		if (sFirst.length > 0) {
			ShowSubMenu(sFirst);
		}
	}
	else if (isNS) {
	
		//SuppressEvents();

		d = parent.frames["contents"].document;
		
		len = d.links.length;

		aText = new Array(len);
		aTitle = new Array(len);
		aLinks = new Array(len);
		aIDs = new Array(len);
		aHashes = new Array(len);
		aTargets = new Array(len);
		aClasses = new Array(len);
		
		for (var n = 0; n < len; n++) {
		
		    var l = d.links[n];
		
			aText[n] = l.text;
			aTitle[n] = l.title;
			aLinks[n] = l.href;
			aIDs[n] = l.ID;
			aHashes[n] = l.hash;
			aTargets[n] = l.target;
			aClasses[n] = l.className;
		}

		parent.frames['toolbar'].ShowNSTree(4);
	}
}

function ShowNSTree(idx) 
{
	var nCnt = 0;
	var n = 0;
	var htmlString = "";
	var isMenuHeader = false;
	var isChildless = false;

	len = aText.length;

	htmlString = "<html>";
	htmlString += "<head>";
    htmlString += "<link rel='stylesheet' href='styles.css' type='text/css'>";
    htmlString += "<link rel='stylesheet' href='pagestyle.css' type='text/css'>";
	htmlString += "</head>";
	htmlString += "<BODY>";
	htmlString += "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD>";

	nCnt = 0;

	for (n = 0; n < len; n++) {
	
		isChildless = false;
	    isMenuHeader = false;

		if ("menuHeader" == aClasses[n]) {
		
			isMenuHeader = true;
			nCnt++;
		}

//		if ("frontpage" != aTargets[n + 1]) {
//			isChildless = false;
//		}
//		else {
//			if ("#top" == aHashes[n + 1] || aHashes[n + 1].length == 0 || "javascript:doNothing();" == aLinks[n + 1]) {
//				if (aLinks[n + 1].indexOf("SetCurrentJokes") == -1) {
//					isChildless = true;
//				}
//			}
//		}

		if ((nCnt == idx - 1) || (true == isMenuHeader)) {

			if (true == isMenuHeader) {

                if (n < len - 1) {			
				    isChildless = ("menuHeader" == aClasses[n + 1]);
				}

				if (1 != nCnt) {
					htmlString += "</TD></TR><TR><TD VALIGN=MIDDLE ALIGN=MIDDLE WIDTH=9>";
				}

				if (true == isChildless) {
					htmlString += "<IMG SRC='empty.gif' CLASS='treeRoot' BORDER=0></TD><TD>";
				}
				else {

					htmlString += "<A HREF=\"javascript:parent.frames['toolbar'].ShowNSTree(" + (nCnt + 1) + ");\">";

					if (nCnt == idx - 1) {
						htmlString += "<IMG NAME='IMG_" + nCnt + "' SRC='minus.gif' CLASS='treeRoot' BORDER=0>";
					}
					else {
						htmlString += "<IMG NAME='IMG_" + nCnt + "' SRC='plus.gif' CLASS='treeRoot' BORDER=0>";
					}

					htmlString += "</A></TD><TD>";
				}
			}
			else {
				htmlString += "<IMG SRC='blubulit.gif' ALIGN=LEFT>";
			}

			htmlString += "<A HREF='";
			htmlString += aLinks[n];
			htmlString += "' ID='";
			htmlString += aIDs[n];
			htmlString += "' TARGET='";
			htmlString += aTargets[n];
			htmlString += "' TITLE='";
			htmlString += aTitle[n];
			htmlString += "' onMouseOver=\"parent.frames['toolbar'].mouseOver(this);\"";

			if (true == isMenuHeader) {
    			htmlString += "' onMouseOut=\"parent.frames['toolbar'].mouseOutHeader(this);\"";
    		}
    		else {
    			htmlString += "' onMouseOut=\"parent.frames['toolbar'].mouseOutItem(this);\"";
    		}
    		
			htmlString += " CLASS='";

			if (true == isMenuHeader) {
				htmlString += "menuHeader";
			}
			else {
				htmlString += "menuItem";
			}

			htmlString += "'>";
			htmlString += aText[n];
			htmlString += "<BR></A>";

			if (true == isMenuHeader) {
				htmlString += "</TD></TR><TR VALIGN=TOP><TD VALIGN=MIDDLE ALIGN=MIDDLE WIDTH=9></TD><TD VALIGN=TOP>";
			}
		}
	}

	htmlString += "</TD></TR></TABLE>";
	htmlString += "</BODY>";
	htmlString += "</html>";
	
	parent.frames["contents"].document.open();
	parent.frames["contents"].document.write(htmlString);
	parent.frames["contents"].document.close();
	
	//document.data = s;
}

function ShowSubMenu(sMenu) 
{
	if (isIE) {

		if (sCurrent != sMenu) {
			if (sCurrent.length > 0) {

				d.all[sCurrent].style.display = "none";
				d.all["IMG_" + sCurrent].src = "plus.gif";
			}
		}

		sCurrent = sMenu;
		d.all[sCurrent].style.display = "block";
		d.all["IMG_" + sCurrent].src = "minus.gif";
	}
}


