	topCount = 0;
  if (!window.imgHspace) imgHspace=0;
	
function Initialise() {
	bIsLoaded = false;
	bAllFinished = false;
	bBeingCreated = true;
	bOverMenu = false;
	iHighestZ = 50000;
	mSecsVis = iSecondsVisible * 1000;
	topCount = 1;
	allTimer = null;

	iImageSpan = (IE4) ? iImageSize : iImageSize + 12;
	sImageHTML = "<SPAN STYLE='width:" + iImageSpan + ";height:100%;float:right'>";
	sImageHTML += "<IMG SRC='" + sImage + "' WIDTH=" + iImageSize + " HEIGHT=" + iImageSize + " BORDER=0>";
	sImageHTML += "</SPAN>";
}

function LoadMenus(menuID) {
	Initialise();
	menuArrayName = (LoadMenus.arguments.length==0) ? "arMenu" : menuID;
	while(eval("window." + menuArrayName + topCount)) {
		(IE4) ? GenerateTreesIE(false, topCount) : makeMenuNN(false, topCount);
		topCount++ }
	bIsLoaded = true;
	status = (topCount-1) + " Hierarchical Menu Trees Created"
	bAllFinished = true;
	bBeingCreated = false;
}

function makeMenuNN(bIsChild, menuCount, parentMenu, parItem) {
	menu = eval("Menu" + menuCount + "= new Layer(null, window)");
	menu.array = eval(menuArrayName + menuCount);
	menu.SetTreeProperties = SetTreeProperties;
	menu.SetTreeProperties(bIsChild,parentMenu);

	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
		status = "Creating Hierarchical Menus: " + menuCount + " / " + menu.itemCount;
		prevItem = (menu.itemCount > 1) ? menu.item : null;
		sArrayName = "item" + menuCount + "_" + menu.itemCount;

		menu.item = eval(sArrayName + "= new Layer(width, menu)");
		menu.item.prevItem = prevItem;
		menu.item.setup = itemSetup;
		menu.item.setup(menu.itemCount,menu.array);
		if (menu.item.hasChildren) {
			makeMenuNN(true, menuCount + "_" + menu.itemCount, menu, menu.item);
			menu = menu.parentMenu; }
	}
	menu.lastItem = menu.item;
	menu.setup(bIsChild, parentMenu, parItem);
	menu.xPos = aPosX[menuCount - 1];
	menu.yPos = aPosY[menuCount - 1];
}

function GenerateTreesIE(bIsChild, menuCount, parentMenu) {
	sMenuID = "Menu" + menuCount;
	sElementHTML = "<DIV ID=" + sMenuID + " STYLE='position:absolute'></DIV>";
	window.document.body.insertAdjacentHTML("BeforeEnd", sElementHTML);
	
	menu = eval(sMenuID);
	menu.array = eval(menuArrayName + menuCount);
	menu.SetTreeProperties = SetTreeProperties;
	menu.SetTreeProperties(bIsChild, parentMenu);
	menu.itemStr = "";
	
	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
		status = "Creating Hierarchical Menus: " + menuCount + " / " + menu.itemCount;
		sItemID = "item" + menuCount + "_" + menu.itemCount;
		iArrayNum = (menu.itemCount - 1) * iMaxPar;
		text = menu.array[iArrayNum];
		bHasChildren = menu.array[iArrayNum + 2];
		statusText = (iMaxPar==4) ? "" : menu.array[iArrayNum + 3];
		sTextHTML = (bHasChildren) ? sImageHTML + text : text;
		menu.itemStr += "<SPAN ID=" + sItemID + " STYLE=\"width:" + width + "\">" + sTextHTML + "</SPAN><BR>";
		if (bHasChildren) {
			GenerateTreesIE(true, menuCount + "_" + menu.itemCount, menu);
			menu = menu.parentMenu; }	
	}
	menu.innerHTML = menu.itemStr;
	itemCol = menu.children.tags("SPAN");
	for (i=0; i<itemCol.length; i++) {
		it = itemCol(i);
		it.setup = itemSetup;
		it.setup(i+1, menu.array);
  }
	menu.lastItem = itemCol(itemCol.length-1);
	menu.setup(bIsChild, parentMenu);
	menu.xPos = aPosX[menuCount - 1];
	menu.yPos = aPosY[menuCount - 1];
}

function SetTreeProperties(bIsChild, parentMenu) {
	this.width = width;
	this.backColour = backCol;
	this.overColour = overCol;
	this.fontOverColour = overFnt;
	this.borderColour =  borCol;
	this.maxItems = this.array.length / iMaxPar;
	this.hasParent = bIsChild;
	this.setup = menuSetup;
	this.itemCount = 0;
	
	if (!bIsChild) {
		this.parentTree = this;
		this.startChild = this; }
	else { this.parentTree = parentMenu.parentTree; }
}

function itemSetup(whichItem, whichArray) {
	this.onmouseover = itemOver;
	this.onmouseout = itemOut;
	this.container = (IE4) ? this.offsetParent : this.parentLayer;
	iArrayNum = (whichItem - 1) * iMaxPar;
	this.text = whichArray[iArrayNum];
	this.URL = whichArray[iArrayNum + 1];
	this.hasChildren = whichArray[iArrayNum + 2];
	this.statusText = (iMaxPar==4) ? whichArray[iArrayNum + 3] : "";

	if (IE4 && this.hasChildren) {
		this.child = eval("Menu" + this.id.substr(4));
		this.child.parentMenu = this.container;
		this.child.parentItem = this;
	}
	if (this.URL) {
		if (IE4) { this.onclick = linkIt; this.style.cursor = "hand"; }
		if (NS4) { this.captureEvents(Event.MOUSEUP); this.onmouseup = linkIt; }
	}
	if (IE4) {
		with (this.style) {
			padding = itemPad;
			paddingRight = itemPad;
			color = sFontColour;
			fontSize = iFontSize + "pt";
			fontWeight = (iFontWeight=="") ? "normal" : iFontWeight;
			fontFamily = sFontFace;
			borderBottomWidth = (bBottomWidth==null)?"1px":bBottomWidth + "px";
			borderBottomColor = borCol;
			borderBottomStyle = "solid";
			backgroundColor = backCol; }
	}
	if (NS4) {
		this.HTML = "<FONT FACE='" + sFontFace + "' POINT-SIZE=" + iFontSize + " COLOR='" + sFontColour + "'>" + this.text + "</FONT>";
		if(this.hasChildren) { this.document.write(sImageHTML); this.document.close(); }  
		this.visibility = "inherit";
		this.bgColor = backCol;
		if (whichItem == 1) { this.top = itemPad; }
		else { this.top = (this.prevItem.top + this.prevItem.clip.height + 1) }
		this.left = itemPad;
		this.clip.top = this.clip.left = -itemPad + 1;
		this.clip.right = (this.container.width - itemPad - 1);
		iMaxSpace= this.container.width - (itemPad*2);
		this.textLayer = new Layer(iMaxSpace, this);
		this.textLayer.document.write(this.HTML);
		this.textLayer.document.close();
		this.textLayer.visibility = "inherit";
		this.clip.bottom = this.textLayer.document.height + itemPad;
		this.dummyLyr = new Layer(100, this);
		this.dummyLyr.left = this.dummyLyr.top = -itemPad;
		this.dummyLyr.clip.width = this.clip.width;
		this.dummyLyr.clip.height = this.clip.height;
		this.dummyLyr.visibility = "inherit"; }
}	

function menuSetup(hasParent, openCont, openItem) {
	this.onmouseover = menuOver;
	this.onmouseout = menuOut;
	
	this.showIt = showIt;
	this.keepInWindow = keepInWindow;
	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideChildren = hideChildren;
	this.hideTop = hideTop;
	this.hasChildVisible = false;
	this.isOn = false;
	this.hideTimer = null;
	this.childOverlap = childOverlap;
	this.currentItem = null;
	this.hideSelf = hideSelf;
		
	if (hasParent) {
		this.hasParent = true;
		this.parentMenu = openCont;
		if (NS4) { this.parentItem = openItem; this.parentItem.child = this }}
	else { this.hasParent = false; }
  if (IE4) {
		with (this.style) {
			width = this.width;
			borderWidth = (bBorderWidth==null)?1:bBorderWidth;
			borderColor = this.borderColour;
			borderStyle = "solid";
			zIndex = iHighestZ; }
		this.lastItem.style.border="";
		this.showIt(false);
		this.onselectstart = cancelSelect;
		this.moveTo = moveTo;
		this.moveTo(0,0);
	}
	if (NS4) {
		this.bgColor = this.borderColour;
		this.fullHeight = this.lastItem.top + this.lastItem.clip.bottom + 1;
		this.clip.right = this.width;
		this.clip.bottom = this.fullHeight;
	}
}

function menuShow(menuName, e){
	var i;
	if (!bIsLoaded) return;
	showHide('ComboBox','','hide');
	for (i=1; i<25; i=i+1) showHide('ComboBox'+i,'','hide');
	LinkElement = (IE4) ? event.srcElement : e.target;
	if (!bBeingCreated && !bAllFinished) LoadMenus();
	LinkElement.menuName = menuName;	
	setTimeout("if(!bOverMenu && !vShowMenu)hideAll();", mSecsVis);
	ShowIt(e);
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}

function showHide() {
  var i,p,v,obj,args=showHide.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function ShowIt(e){
	if (!bIsLoaded || !bAllFinished) return true;
	hideAll();
	LinkElement = (IE4) ? event.srcElement : e.target;
	currentMenu = eval(LinkElement.menuName);
	currentMenu.hasParent = false;
	currentMenu.parentTree.startChild = currentMenu;
	currentMenu.moveTo(currentMenu.xPos, currentMenu.yPos);
	currentMenu.isOn = true;
	currentMenu.showIt(true);
	return false;
}

function Show(menuName, e) {
	if (!bIsLoaded) return;
	vShowMenu = true;
	menuShow(menuName, e);
}

function menuOff() {
	if (!bIsLoaded) return;
	vShowMenu = false;
}

function menuOver(e) {
	this.isOn = true;
	bOverMenu = true;
	currentMenu = this;
	if (this.hideTimer) clearTimeout(this.hideTimer);
}

function menuOut() {
	if (IE4) { if (window.event.srcElement.contains(window.event.toElement)) return; }
	this.isOn = false;
	bOverMenu = false;
	window.status = "";
	allTimer = setTimeout("currentMenu.hideTree();",10);
}

function itemOver(){
	if (keepHilite) {
		if (this.container.currentItem && this.container.currentItem != this) {
			if (IE4) with (this.container.currentItem.style) { backgroundColor = backCol; color = sFontColour }
			if (NS4) { this.container.currentItem.bgColor = backCol; color = sFontColour }
				
		}}
	if (IE4) {
		theEvent = window.event;
		if (theEvent.srcElement.tagName == "IMG") return;
		this.style.backgroundColor = this.container.overColour;
		this.style.color = this.container.fontOverColour }
	else { this.bgColor = this.container.overColour; this.color = this.container.overColour; }

	window.status = (this.statusText=="") ? this.text : this.statusText;
	this.container.currentItem = this;
	if (this.container.hasChildVisible) { this.container.hideChildren(this); }
	if (this.hasChildren) { 
		horOffset = (this.container.width - this.container.childOverlap);
		if (NS4) {
			this.childX = this.container.left + horOffset;
			this.childY = (this.pageY+this.clip.top) + childOffset; }
		else {
			this.childX = this.container.style.pixelLeft + horOffset;
			this.childY = this.offsetTop + this.container.style.pixelTop + childOffset + 1; }
		this.child.moveTo(this.childX, this.childY);
		this.child.keepInWindow();
		this.container.hasChildVisible = true;
		this.container.visibleChild = this.child;
		this.child.showIt(true);
	}
}

function itemOut() {
	if (IE4) {
		theEvent = window.event;
    	if (theEvent.srcElement.contains(theEvent.toElement)
     || (theEvent.fromElement.tagName=="IMG" && theEvent.toElement.contains(theEvent.fromElement)))
        return;
		if (!keepHilite) this.style.backgroundColor = backCol; this.style.color = sFontColour }
	else {
		if (!keepHilite) this.bgColor = backCol; this.color = sFontColour
		if (!bOverMenu) { allTimer = setTimeout("currentMenu.hideTree()",10); }
	}
}

function moveTo(xPos, yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

function showIt(on) {
	var i;
	vShowHide = (!on)?"show":"hide";
	if (NS4) {
		this.visibility = (on) ? "show" : "hide";
		if (keepHilite && this.currentItem) { this.currentItem.bgColor = this.backColour; }}
	else {
		this.style.visibility = (on) ? "visible" : "hidden";
		if (keepHilite && this.currentItem) {
			with (this.currentItem.style) {
				backgroundColor = this.backColour;
				color = this.fontColour; }}}
	this.currentItem = null;
	showHide('ComboBox','',vShowHide);
	for (i=1; i<25; i=i+1) showHide('ComboBox'+i,'',vShowHide);
}

function keepInWindow() {
	scrBars = 20;
	botScrBar = scrBars;
	rtScrBar = scrBars;
	if (NS4) {
		winRight = (window.pageXOffset + window.innerWidth) - rtScrBar;
		rightPos = this.left + this.width;
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.left;
				newLeft = ((parentLeft-this.width) + this.childOverlap);
				this.left = newLeft;}
			else {
				dif = rightPos - winRight;
				this.left -= dif; }}
		winBot = (window.pageYOffset + window.innerHeight) - botScrBar ;
		botPos = this.top + this.fullHeight;
		if (botPos > winBot) {
			dif = botPos - winBot;
			this.top -= dif; }
		winLeft = window.pageXOffset;
		leftPos = this.left;
		if (leftPos < winLeft) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.left;
				newLeft = ((parentLeft+this.width) - this.childOverlap);
				this.left = newLeft; }
			else { this.left = 5;}}}
	else {
    winRight = (window.document.body.scrollLeft + window.document.body.clientWidth) - rtScrBar;
		rightPos = this.style.pixelLeft + this.width;
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.style.pixelLeft;
				newLeft = ((parentLeft - this.width) + this.childOverlap);
				this.style.pixelLeft = newLeft; }
			else {
				dif = rightPos - winRight;
				this.style.pixelLeft -= dif; }}

		winBot = (window.document.body.scrollTop + window.document.body.clientHeight) - botScrBar;
		botPos = this.style.pixelTop + this.fullHeight;

		if (botPos > winBot) {
			dif = botPos - winBot;
			this.style.pixelTop -= dif; }
		
		winLeft = window.document.body.scrollLeft;
		leftPos = this.style.pixelLeft;

		if (leftPos < winLeft) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.style.pixelLeft;
				newLeft = ((parentLeft+this.width) - this.childOverlap);
				this.style.pixelLeft = newLeft; }
			else { this.style.pixelLeft = 5; }}}
}

function linkIt() {
	if (this.URL.indexOf("javascript:")!=-1) eval(this.URL)
	else window.location.href = this.URL;
}

function Hide(menuName){
	if (!bIsLoaded || !bAllFinished) return;
	whichEl = eval(menuName);
	whichEl.isOn = false;
	whichEl.hideTop();
}

function hideAll() {
	for(i=1; i<topCount; i++) {
		temp = eval("Menu" + i + ".startChild");
		temp.isOn = false;
		if (temp.hasChildVisible) temp.hideChildren();
		temp.showIt(false);
	}
}

function hideTree() {
	allTimer = null;
	if (bOverMenu) return;
	if (this.hasChildVisible) {
		this.hideChildren(); }
	this.hideParents();
}

function hideTop() {
	whichTop = this;
	this.hideTimer = setTimeout("if(whichTop.hideSelf)whichTop.hideSelf()",mSecsVis);
}

function hideSelf() {
	this.hideTimer = null;
	if (!this.isOn && !bOverMenu) { 
		this.showIt(false);
	}
}

function hideParents() {
	tempMenu = this;
	while (tempMenu.hasParent) {
		tempMenu.showIt(false);
		tempMenu.parentMenu.isOn = false;		
		tempMenu = tempMenu.parentMenu;
	}
	tempMenu.hideTop();
}

function hideChildren(item) {
	tempMenu = this.visibleChild;
	while (tempMenu.hasChildVisible) {
		tempMenu.visibleChild.showIt(false);
		tempMenu.hasChildVisible = false;
		tempMenu = tempMenu.visibleChild;
	}
	if (!this.isOn || !item.hasChildren || this.visibleChild != this.child) {
		this.visibleChild.showIt(false);
		this.hasChildVisible = false; }
}

function cancelSelect(){ return false }
