topCount = 0;
if (!window.imgHspace) imgHspace=0;
bIsLoaded = false;	
var onMenuItem = 1;
var sMenuImageName = '';
var boverTitleImage = false;
var report = false;

function Initialise() {
	bAllFinished = false;
	bBeingCreated = true;
	bOverMenu = false;
	
	iHighestZ = 50000;
	mSecsVis = iSecondsVisible * 1000;
	topCount = 1;
	allTimer = null;
}


function LoadMenus() {
	LoadMenuImages();
	status = "Loading menus";
	Initialise();
  	if (IE4 || NN4) { 
        	while(eval("window.arMenu" + topCount)) {
			(IE4) ? GenerateTreesIE(false, topCount) : makeMenuNN(false, topCount);
			topCount++; 
			}
	}
	bIsLoaded = true;
	bAllFinished = true;
	bBeingCreated = false;
	status = "";
}

function makeMenuNN(bIsChild, menuCount, parentMenu, parItem) {
	menu = eval("Menu" + menuCount + "= new Layer(null, window)");
	menu.array = eval("arMenu" + menuCount);
	menu.SetTreeProperties = SetTreeProperties;
	menu.SetTreeProperties(bIsChild, parentMenu, menuCount);
	var f = new String;
	var d = new Date;

	while (menu.itemCount < menu.maxItems)
	{
		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, menuCount); //problem here
		if (menu.item.hasChildren)
		{
			makeMenuNN(true, menuCount + "_" + menu.itemCount, menu, menu.item);
			menu = menu.parentMenu;
		}
	}
	menu.lastItem = menu.item; 
	menu.setup(bIsChild, parentMenu, parItem);
	iMenuArray = GetMenuArrayIndex(menuCount) - 1;
	menu.xPos = aPosX[iMenuArray];
	menu.yPos = aPosY[iMenuArray];
	//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("arMenu" + menuCount);
	menu.SetTreeProperties = SetTreeProperties;
	menu.SetTreeProperties(bIsChild, parentMenu, menuCount);
	menu.itemStr = "";

	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
		sItemID = "item" + menuCount + "_" + menu.itemCount;
		iArrayNum = (menu.itemCount - 1) * 3;
		text = menu.array[iArrayNum];
		bHasChildren = menu.array[iArrayNum + 2];
		sTextHTML = (bHasChildren) ? GetImageHTML(menuCount) + 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, menuCount);
  }
	menu.lastItem = itemCol(itemCol.length -1);
	menu.setup(bIsChild, parentMenu);
	iMenuArray = GetMenuArrayIndex(menuCount) - 1;
	menu.xPos = aPosX[iMenuArray];
	menu.yPos = aPosY[iMenuArray];
	//menu.xPos = aPosX[menuCount - 1];
	//menu.yPos = aPosY[menuCount - 1];
}

function SetTreeProperties(bIsChild, parentMenu, menuCount) {
	this.width = width;
	iMenuArray = GetMenuArrayIndex(menuCount) - 1;
	this.backColour = sbackColour[iMenuArray];
	this.FontColour = sFontColour[iMenuArray];
	this.overColour = soverColour[iMenuArray];
	this.overFontColour = soverFontColour[iMenuArray];
	this.borderColour = sborderColour[iMenuArray];
	this.maxItems = this.array.length / 3;
	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, menuCount) {
	this.onmouseover = itemOver;
	this.onmouseout = itemOut;
	this.menuCount = menuCount;
	this.container = (IE4) ? this.offsetParent : this.parentLayer;
	iArrayNum = (whichItem - 1) * 3;
	this.text = whichArray[iArrayNum];
	this.URL = whichArray[iArrayNum + 1];
	this.hasChildren = whichArray[iArrayNum + 2];
	
	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 (NN4) { this.captureEvents(Event.MOUSEUP); this.onmouseup = linkIt; }
	}
	iMenuArray = GetMenuArrayIndex(menuCount) - 1;
	if (IE4) {
		with (this.style) {
			textAlign = stextAlign[iMenuArray];
			color = sFontColour[iMenuArray];
			borderBottomColor = sborderColour[iMenuArray];
			backgroundColor = sbackColour[iMenuArray];

			padding = itemPad;
			paddingRight = itemPad;

			fontSize = iFontSize + "pt";
			fontWeight = "normal";
			fontFamily = sFontFace;			
			borderBottomWidth = "1px";
			borderBottomStyle = "solid";
			
			
			//borderTopWidth = "1px";
			//borderTopStyle = "solid";
			//borderLeftWidth = "1px";
			//borderLeftStyle = "solid";
			//borderRightWidth = "1px";
			//borderRightStyle = "solid";
			//borderRightColor = "FFFFFF";
			//borderLeftColor = "FFFFFF";
			//borderTopColor = "FFFFFF";
			//borderBottomColor = "FFFFFF";

		}
	}
	if (NN4) {
		//this.style.textAlign = stextAlign[iMenuArray];
		this.HTML = "<FONT FACE='" + sFontFace + "' POINT-SIZE=" + iFontSize + " COLOR='" + sFontColour[iMenuArray] + "'>" + this.text + "</FONT>";
		//this.HTML = "<Table border=0 cellspacing=0 cellpadding=0><tr><td align=" + stextAlign[iMenuArray] + "><FONT FACE='" + sFontFace + "' POINT-SIZE=" + iFontSize + " COLOR='" + sFontColour[iMenuArray] + "'>" + this.text + "</FONT></td></tr></table>";
		if(this.hasChildren) { this.document.write(GetImageHTML(menuCount)); this.document.close(); } 
 		this.visibility = "inherit";
		this.bgColor = sbackColour[iMenuArray];
		this.fgColor = sFontColour[iMenuArray];
		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"; 
		if (!report)
		{
			report = true;
		}
	}	
}	

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 (NN4) { this.parentItem = openItem; this.parentItem.child = this }}
	else { this.hasParent = false; }
  	if (IE4) {
		with (this.style) {
			width = this.width;
			borderWidth = 1;
			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 (NN4) {
		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 Show(menuName, e){ 
	if (!bIsLoaded) return;
	LinkElement = (IE4) ? event.srcElement : e.target;
	if (!bBeingCreated && !bAllFinished) LoadMenus();
	LinkElement.menuName = menuName;	
	ShowIt(e);
}

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 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)) 
		onMenuItem = -1;
		//return; 
		
	}
	this.isOn = false;
	bOverMenu = false;
	window.status = "";
	allTimer = setTimeout("currentMenu.hideTree()",10);
}

function itemOver(){
	iMenuArray = GetMenuArrayIndex(this.menuCount) - 1;
	if (bkeepHilite) {
		if (this.container.currentItem && this.container.currentItem != this) {
			if (IE4) with (this.container.currentItem.style) { 
				backgroundColor = sbackColour[iMenuArray]; 
				color = sFontColour[iMenuArray];			
			}
			if (NN4) this.container.currentItem.bgColor = sbackColour[iMenuArray]; this.container.currentItem.fgColor = sFontColour[iMenuArray];
		}}
	if (IE4) {
		theEvent = window.event;
		if (theEvent.srcElement.tagName == "IMG") return;
		this.style.backgroundColor = this.container.overColour;
		this.style.color = this.container.overFontColour; 
	}
	else { 	this.bgColor = this.container.overColour; this.fgColor = this.container.overFontColour; 
	}

	//window.status = this.URL;
	//window.status = this.URL.slice(30, this.URL.length -2);
	window.status = this.text;
	this.container.currentItem = this;
	if (this.container.hasChildVisible) { this.container.hideChildren(this); }
	if (this.hasChildren) { 
		horOffset = (this.container.width - this.container.childOverlap);
		if (NN4) {
			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() {
	iMenuArray = GetMenuArrayIndex(this.menuCount) - 1;
	if (IE4) {
		theEvent = window.event;
    		if (theEvent.srcElement.contains(theEvent.toElement) || (theEvent.fromElement.tagName=="IMG" && theEvent.toElement.contains(theEvent.fromElement))) {
        		return;
		}
		if (!bkeepHilite) {
			this.style.backgroundColor = sbackColour[iMenuArray]; 
			this.style.color = sFontColour[iMenuArray];}
		else {
			this.style.backgroundColor = soverColour[iMenuArray]; 
			this.style.color = soverFontColour[iMenuArray];}
		}
	else {
		if (!bkeepHilite) {
			this.bgColor = sbackColour[iMenuArray]; 
			this.fgColor = sFontColour[iMenuArray];
		}
		if (!bOverMenu) { 
			allTimer = setTimeout("currentMenu.hideTree()",10); 
		}
	}
}

function moveTo(xPos, yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

function showIt(on) {
	if (NN4) {
		this.visibility = (on) ? "show" : "hide";
		if (bkeepHilite && this.currentItem) { this.currentItem.bgColor = this.backColour; this.currentItem.fgColor = this.FontColour; }}
	else {
		this.style.visibility = (on) ? "visible" : "hidden";
		if (bkeepHilite && this.currentItem) {
			with (this.currentItem.style) {
				backgroundColor = this.backColour;
				color = this.FontColour; }}}
	this.currentItem = null;
}

function keepInWindow() {
	scrBars = 20;
	botScrBar = scrBars;
	rtScrBar = scrBars;
	if (NN4) {
		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();
	setTimeout("if(!boverTitleImage && !bOverMenu) {MenuOut1(sMenuImageName);}",mSecsVis);
}

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 }

function GetMenuArrayIndex(menuCount) {
	var menuIndex = 0;
	if(isNaN(menuCount)){
    		menuIndex = menuCount.slice(0, menuCount.indexOf('_'))
    	}
    	else
    	{
    		menuIndex = menuCount;
    	}
    	return menuIndex;
}

function GetImageHTML(menuCount) {
	var iMenuIndex = GetMenuArrayIndex(menuCount) - 1
	if (sImageURL[iMenuIndex] == '') {
		return '';
	}
	else {
		iImageSpan = (IE4) ? iImageSize : iImageSize + 12;
		sImageHTML = ''
		sImageHTML = "<SPAN STYLE='width:" + iImageSpan + ";height:100%;float:right'>";
		sMenuImageURL = sImageURL[iMenuIndex]
		if(sMenuImageURL != '')
   		{
			sImageHTML += "<IMG SRC='" + sMenuImageURL + "' WIDTH=" + iImageSize + " HEIGHT=" + iImageSize + " BORDER=0>";
    		}
		sImageHTML += "</SPAN>";
    		return sImageHTML;
	}
}

function MenuOver(imgName, menuName, e) {
	if(sMenuImageName != '' && sMenuImageName != imgName){
   		if (bMenuImagesLoaded) {  
    			if (document.images) {
    				imgCurrent = eval(sMenuImageName + "out.src");
      				if (document[sMenuImageName].src != imgCurrent) {
          				MenuOut1(sMenuImageName );
      				}
    			}
    		}   	
    	}
	sMenuImageName = imgName
	boverTitleImage  = true;
 	MenuOver2(imgName);  
  	if (bDisplayMenus) {
    		if (bIsLoaded) {
      			if (IE4 || NN4) {Show(menuName, e);}
    		}
  	}
}

function MenuOut(imgName, menuName) {
	if (bkeepTopImage) {
		setTimeout("if(!bOverMenu && !boverTitleImage ) {MenuOut1(sMenuImageName);}",mSecsVis);
	}
	else{
		MenuOut1(imgName);
	}
  	if (bDisplayMenus) {
    		if (bIsLoaded) {
      			if (IE4 || NN4) {Hide(menuName);}
    		}
  	}
  	boverTitleImage  = false;
}

function MenuOver1(imgName) {
  	if (bIsLoaded) {
    		if (IE4 || NN4) {
    			hideAll();
    		}  
  	}
 	MenuOver2(imgName);  
}

function MenuOver2(imgName) {
 	if (bMenuImagesLoaded) {
    		if (document.images) {
      			if (imgName != sMenuTitle) {
    	  			imgChange= eval(imgName + "over.src");
    	  			document[imgName].src= imgChange;
      			}
    		}
  	}
}

function MenuOut1(imgName) {
  	if (bMenuImagesLoaded) {  
    		if (document.images) {
      			if (imgName != sMenuTitle) {
          			imgChange= eval(imgName + "out.src");
          			document[imgName].src= imgChange;
      			}
    		}
    	}
}