function StringBuffer() {

this.data = new Array();

var i=0;

this.append = function(str) {

	this.data[i++] = str

	}

this.empty = function() {

	this.data.length = 0;

	}

this.toString = function() {

	return this.data.join("");

	}

}

var hasPageLoaded = 0;

var selectBoxFixIE;

var all_menus = new Array();

var all_menus_load = new Array();

var all_menus_count = 0;

var font_colour = "";

var font_over_colour = "";

var background_colour = "";

var background_over_colour = "";

var main_background_colour = "#eeeeee";

var font_family

var styleText = "Selectors: \n";

var ie4bugfix=0;

if (document.styleSheets && document.styleSheets.rules) {

    var oStyleSheet=document.styleSheets[0];

    var oRule=oStyleSheet.rules[2];

    for (i=0;i<oStyleSheet.rules.length;i++) {

        styleText = styleText + oStyleSheet.rules[i].selectorText + "\n";

	    if (oStyleSheet.rules[i].selectorText == "DIV.clsMenu A") {

		    if (ie4bugfix==0) {

			    font_colour = oStyleSheet.rules[i].style.color;

			    ie4bugfix = 1;

		    }

	    }

	    if (oStyleSheet.rules[i].selectorText == "DIV.clsMenu") {	

		    main_background_colour = oStyleSheet.rules[i].style.color;

	    }

	    if (oStyleSheet.rules[i].selectorText == "DIV.clsMenu A:hover") {

		    font_over_colour =  oStyleSheet.rules[i].style.color;

		    background_over_colour = oStyleSheet.rules[i].style.backgroundColor;

	    }

	    if (oStyleSheet.rules[i].selectorText == ".dynamicMenuItemStyle") {

            font_colour = oStyleSheet.rules[i].style.color;

            background_colour = oStyleSheet.rules[i].style.backgroundColor;

            font_family = oStyleSheet.rules[i].style.fontFamily;

	    }

	    if (oStyleSheet.rules[i].selectorText == ".dynamicMenuItemOverStyle") {

            font_over_colour = oStyleSheet.rules[i].style.color;

            background_over_colour = oStyleSheet.rules[i].style.backgroundColor;

            font_family = oStyleSheet.rules[i].style.fontFamily;

	    }

    }



}

function selectBoxFixIE_hide() {

	if (document.all) {

		for (var i=0;i<selectBoxFixIE.length;i++) {

			if (i!=0) {

			selectBoxFixIE[i].style.visibility="hidden";

			}

		}

	}

}

var getElementById_recHolder;

function get_id(id) {

	if (document.all) return document.all[id];

		else if (document.layers) {

		getElementById_recHolder = null;

		layers_rec(document.layers,id);

		var oNesLayer = getElementById_recHolder;

			if (oNesLayer != null) {

			oNesLayer.style = oNesLayer;

			return oNesLayer.style;

			}

			else {

			return null;

			}

		}

}

function layers_rec(doc,id) {

	for ( var x = 0; x < doc.length; x++ ) {

			if (doc[x].document.layers.length > 0) layers_rec(doc[x].document.layers,id);

			if (doc[x].id == (doc[id] ? doc[id].id : null)) {

			getElementById_recHolder = doc[x];

			}

	}

}

if (!document.getElementById) document.getElementById=get_id;



function getDim(el){

	if (!document.layers) {

		for (var lx=0,ly=0;el!=null;

			lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);

		return {x:lx,y:ly}

	}

	else {

	return {x:el.pageX,y:el.pageY}

	}

}

var find_nes_layers_array = new Array();

function find_nes_layers(doc) {

	for ( var x = 0; x < doc.length; x++ ) {

		if (doc[x].document.layers.length > 0) find_nes_layers(doc[x].document.layers);

		if (doc[x].id.match(/nsdynamicmenu_gid\d+/i)) {

			find_nes_layers_array[find_nes_layers_array.length] = doc[x];

		}

	}

}

function write_dynamic_menu(gid,desc,width,owidth,height,linkRef) {

var o = new StringBuffer();

o.append("<div id='dynamicmenu_gid");

o.append(gid);

o.append("' style='position:relative;width:100%; height: ");

o.append(height);

o.append(";' ");

o.append("onMouseOver='dynamic_menu_over(this,window.all_menus[thismenu_gid");

o.append(gid);

o.append("],");

o.append(owidth);

o.append(");' ");

o.append("onMouseOut='dynamic_menu_out(this,thismenu_gid");

o.append(gid);

o.append(");FW_startTimeout();' ");

o.append("onClick='");

o.append(linkRef);

o.append("'>");

o.append("<div id='dynamicMenuStart_gid");

o.append(gid);

o.append("' class='dynamicMenuStart' style='position:absolute; top:0; left:0; ");

o.append("width: 100%; height: ");

o.append(height);

o.append("; visibility: visible;'>");

o.append("<img src='images/arrows.gif' alt='' width='8' height='8' border='0' align='right' style='margin-top: 3px;'>");

o.append(desc);

o.append("</div>");

o.append("<div id='dynamicMenuOver_gid");

o.append(gid);

o.append("' class='dynamicMenuOver' style='position:absolute; top:0; left:0; ");

o.append("width: 100%; height: ");

o.append(height);

o.append("; visibility: hidden;'>");

o.append("<img src='images/arrows.gif' alt='' width='8' height='8' border='0' align='right' style='margin-top: 3px;'>");

o.append(desc);

o.append("</div>");

o.append("</div>");

document.write(o.toString());

}

function dynamic_menu_over(e,menuref,containerOffset) {

if (hasPageLoaded == 0) return false;

var arrayRef = e.id.match(/_gid(.*)/i)[0]

if (!menuref.loaded) {

writeMenus(menuCont,menuref);

}

var menu_start;

var menu_over;

var elementRef = e.id.match(/_gid(\d*)_?(\d*)/i)[0];

var oElement = e;

var getPos = getDim(oElement);

selectBoxFixIE_hide();

	if (!document.layers) {

	menu_start=document.getElementById("dynamicMenuStart" + elementRef);

	menu_over=document.getElementById("dynamicMenuOver" + elementRef);

	menu_start.style.visibility = "hidden";

	menu_over.style.visibility = "visible";

	containerOffset=oElement.offsetWidth;

	}

	window.FW_showMenu(menuref,getPos.x+containerOffset,getPos.y+0);

}

function dynamic_menu_out(e) {

if (hasPageLoaded == 0) return false;

var elementRef = e.id.match(/_gid(\d*)_?(\d*)/i)[0];

var oElement = e;

	if (!document.layers) {

	menu_start=document.getElementById("dynamicMenuStart" + elementRef);

	menu_over=document.getElementById("dynamicMenuOver" + elementRef);

	menu_start.style.visibility = "visible";

	menu_over.style.visibility = "hidden";

	}

}

function dynamic_menu_startup() {

hasPageLoaded = 1;

	if (document.all) {

	selectBoxFixIE = document.all.tags("select");

	}

	if (document.layers) {

	find_nes_layers(document.layers);

		for (var i=0;i<find_nes_layers_array.length;i++) {

		find_nes_layers_array[i].captureEvents(Event.MOUSEOVER|Event.MOUSEOUT);

		}

	}

}

function Menu(label, mw, mh, fnt, fs, fclr, fhclr, bg, bgh) {

	this.version = "990702 [Menu; menu.js]";

	this.type = "Menu";

	this.menuWidth = mw;

	this.menuItemHeight = mh;

	this.fontSize = fs||12;

	this.fontWeight = "plain";

	this.fontFamily = fnt||"arial,helvetica,verdana,sans-serif";

	this.fontColor = fclr||"#000000";

	this.fontColorHilite = fhclr||"#ffffff";

	this.bgColor = "#555555";

	this.menuBorder = 1;

	this.menuItemBorder = 1;

	this.menuItemBgColor = bg||"#cccccc";

	this.menuLiteBgColor = "#ffffff";

	this.menuBorderBgColor = "#777777";

	this.menuHiliteBgColor = bgh||"#000084";

	this.menuContainerBgColor = "#cccccc";

	this.childMenuIcon = "../../arrows.gif";

	this.items = new Array();

	this.actions = new Array();

	this.childMenus = new Array();



	this.hideOnMouseOut = true;



	this.addMenuItem = addMenuItem;

	this.addMenuSeparator = addMenuSeparator;

	this.writeMenus = writeMenus;

	this.FW_showMenu = FW_showMenu;

	this.onMenuItemOver = onMenuItemOver;

	this.onMenuItemAction = onMenuItemAction;

	this.hideMenu = hideMenu;

	this.hideChildMenu = hideChildMenu;



	if (!window.menus) window.menus = new Array();

	this.label = label || "menuLabel" + window.menus.length;

	window.menus[this.label] = this;

	window.menus[window.menus.length] = this;

	if (!window.activeMenus) window.activeMenus = new Array();

}



function addMenuItem(label, action) {

	this.items[this.items.length] = label;

	this.actions[this.actions.length] = action;

}



function addMenuSeparator() {

	this.items[this.items.length] = "separator";

	this.actions[this.actions.length] = "";

	this.menuItemBorder = 0;

}

function FIND(item) {

	if (document.all) return(document.all[item]);

	if (document.getElementById) return(document.getElementById(item));

	return(false);

}

function preWrite(container) {

window.fwWroteMenu = false

	if (document.captureEvents) {	

		document.captureEvents(Event.MOUSEUP);

	}

	if (document.addEventListener) {	

		document.addEventListener("mouseup", onMenuItemOver, false);

	}

	if (document.layers && window.innerWidth) {

		window.onresize = NS4resize;

		window.NS4sIW = window.innerWidth;

		window.NS4sIH = window.innerHeight;

	}

	document.onmouseup = mouseupMenu;

	container.isContainer = true;

	container.menus = new Array();

	container.menus = window.menus;

	container.innerHTML=content.toString();

	content = null;

	delete content;

}

function writeMenus(container,mRef) {

	if (!container) return;	

	window.fwHideMenuTimer = null;

		if (!FIND("menuLayer0")) return;

		var menuCount = mRef.totalMenuItems;

		for (var x=mRef.labelStart; x<mRef.labelEnd+1; x++) {

			var menuLayer = FIND("menuLayer" + x);

			container.menus[x].menuLayer = "menuLayer" + x;

			menuLayer.Menu = container.menus[x];

			menuLayer.Menu.container = "menuLayer" + x;

			menuLayer.style.zIndex = 1;

		    var s = menuLayer.style;

			s.top = s.pixelTop = -300;

			s.left = s.pixelLeft = -300;

			var menu = container.menus[x];

			menu.menuItemWidth = menu.menuWidth || menu.menuIEWidth || 140;

			var top = 0;

			for (var i=0; i<container.menus[x].items.length; i++) {

				var l = FIND("menuItem" + menuCount);

				l.Menu = container.menus[x];

				l.style.pixelWidth = menu.menuItemWidth;	

				l.style.pixelHeight = menu.menuItemHeight;

				l.style.pixelTop = top;

				top = top + menu.menuItemHeight+menu.menuItemBorder;

				l.style.fontSize = menu.fontSize;

		                l.style.fontFamily = font_family;

				l.style.backgroundColor = menu.menuItemBgColor;

				l.style.visibility = "inherit";

				l.saveColor = menu.menuItemBgColor;

				l.menuHiliteBgColor = menu.menuHiliteBgColor;

				l.action = container.menus[x].actions[i];

				l.hilite = FIND("menuItemHilite" + menuCount);

				l.focusItem = FIND("focusItem" + x);

				l.focusItem.style.pixelTop = l.focusItem.style.top = -30;

				var childItem = FIND("childMenu" + menuCount);

				if (childItem) {

					l.childMenu = container.menus[x].items[i].menuLayer;

					childItem.style.pixelLeft = childItem.style.left = menu.menuItemWidth -11;

					childItem.style.pixelTop = childItem.style.top =(menu.menuItemHeight /2) -4;

					l.Menu.childMenus[l.Menu.childMenus.length] = l.childMenu;

				}

				var sep = FIND("menuSeparator" + menuCount);

				if (sep) {

					sep.style.clip = "rect(0 " + (menu.menuItemWidth - 3) + " 1 0)";

					sep.style.width = sep.style.pixelWidth = menu.menuItemWidth;	

					sep.style.backgroundColor = menu.bgColor;

					sep = FIND("menuSeparatorLite" + menuCount);

					sep.style.clip = "rect(1 " + (menu.menuItemWidth - 3) + " 2 0)";

					sep.style.width = sep.style.pixelWidth = menu.menuItemWidth;	

					sep.style.backgroundColor = menu.menuLiteBgColor;

					l.style.height = l.style.pixelHeight = menu.menuItemHeight/2;

					l.isSeparator = true

					top -= (menu.menuItemHeight - l.style.pixelHeight)

				} else {

					l.style.cursor = "hand"

				}

				menuCount++;

			}

			menu.menuHeight = top-1;

			var lite = FIND("menuLite" + x);

			var s = lite.style;

			s.height = s.pixelHeight = menu.menuHeight +(menu.menuBorder * 2);

			s.width = s.pixelWidth = menu.menuItemWidth + (menu.menuBorder * 2);

			s.backgroundColor = menu.menuLiteBgColor;



			var body = FIND("menuFg" + x);

			s = body.style;

			s.height = s.pixelHeight = menu.menuHeight + menu.menuBorder;

			s.width = s.pixelWidth = menu.menuItemWidth + menu.menuBorder;

			s.backgroundColor = menu.bgColor;



			s = menuLayer.style;

			s.width = s.pixelWidth  = menu.menuItemWidth + (menu.menuBorder * 4);

			s.height = s.pixelHeight  = menu.menuHeight+(menu.menuBorder*4);

		}

		window.fwWroteMenu = true;

		status = "";

		mRef.loaded = true;

}

function NS4resize() {

	if (NS4sIW < window.innerWidth || 

		NS4sIW > window.innerWidth || 

		NS4sIH > window.innerHeight || 

		NS4sIH < window.innerHeight ) 

	{

		window.location.reload();

	}

}

function onMenuItemOver(e, l) {

	FW_clearTimeout();

	l = l || this;

	a = window.ActiveMenuItem;

	if (document.layers) {

		if (a) {

			a.document.bgColor = a.saveColor;

			if (a.hilite) a.hilite.visibility = "hidden";

			if (a.Menu.bgImageOver) {

				a.background.src = a.Menu.bgImageUp;

			}

			a.focusItem.top = -100;

			a.clicked = false;

		}

		if (l.hilite) {

			l.document.bgColor = l.menuHiliteBgColor;

			l.zIndex = 1;

			l.hilite.visibility = "inherit";

			l.hilite.zIndex = 2;

			l.document.layers[1].zIndex = 1;

			l.focusItem.zIndex = this.zIndex +2;

		}

		if (l.Menu.bgImageOver) {

			l.background.src = l.Menu.bgImageOver;

		}

		l.focusItem.top = this.top;

		l.Menu.hideChildMenu(l);

	} else if (l.style && l.Menu) {

		if (a) {

			a.style.backgroundColor = a.saveColor;

			if (a.hilite) a.hilite.style.visibility = "hidden";

			if (a.Menu.bgImageUp) {

				a.style.background = "url(" + a.Menu.bgImageUp +")";;

			}

		} 

		if (l.isSeparator) return;

		l.style.backgroundColor = l.menuHiliteBgColor;

		l.zIndex = 1;  // magic IE 4.5 mac happy doohicky.	jba

		if (l.Menu.bgImageOver) {

			l.style.background = "url(" + l.Menu.bgImageOver +")";

		}

		if (l.hilite) {

			l.style.backgroundColor = l.menuHiliteBgColor;

			l.hilite.style.visibility = "inherit";

		}

		l.focusItem.style.top = l.focusItem.style.pixelTop = l.style.pixelTop;

		l.focusItem.style.zIndex = l.zIndex +1;

		l.Menu.hideChildMenu(l);

	} else {

		return; // not a menu - magic IE 4.5 mac happy doohicky.  jba

	}

	window.ActiveMenuItem = l;

}

function onMenuItemAction(e, l) {

	l = window.ActiveMenuItem;

	if (!l) return;

	hideActiveMenus();

	if (l.action) {

		eval("" + l.action);

	}

	window.ActiveMenuItem = 0;

}

function FW_clearTimeout()

{

	if (fwHideMenuTimer) clearTimeout(fwHideMenuTimer);

	fwHideMenuTimer = null;

	fwDHFlag = false;

}

function FW_startTimeout()

{

	fwStart = new Date();

	fwDHFlag = true;

	fwHideMenuTimer = setTimeout("fwDoHide()", 1000);

}

function fwDoHide()

{

	if (!fwDHFlag) return;

	var elapsed = new Date() - fwStart;

	if (elapsed < 1000) {

		fwHideMenuTimer = setTimeout("fwDoHide()", 1100-elapsed);

		return;

	}

	fwDHFlag = false;

	//start ie select bug fix mark edwards 06/12/2001;

	//show all hidden select box's

	if (!document.layers) {

	var selectBoxFixIE = document.all.tags("select")

	for (var i=0;i<selectBoxFixIE.length;i++) {



	selectBoxFixIE[i].style.visibility="visible";



	}

	}

	//end ie select bug fix

	hideActiveMenus();



	window.ActiveMenuItem = 0;

}

function FW_showMenu(menu, x, y, child) {

	if (!window.fwWroteMenu) return;

	FW_clearTimeout();

	if (FIND("menuItem0")) {

		

		var l = menu.menuLayer || menu;	

		//alert(l);

		hideActiveMenus();



		if (typeof(l) == "string") {

			l = FIND(l);

		}

		

		window.ActiveMenu = l;

		

		var s = l.style;

		s.visibility = "inherit";

		

		if (x != "relative") 

			s.left = s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;

		if (y != "relative") 

			s.top = s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;

		l.Menu.xOffset = document.body.scrollLeft;

		l.Menu.yOffset = document.body.scrollTop;

	}

	

	if (menu) {

		window.activeMenus[window.activeMenus.length] = l;

	}

}

function onMenuItemDown(e, l) {

	var a = window.ActiveMenuItem;

	if (document.layers) {

		if (a) {

			a.eX = e.pageX;

			a.eY = e.pageY;

			a.clicked = true;

		}

    }

}

function mouseupMenu(e)

{

	hideMenu(true, e);

	hideActiveMenus();

	return true;

}

function getExplorerVersion()

{

	var ieVers = parseFloat(navigator.appVersion);

	if( navigator.appName != 'Microsoft Internet Explorer' )

		return ieVers;

	var tempVers = navigator.appVersion;

	var i = tempVers.indexOf( 'MSIE ' );

	if( i >= 0 ) {

		tempVers = tempVers.substring( i+5 );

		ieVers = parseFloat( tempVers ); 

	}

	return ieVers;

}



function mouseoutMenu()

{

	if ((navigator.appName == "Microsoft Internet Explorer")

		&& (getExplorerVersion() < 4.5))

		return true;

	hideMenu(false, false);

	return true;

}

function hideMenu(mouseup, e) {

	var a = window.ActiveMenuItem;

	if (a && document.layers) {

		a.document.bgColor = a.saveColor;

		a.focusItem.top = -30;

		if (a.hilite) a.hilite.visibility = "hidden";

		if (mouseup && a.action && a.clicked && window.ActiveMenu) {

 			if (a.eX <= e.pageX+15 && a.eX >= e.pageX-15 && a.eY <= e.pageY+10 && a.eY >= e.pageY-10) {

				setTimeout('window.ActiveMenu.Menu.onMenuItemAction();', 2);

			}

		}

		a.clicked = false;

		if (a.Menu.bgImageOver) {

			a.background.src = a.Menu.bgImageUp;

		}

	} else if (window.ActiveMenu && FIND("menuItem0")) {

		if (a) {

			a.style.backgroundColor = a.saveColor;

			if (a.hilite) a.hilite.style.visibility = "hidden";

			if (a.Menu.bgImageUp) {

				a.style.background = "url(" + a.Menu.bgImageUp +")";;

			}

		}

	}

	if (!mouseup && window.ActiveMenu) {

		if (window.ActiveMenu.Menu) {

			if (window.ActiveMenu.Menu.hideOnMouseOut) {

				FW_startTimeout();

			}

			return(true);

		}

	}

	return(true);

}



function PxToNum(pxStr)

{ 

	if (pxStr.length > 2) {

		n = Number(pxStr.substr(0, pxStr.length-2));

		return(n);

	}

	return(0);

}

function hideChildMenu(hcmLayer) {

	FW_clearTimeout();

	var l = hcmLayer;

	for (var i=0; i < l.Menu.childMenus.length; i++) {

		var theLayer = l.Menu.childMenus[i];

		if (document.layers) {

			theLayer.visibility = "hidden";

		} else {

			theLayer = FIND(theLayer);

			theLayer.style.visibility = "hidden";

		}

		theLayer.Menu.hideChildMenu(theLayer);

	}



	if (l.childMenu) {

		var childMenu = l.childMenu;

		if (document.layers) {

			l.Menu.FW_showMenu(null,null,null,childMenu.layers[0]);

			childMenu.zIndex = l.parentLayer.zIndex +1;

			childMenu.top = l.top + l.parentLayer.top + l.Menu.menuLayer.top + l.Menu.menuItemHeight/3;

			if (childMenu.left + childMenu.clip.width > window.innerWidth) {

				childMenu.left = l.parentLayer.left - childMenu.clip.width + l.Menu.menuLayer.left + 15;

				l.Menu.container.clip.left -= childMenu.clip.width;

			} else {

				childMenu.left = l.parentLayer.left + l.parentLayer.clip.width  + l.Menu.menuLayer.left -5;

			}

			var w = childMenu.clip.width+childMenu.left-l.Menu.container.clip.left;

			if (w > l.Menu.container.clip.width)  

				l.Menu.container.clip.width = w;

			var h = childMenu.clip.height+childMenu.top-l.Menu.container.clip.top;

			if (h > l.Menu.container.clip.height) l.Menu.container.clip.height = h;

			l.document.layers[1].zIndex = 0;

			childMenu.visibility = "inherit";

		} else if (FIND("menuItem0")) {

			childMenu = FIND(l.childMenu);

			var menuLayer = FIND(l.Menu.menuLayer);

			var s = childMenu.style;

			s.zIndex = menuLayer.style.zIndex+1;

			if (document.all) { // ie case.

				s.pixelTop = l.style.pixelTop + menuLayer.style.pixelTop + l.Menu.menuItemHeight/3;

				s.left = s.pixelLeft = (menuLayer.style.pixelWidth) + menuLayer.style.pixelLeft -5;

			} else { // zilla case

				var top = PxToNum(l.style.top) + PxToNum(menuLayer.style.top) + l.Menu.menuItemHeight/3;

				var left = (PxToNum(menuLayer.style.width)) + PxToNum(menuLayer.style.left) -5;

				s.top = top;

				s.left = left;

			}

			childMenu.style.visibility = "inherit";

		} else {

			return;

		}

		window.activeMenus[window.activeMenus.length] = childMenu;

	}

}

function hideActiveMenus() {

	if (!window.activeMenus) return;

	for (var i=0; i < window.activeMenus.length; i++) {

		if (!activeMenus[i]) continue;

		if (activeMenus[i].visibility && activeMenus[i].Menu) {

			activeMenus[i].visibility = "hidden";

			activeMenus[i].Menu.container.visibility = "hidden";

			activeMenus[i].Menu.container.clip.left = 0;

		} else if (activeMenus[i].style) {

			var s = activeMenus[i].style;

			s.visibility = "hidden";

			s.left = -200;

			s.top = -200;

		}

	}

	if (window.ActiveMenuItem) {

		hideMenu(false, false);

	}

	window.activeMenus.length = 0;

}
