RG_a_Parameters = [
	["MenuWidth",          150,		"number"],
	["FontFamily",         "Arial,sans-serif"],
	["FontSize",           10,		"number"],
	["FontBold",           false,	"boolean"],
	["FontItalic",         false,	"boolean"],
	["FontColor",          "black"],
	["FontColorOver",      "white"],
	["BGColor",            "white"],
	["BGColorOver",        "black"],
	["ItemPadding",        3,		"number"],
	["BorderWidth",        2,		"number"],
	["BorderColor",        "red"],
	["BorderStyle",        "solid"],
	["SeparatorSize",      1,		"number"],
	["SeparatorColor",     "yellow"],
	["ImageSrc",           "RG_More_black_right.gif"],
	["ImageSrcOver",       null],
	["ImageSrcLeft",       "RG_More_black_left.gif"],
	["ImageSrcLeftOver",   null],
	["ImageSize",          5,		"number"],
	["ImageHorizSpace",    0,		"number"],
	["ImageVertSpace",     0,		"number"],
	["KeepHilite",         false,	"boolean"],
	["ClickStart",         false,	"boolean"],
	["ClickKill",          true,	"boolean"],
	["ChildOverlap",       20,		"number"],
	["ChildOffset",        10,		"number"],
	["ChildPerCentOver",   null,	"number"],
	["TopSecondsVisible",  .5,		"number"],
	["ChildSecondsVisible",.3,		"number"],
	["StatusDisplayBuild", 1,		"boolean"],
	["StatusDisplayLink",  1,		"boolean"],
	["UponDisplay",        null,	"delayed"],
	["UponHide",           null,	"delayed"],
	["RightToLeft",        false,	"boolean"],
	["CreateTopOnly",      0,		"boolean"],
	["ShowLinkCursor",     false,	"boolean"]
]

RG_MenuIDPrefix = "RG_Menu";
RG_ItemIDPrefix = "RG_Item";
RG_ArrayIDPrefix = "RG_Array";

Function.prototype.isFunction = true;
Function.prototype.isString = false;
String.prototype.isFunction = false;
String.prototype.isString = true;
String.prototype.isBoolean = false;
String.prototype.isNumber = false;
Number.prototype.isString = false;
Number.prototype.isFunction = false;
Number.prototype.isBoolean = false;
Number.prototype.isNumber = true;
Boolean.prototype.isString = false;
Boolean.prototype.isFunction = false;
Boolean.prototype.isBoolean = true;
Boolean.prototype.isNumber = false;
Array.prototype.itemValidation = false;
Array.prototype.isArray = true;

function RG_f_AssignParameters(paramarray){
	var ParamName = paramarray[0];
	var DefaultValue = paramarray[1];
	var FullParamName = "RG_" + ParamName;

	if (typeof eval("window.RG_PG_" + ParamName) == "undefined") {
		if (typeof eval("window.RG_GL_" + ParamName) == "undefined") {
			eval(FullParamName + "= DefaultValue");
		}
		else {
			eval(FullParamName + "= RG_GL_" + ParamName);
		}
	}
	else {
		eval(FullParamName + "= RG_PG_" + ParamName);
	}

	paramarray[0] = FullParamName;
	paramarray[1] = eval(FullParamName);
}

function RG_f_EvalParameters(valuenew,valueold,valuetype){
	var TestString, ParPosition;

	if(typeof valuenew == "undefined" || valuenew == null || (valuenew.isString && valuenew.length == 0)){
		return valueold;
	}

	if(valuetype != "delayed"){
		while(valuenew.isString) {
			ParPosition = valuenew.indexOf("(");
			if(ParPosition !=-1) {
				TestString = "window." + valuenew.substr(0,ParPosition);
				if (typeof eval(TestString) != "undefined" && eval(TestString).isFunction) {
					valuenew = eval(valuenew);
				}
			}
			else break
		}
	}

	while(valuenew.isFunction) {valuenew = valuenew()}

	switch(valuetype){	
		case "number":
			while (valuenew.isString) {valuenew = eval(valuenew)}
			break;
		case "boolean":
			while (!valuenew.isBoolean) {
				valuenew = (valuenew.isNumber) ? valuenew ? true : false : eval(valuenew);
			}
			break;
	}

	return valuenew;
}

for (i=0;i<RG_a_Parameters.length;i++) {
	RG_f_AssignParameters(RG_a_Parameters[i]);
	eval(RG_a_Parameters[i][0] + "= RG_f_EvalParameters("+ RG_a_Parameters[i][0] +",null,RG_a_Parameters[i][2])")
}

RG_ChildPerCentOver = (isNaN(parseFloat(RG_ChildPerCentOver))) ? null : parseFloat(RG_ChildPerCentOver)/100;

RG_ChildMilliSecondsVisible = RG_ChildSecondsVisible * 1000;

function RG_f_ValidateArray(arrayname){
	var MenuArrayIsValid = false;
	var MenuArrayIsObject = (typeof eval("window." + arrayname) == "object");
	if(MenuArrayIsObject) { 
		var TheMenuArray = eval(arrayname);
		if(TheMenuArray.isArray && TheMenuArray.length > 1) {
			MenuArrayIsValid = true;
			if(!TheMenuArray.itemValidation) {
				while((typeof TheMenuArray[TheMenuArray.length-1] != "object") || (!TheMenuArray[TheMenuArray.length-1].isArray)) {
					TheMenuArray.length--;
				}
				TheMenuArray.itemValidation = true;
			}
		}
	}
	return MenuArrayIsValid;
}

if(!window.RG_a_TreesToBuild) {
	RG_a_TreesToBuild = [];
	for(i=1; i<100; i++){
		if(RG_f_ValidateArray(RG_ArrayIDPrefix + i)) RG_a_TreesToBuild[RG_a_TreesToBuild.length] = i;
	}
}

RG_CurrentArray = null;
RG_CurrentTree  = null;
RG_CurrentMenu  = null;
RG_CurrentItem  = null;
RG_a_TopMenus = [];
RG_AreLoaded = false;
RG_AreCreated = false;
RG_BeingCreated = false;
RG_UserOverMenu = false;
RG_HideAllTimer = null;
RG_TotalTrees = 0; 
RG_ZIndex = 5000;

function propertyTransfer(){
	this.obj = eval(this.id + "Obj");
	for (temp in this.obj) {this[temp] = this.obj[temp]}
}

function RG_f_StartIt() {
	if((typeof(document.body) == "undefined") || (document.body == null)) return;
	if(RG_AreCreated) return;
	RG_AreLoaded = true;
	if (RG_ClickKill) {
		RG_f_OtherMouseDown = (document.onmousedown) ? document.onmousedown : new Function;
    	document.onmousedown = function(){RG_f_PageClick();RG_f_OtherMouseDown()}
    }
	else {
		RG_TopMilliSecondsVisible = RG_TopSecondsVisible * 1000;
	}
    RG_f_MakeTrees();
	RG_f_OtherOnLoad();
}

function RG_f_MakeTrees(){
    RG_BeingCreated = true;
	var TreeParams = null;
	var TreeHasChildren = false;
	var ItemArray = null;

	for(var t=0; t<RG_a_TreesToBuild.length; t++) {
		if(!RG_f_ValidateArray(RG_ArrayIDPrefix + RG_a_TreesToBuild[t])) continue;
		RG_CurrentArray = eval(RG_ArrayIDPrefix + RG_a_TreesToBuild[t]);

		TreeParams = RG_CurrentArray[0];
		TreeHasChildren = false;

		for(var i=1; i<RG_CurrentArray.length; i++) {
			ItemArray = RG_CurrentArray[i];
			if(ItemArray[ItemArray.length-1]) {TreeHasChildren = true; break}
		}

		RG_CurrentTree = {
			MenuWidth        : MenuWidth = RG_f_EvalParameters(TreeParams[0],RG_MenuWidth,"number"),
			MenuLeft         : MenuLeft = RG_f_EvalParameters(TreeParams[1],null,"delayed"),
			MenuTop          : MenuTop = RG_f_EvalParameters(TreeParams[2],null,"delayed"),
			ItemWidth        : MenuWidth - (RG_BorderWidth*2),
			FontColor        : RG_f_EvalParameters(TreeParams[3],RG_FontColor),
			FontColorOver    : RG_f_EvalParameters(TreeParams[4],RG_FontColorOver),
			BGColor          : RG_f_EvalParameters(TreeParams[5],RG_BGColor),
			BGColorOver      : RG_f_EvalParameters(TreeParams[6],RG_BGColorOver),
			BorderColor      : RG_f_EvalParameters(TreeParams[7],RG_BorderColor),
			SeparatorColor   : RG_f_EvalParameters(TreeParams[8],RG_SeparatorColor),
			TopIsPermanent   : ((MenuLeft == null) || (MenuTop == null)) ? false : RG_f_EvalParameters(TreeParams[9],false,"boolean"),
			TopIsHorizontal  : TopIsHorizontal = RG_f_EvalParameters(TreeParams[10],false,"boolean"),
			TreeIsHorizontal : TreeHasChildren ? RG_f_EvalParameters(TreeParams[11],false,"boolean") : false,
			PositionUnder    : (!TopIsHorizontal || !TreeHasChildren) ? false : RG_f_EvalParameters(TreeParams[12],false,"boolean"),
			TopImageShow     : TreeHasChildren ? RG_f_EvalParameters(TreeParams[13],true,"boolean")  : false,
			TreeImageShow    : TreeHasChildren ? RG_f_EvalParameters(TreeParams[14],true,"boolean")  : false,
			UponDisplay      : RG_f_EvalParameters(TreeParams[15],RG_UponDisplay,"delayed"),
			UponHide         : RG_f_EvalParameters(TreeParams[16],RG_UponHide,"delayed"),
			RightToLeft      : RG_f_EvalParameters(TreeParams[17],RG_RightToLeft,"boolean"),
			ClickStart		 : RG_f_EvalParameters(TreeParams[18],RG_ClickStart,"boolean"),
			TopIsVariableWidth  : RG_f_EvalParameters(TreeParams[19],false,"boolean"),
			TreeIsVariableWidth  : RG_f_EvalParameters(TreeParams[20],false,"boolean")
		}

		RG_CurrentMenu = null;
		RG_f_MakeMenu(RG_a_TreesToBuild[t]);
		RG_a_TopMenus[RG_TotalTrees] = RG_CurrentTree.treeParent;
		RG_TotalTrees++;
		if(RG_CurrentTree.TopIsPermanent){
			with(RG_CurrentTree.treeParent) {
				RG_CurrentTree.treeParent.xPos = eval(RG_CurrentTree.MenuLeft);
				RG_CurrentTree.treeParent.yPos = eval(RG_CurrentTree.MenuTop);
				moveTo(RG_CurrentTree.treeParent.xPos,RG_CurrentTree.treeParent.yPos);
				style.zIndex = RG_ZIndex;
				setTimeout(RG_CurrentTree.treeParent.id + ".fixSize(true)",10);
			}
		}
    }

	if(RG_StatusDisplayBuild) status = RG_TotalTrees + " Hierarchical Menu Trees Created";
    RG_AreCreated = true;
    RG_BeingCreated = false;
}

function RG_f_GetItemDivStr(itemid,disptext,hasmore){
	var WidthValue = RG_CurrentMenu.isHorizontal ? (ItemElement.isLastItem) ? (RG_CurrentTree.MenuWidth - RG_BorderWidth - RG_SeparatorSize) : (RG_CurrentTree.MenuWidth - RG_BorderWidth) : RG_CurrentTree.ItemWidth;
	var TempString = "<DIV ID=" + itemid + " STYLE='position:absolute;width:" + WidthValue + "px'>";
	if(RG_CurrentMenu.showImage) {
		var FullPadding  = (RG_ItemPadding*2) + RG_ImageSize + RG_ImageHorizSpace;
	}
    if(hasmore && RG_CurrentMenu.showImage) {
		var ImgSrc      = RG_CurrentTree.RightToLeft ? RG_ImageSrcLeft : RG_ImageSrc;
		var ImgStyle    = "top:"+ (RG_ItemPadding + RG_ImageVertSpace) + "px;width:"+ RG_ImageSize + "px;";
		var ImgString   = "<IMG ID='RG_ImMore' STYLE='position:absolute;"+ ImgStyle +"' SRC='" + ImgSrc + "' HSPACE=0 VSPACE=0 BORDER=0>";
		TempString += ImgString;
	}
	TempString += disptext + "</DIV>";
	return TempString;
}

function RG_f_SetItemProperties(itemid,itemidsuffix) {
	this.tree        = RG_CurrentTree;
	this.itemsetup   = RG_f_ItemSetup;
	this.index       = RG_CurrentMenu.itemCount - 1;
	this.isLastItem  = (RG_CurrentMenu.itemCount == RG_CurrentMenu.maxItems);
	this.array		 = RG_CurrentMenu.array[RG_CurrentMenu.itemCount];
	this.dispText    = this.array[0];
	this.linkText    = this.array[1];
	this.permHilite  = RG_f_EvalParameters(this.array[3],false,"boolean");
	this.hasRollover = (!this.permHilite && RG_f_EvalParameters(this.array[2],true,"boolean"));
	this.hasMore	 = RG_f_EvalParameters(this.array[4],false,"boolean") && RG_f_ValidateArray(RG_ArrayIDPrefix + itemidsuffix);
	this.childID	 = this.hasMore ? (RG_MenuIDPrefix + itemidsuffix) : null;
	this.child		 = null;
    this.onmouseover = RG_f_ItemOver;
    this.onmouseout  = RG_f_ItemOut;
	this.setItemStyle = RG_f_SetItemStyle;
	this.itemStr	 = RG_f_GetItemDivStr(itemid,this.dispText,this.hasMore);
	this.showChild   = RG_f_ShowChild;
	this.ChildOverlap = null;
}

function RG_f_Make4ItemElement(menucount) {
	var ItemIDSuffix = menucount + "_" + RG_CurrentMenu.itemCount;
	var LayerID  = RG_ItemIDPrefix + ItemIDSuffix;
	var ObjectID = LayerID + "Obj";
	eval(ObjectID + " = new Object()");
	ItemElement = eval(ObjectID);
	ItemElement.setItemProperties = RG_f_SetItemProperties;
	ItemElement.setItemProperties(LayerID,ItemIDSuffix);
	return ItemElement;
}

function RG_f_MakeElement(menuid) {
	var MenuObject;
	var LayerID  = menuid;
	var ObjectID = LayerID + "Obj";
	eval(ObjectID + " = new Object()"); 
	MenuObject = eval(ObjectID);
	return MenuObject;
}

function RG_f_MakeMenu(menucount) {
	if(!RG_f_ValidateArray(RG_ArrayIDPrefix + menucount)) return false;
	RG_CurrentArray = eval(RG_ArrayIDPrefix + menucount);
	NewMenu = document.all(RG_MenuIDPrefix + menucount);
	if(!NewMenu) {
		NewMenu = RG_f_MakeElement(RG_MenuIDPrefix + menucount);
		NewMenu.array = RG_CurrentArray;
		NewMenu.tree  = RG_CurrentTree;

		if(RG_CurrentMenu) {
			NewMenu.parentMenu = RG_CurrentMenu;
			NewMenu.parentItem = RG_CurrentMenu.itemElement;
			NewMenu.parentItem.child = NewMenu;
			NewMenu.hasParent = true;
			NewMenu.isHorizontal = RG_CurrentTree.TreeIsHorizontal;
			NewMenu.showImage = RG_CurrentTree.TreeImageShow;
		}
		else {
			NewMenu.isHorizontal = RG_CurrentTree.TopIsHorizontal;
			NewMenu.showImage = RG_CurrentTree.TopImageShow;
		}
	
		RG_CurrentMenu = NewMenu;
		RG_CurrentMenu.itemCount = 0;
		RG_CurrentMenu.maxItems = RG_CurrentMenu.array.length - 1;
		RG_CurrentMenu.showIt = RG_f_ShowIt;
		RG_CurrentMenu.keepInWindow = RG_f_KeepInWindow;
	    RG_CurrentMenu.onmouseover = RG_f_MenuOver;
	    RG_CurrentMenu.onmouseout = RG_f_MenuOut;
	    RG_CurrentMenu.hideTree = RG_f_HideTree
	    RG_CurrentMenu.hideParents = RG_f_HideParents;
	    RG_CurrentMenu.hideChildren = RG_f_HideChildren;
	    RG_CurrentMenu.hideTop = RG_f_HideTop;
	    RG_CurrentMenu.hideSelf = RG_f_HideSelf;
		RG_CurrentMenu.count = menucount;
	    RG_CurrentMenu.hasChildVisible = false;
	    RG_CurrentMenu.isOn = false;
	    RG_CurrentMenu.hideTimer = null;
	    RG_CurrentMenu.currentItem = null;
		RG_CurrentMenu.setMenuStyle = RG_f_SetMenuStyle;
		RG_CurrentMenu.sizeFixed = false;
		RG_CurrentMenu.fixSize = RG_f_FixSize;
		RG_CurrentMenu.onselectstart = RG_f_CancelSelect;
    	RG_CurrentMenu.moveTo = RG_f_MoveTo;
		RG_CurrentMenu.IsVariableWidth = ((RG_CurrentMenu.hasParent && RG_CurrentTree.TreeIsVariableWidth) || (!RG_CurrentMenu.hasParent && RG_CurrentTree.TopIsVariableWidth));
		RG_CurrentMenu.htmlString = "<DIV ID='" + RG_MenuIDPrefix + menucount +"' STYLE='position:absolute;visibility:hidden;width:"+ RG_CurrentTree.MenuWidth +"'>";
	}

	while (RG_CurrentMenu.itemCount < RG_CurrentMenu.maxItems) {
		RG_CurrentMenu.itemCount++;

		RG_CurrentItem = document.all(RG_ItemIDPrefix + menucount + "_" + RG_CurrentMenu.itemCount);
		if(!RG_CurrentItem) {
			if(RG_StatusDisplayBuild) status = "Creating Hierarchical Menus: " + menucount + " / " + RG_CurrentMenu.itemCount;
			RG_CurrentMenu.itemElement = RG_f_Make4ItemElement(menucount);
			RG_CurrentMenu.htmlString += RG_CurrentMenu.itemElement.itemStr;
		}
		if(RG_CurrentMenu.itemElement.hasMore && (!RG_CreateTopOnly || RG_AreCreated && RG_CreateTopOnly)) {
	        MenuCreated = RG_f_MakeMenu(menucount + "_" + RG_CurrentMenu.itemCount);
            if(MenuCreated) {
				RG_CurrentMenu = RG_CurrentMenu.parentMenu;
			}
        }
    }

	document.body.insertAdjacentHTML("BeforeEnd",RG_CurrentMenu.htmlString + "</DIV>");
	menuLyr = document.all(RG_MenuIDPrefix + menucount);
	menuLyr.propertyTransfer = propertyTransfer;
	menuLyr.propertyTransfer();
	RG_CurrentMenu = menuLyr;
	if(!RG_CurrentMenu.hasParent)RG_CurrentTree.treeParent = RG_CurrentTree.startChild = RG_CurrentMenu;
	RG_CurrentMenu.setMenuStyle();
    RG_CurrentMenu.items = RG_CurrentMenu.children;
	RG_CurrentMenu.lastItem = RG_CurrentMenu.items[RG_CurrentMenu.items.length-1];
    for(var i=0; i<RG_CurrentMenu.items.length; i++) {
        it = RG_CurrentMenu.items[i];
		it.siblingBelow = i>0 ? RG_CurrentMenu.items[i-1] : null;
		it.propertyTransfer = propertyTransfer;
		it.propertyTransfer();
		it.itemsetup(i+1);
	}
	RG_CurrentMenu.moveTo(0,0);
	return RG_CurrentMenu;
}

function RG_f_SetMenuStyle(){
	with(this.style) {
		borderWidth = RG_BorderWidth + "px";
		borderColor = RG_CurrentTree.BorderColor;
		borderStyle = RG_BorderStyle;
		overflow    = "hidden";
		cursor      = "default";
	}
}

function RG_f_SetItemStyle() {
	with(this.style){
		backgroundColor = (this.permHilite) ? RG_CurrentTree.BGColorOver : RG_CurrentTree.BGColor;
		color		= (this.permHilite) ? RG_CurrentTree.FontColorOver : RG_CurrentTree.FontColor;
		font		= ((RG_FontBold) ? "bold " : "normal ") + RG_FontSize + "pt " + RG_FontFamily;
		padding		= RG_ItemPadding + "px";
		fontStyle	= (RG_FontItalic) ? "italic" : "normal";
		overflow	= "hidden";
		pixelWidth	= RG_CurrentTree.ItemWidth;

		if((this.menu.showImage && (!this.menu.IsVariableWidth || (this.menu.IsVariableWidth && this.tree.RightToLeft && !this.menu.isHorizontal))) || (this.menu.IsVariableWidth && this.imgLyr)) {

			var FullPadding  = (RG_ItemPadding*2) + RG_ImageSize + RG_ImageHorizSpace;
			if (this.tree.RightToLeft) paddingLeft = FullPadding + "px";
			else paddingRight = FullPadding + "px";
		}
		if(!this.isLastItem) {
			var SeparatorString = RG_SeparatorSize + "px solid " + this.tree.SeparatorColor;
			if (this.menu.isHorizontal) borderRight = SeparatorString;
			else borderBottom = SeparatorString;
		}

		if(this.menu.isHorizontal){
			pixelTop = 0;
			if(this.menu.IsVariableWidth) {
				this.realWidth = this.scrollWidth;
				if(this.isLastItem) pixelWidth = this.realWidth;
				else pixelWidth = (this.realWidth + RG_SeparatorSize);
				pixelLeft = this.index ? (this.siblingBelow.style.pixelLeft + this.siblingBelow.style.pixelWidth) : 0;
				if(this.isLastItem) {
					LeftAndWidth = pixelLeft + pixelWidth;
					this.menu.style.pixelWidth = LeftAndWidth + (RG_BorderWidth * 2);
				}

			}
			else {
				if(this.isLastItem) pixelWidth = (RG_CurrentTree.MenuWidth - RG_BorderWidth - RG_SeparatorSize);
				else pixelWidth = (RG_CurrentTree.MenuWidth - RG_BorderWidth);
				pixelLeft = (this.index * (RG_CurrentTree.MenuWidth - RG_BorderWidth));
				var LeftAndWidth = pixelLeft + pixelWidth;
				this.menu.style.pixelWidth = LeftAndWidth + (RG_BorderWidth * 2);
			}
		}
		else {
			pixelLeft = 0;
		}
	}
}

function RG_f_FixSize(makevis){
	if(this.isHorizontal) {
		var MaxItemHeight = 0;
	    for(i=0; i<this.items.length; i++) {
	        var TempItem = this.items[i];
		    if (TempItem.index) {
				var SiblingHeight = TempItem.siblingBelow.scrollHeight;
				MaxItemHeight = Math.max(MaxItemHeight,SiblingHeight);
			}
	       	else{
				MaxItemHeight = TempItem.scrollHeight;
			}
		}
	    for(i=0; i<this.items.length; i++) {
	        var TempItem = this.items[i];
			TempItem.style.pixelHeight = MaxItemHeight;
			if(TempItem.imgLyr) {
				if(this.tree.RightToLeft){
					TempItem.imgLyr.style.pixelLeft = (RG_ItemPadding + RG_ImageHorizSpace);
				}
				else {
					TempItem.imgLyr.style.pixelLeft = TempItem.style.pixelWidth - ((TempItem.isLastItem ? 0 : RG_SeparatorSize) + RG_ItemPadding + RG_ImageHorizSpace + RG_ImageSize);
				}
			}
		}
		this.style.pixelHeight = MaxItemHeight + (RG_BorderWidth * 2);
	}
	else {
		if(this.IsVariableWidth) {
			var MaxItemWidth = 0;
	    	for(i=0; i<this.items.length; i++) {
	        	var TempItem = this.items[i];
				TempItem.style.pixelWidth = TempItem.scrollWidth;
				MaxItemWidth = i ? Math.max(MaxItemWidth,TempItem.style.pixelWidth) : TempItem.style.pixelWidth;
			}
	    	for(i=0; i<this.items.length; i++) {
				this.items[i].style.pixelWidth = MaxItemWidth;
			}
			this.style.pixelWidth = MaxItemWidth + (RG_BorderWidth * 2);
		}
	    for(i=0; i<this.items.length; i++) {
	        var TempItem = this.items[i];
		    if (TempItem.index) {
				var SiblingHeight =(TempItem.siblingBelow.scrollHeight + RG_SeparatorSize);
				TempItem.style.pixelTop = TempItem.siblingBelow.style.pixelTop + SiblingHeight;
			}
			else TempItem.style.pixelTop = 0;
			if(TempItem.imgLyr) {
				if(RG_CurrentTree.RightToLeft){
					TempItem.imgLyr.style.pixelLeft = (RG_ItemPadding + RG_ImageHorizSpace);
				}
				else {
					TempItem.imgLyr.style.pixelLeft = TempItem.style.pixelWidth - (RG_ItemPadding + RG_ImageHorizSpace + RG_ImageSize);
				}
			}
		}
		this.style.pixelHeight = TempItem.style.pixelTop + TempItem.scrollHeight + (RG_BorderWidth * 2);
	}
	this.sizeFixed = true;
	if(makevis)this.style.visibility = "visible";
}

function RG_f_ItemSetup(whichItem) {
    this.menu = this.parentElement;
	this.ClickStart = this.hasMore && this.tree.ClickStart && (this.tree.TopIsPermanent && (this.tree.treeParent==this.menu));
	if(this.ClickStart) {
		this.linkText = "";
		this.onclick = this.showChild;
	}

    if (this.hasMore) {
		if(this.menu.showImage){
			this.imgLyr = this.children("RG_ImMore");
			this.hasImageRollover = ((!this.tree.RightToLeft && RG_ImageSrcOver) || (this.tree.RightToLeft && RG_ImageSrcLeftOver));
			if(this.hasImageRollover) {
				this.imageSrc = this.tree.RightToLeft ? RG_ImageSrcLeft : RG_ImageSrc;
				this.imageSrcOver = this.tree.RightToLeft ? RG_ImageSrcLeftOver : RG_ImageSrcOver;
				if(this.permHilite) this.imgLyr.src = this.imageSrcOver;
			}
		}

        this.child = document.all(this.childID);
        if(this.child) {
			this.child.parentMenu = this.menu;
        	this.child.parentItem = this;
		}
    }
	if(this.linkText && !this.ClickStart) {
		this.onclick = RG_f_LinkIt;
		if(RG_ShowLinkCursor)this.style.cursor = "hand";
	}

	this.setItemStyle();
}

function RG_f_PopUp(menuname){
    if (!RG_AreLoaded) return;
	menuname = menuname.replace("elMenu",RG_MenuIDPrefix);
	var TempMenu = document.all(menuname);
	if(!TempMenu) return;
	RG_CurrentMenu = TempMenu;
	if (RG_CurrentMenu.tree.ClickStart) {
		var ClickElement = event.srcElement;
		ClickElement.onclick = RG_f_PopMenu;
    }
	else RG_f_PopMenu();
}

function RG_f_PopMenu(){
    if (!RG_AreLoaded || !RG_AreCreated) return true;
    if (RG_CurrentMenu.tree.ClickStart && event.type != "click") return true;
	var mouse_x_position, mouse_y_position;
    RG_f_HideAll();
    RG_CurrentMenu.hasParent = false;
	RG_CurrentMenu.tree.startChild = RG_CurrentMenu;
	RG_CurrentMenu.mouseX = mouse_x_position = (event.clientX + document.body.scrollLeft);
	RG_CurrentMenu.mouseY = mouse_y_position = (event.clientY + document.body.scrollTop);
	RG_CurrentMenu.xIntended = RG_CurrentMenu.xPos = (RG_CurrentMenu.tree.MenuLeft!=null) ? eval(RG_CurrentMenu.tree.MenuLeft) : mouse_x_position;
	RG_CurrentMenu.yIntended = RG_CurrentMenu.yPos = (RG_CurrentMenu.tree.MenuTop!=null)  ? eval(RG_CurrentMenu.tree.MenuTop)  : mouse_y_position;
	if(!RG_CurrentMenu.sizeFixed) RG_CurrentMenu.fixSize(false);
    RG_CurrentMenu.keepInWindow();
    RG_CurrentMenu.moveTo(RG_CurrentMenu.xPos,RG_CurrentMenu.yPos);
    RG_CurrentMenu.isOn = true;
    RG_CurrentMenu.showIt(true);
    return false;
}

function RG_f_MenuOver() {
	if(!this.tree.startChild){this.tree.startChild = this}
	if(this.tree.startChild == this) RG_f_HideAll(this)
    this.isOn = true;
    RG_UserOverMenu = true;
    RG_CurrentMenu = this;
    if (this.hideTimer) clearTimeout(this.hideTimer);
}

function RG_f_MenuOut() {
	if(event.srcElement.contains(event.toElement)) return;
    this.isOn = false;
    RG_UserOverMenu = false;
    if(RG_StatusDisplayLink) status = "";
	if(!RG_ClickKill) {
		clearTimeout(RG_HideAllTimer);
		RG_HideAllTimer = null;
		RG_HideAllTimer = setTimeout("RG_CurrentMenu.hideTree()",RG_ChildMilliSecondsVisible);
	}
}

function RG_f_ShowChild(){
	if(!this.child) {
		RG_CurrentTree = this.tree;
		RG_CurrentMenu = this.menu;
		RG_CurrentItem = this;
		this.child = RG_f_MakeMenu(this.menu.count + "_"+(this.index+1));
		this.tree.treeParent = this.menu;
		this.tree.startChild = this.menu;
       	this.child.parentItem = this;
	}

	if(!this.child.sizeFixed) this.child.fixSize(false);

	if (this.tree.PositionUnder && (this.menu == this.tree.treeParent)) {
		this.child.xPos = this.menu.style.pixelLeft + this.style.pixelLeft;
		this.child.yPos = this.menu.style.pixelTop + this.menu.offsetHeight - (RG_BorderWidth);
	}
	else {
		if(this.ChildOverlap==null) {
			this.DistanceToRightEdge = this.style.pixelWidth;
			if (!this.menu.isHorizontal || (this.menu.isHorizontal && this.isLastItem)) this.DistanceToRightEdge += RG_BorderWidth;
			this.DistanceToLeftEdge = (!this.menu.isHorizontal || (this.menu.isHorizontal && this.index==0)) ? RG_BorderWidth : RG_SeparatorSize;
			this.ChildOverlap = (parseInt((RG_ChildPerCentOver != null) ? (RG_ChildPerCentOver  * this.DistanceToRightEdge) : RG_ChildOverlap));
		}

		this.oL = this.menu.style.pixelLeft + this.offsetLeft + RG_BorderWidth;
		this.oT = this.menu.style.pixelTop  + this.offsetTop;
		if(this.tree.RightToLeft) {
			this.child.xPos = ((this.oL - this.DistanceToLeftEdge) + this.ChildOverlap) - this.child.style.pixelWidth;
		}
		else {		
			this.child.xPos = (this.oL + this.DistanceToRightEdge) - this.ChildOverlap;
		}
		this.child.yPos = this.oT + RG_ChildOffset + RG_BorderWidth;
	}
	this.child.xDiff = this.child.xPos - this.menu.style.pixelLeft;
	this.child.yDiff = this.child.yPos - this.menu.style.pixelTop;
	if(!this.tree.PositionUnder || this.menu!=this.tree.treeParent) this.child.keepInWindow();
	this.child.moveTo(this.child.xPos,this.child.yPos);
	this.menu.hasChildVisible = true;
	this.menu.visibleChild = this.child;
	this.child.showIt(true);
}

function RG_f_ItemOver(){
    if (RG_KeepHilite) {
        if (this.menu.currentItem && this.menu.currentItem != this && this.menu.currentItem.hasRollover) {
            with(this.menu.currentItem.style){
				backgroundColor = this.tree.BGColor;
            	color = this.tree.FontColor
			}
			if(this.menu.currentItem.hasImageRollover)this.menu.currentItem.imgLyr.src = this.menu.currentItem.imageSrc;
        }
    }
	if(event.srcElement.id == "RG_ImMore") return;
	if(this.hasRollover) {
		this.style.backgroundColor = this.tree.BGColorOver;
		this.style.color = this.tree.FontColorOver;
		if(this.hasImageRollover)this.imgLyr.src = this.imageSrcOver;
	}
    if(RG_StatusDisplayLink) status = this.linkText;
    this.menu.currentItem = this;
	if (this.menu.hasChildVisible) {
		if(this.menu.visibleChild == this.child && this.menu.visibleChild.hasChildVisible) this.menu.visibleChild.hideChildren(this);
		else this.menu.hideChildren(this);
    }
    if (this.hasMore && !this.ClickStart) this.showChild();
}

function RG_f_ItemOut() {
	if (event.srcElement.contains(event.toElement)
	  || (event.fromElement.tagName=="IMG" && (event.toElement && event.toElement.contains(event.fromElement))))
		  return;
    if ( (!RG_KeepHilite || ((this.tree.TopIsPermanent && (this.tree.treeParent==this)) && !this.menu.hasChildVisible)) && this.hasRollover) {
		with(this.style) {
			backgroundColor = this.tree.BGColor;
			color = this.tree.FontColor
		}
		if(this.hasImageRollover)this.imgLyr.src = this.imageSrc;

    }
}

function RG_f_MoveTo(xPos,yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

function RG_f_ShowIt(on) {
	if (!(this.tree.TopIsPermanent && (this.tree.treeParent==this))) {
		if(!this.hasParent || (this.hasParent && this.tree.TopIsPermanent && (this.tree.treeParent==this.parentMenu))) {
			var IsVisible = (this.style.visibility == "visible");
			if ((on && !IsVisible) || (!on && IsVisible))
				eval(on ? this.tree.UponDisplay : this.tree.UponHide)
		}
		if (on) this.style.zIndex = ++RG_ZIndex;
		this.style.visibility = (on) ? "visible" : "hidden";
	}
    if (RG_KeepHilite && this.currentItem && this.currentItem.hasRollover) {
		with(this.currentItem.style){
			backgroundColor = this.tree.BGColor;
			color = this.tree.FontColor;
		}
		if(this.currentItem.hasImageRollover)this.currentItem.imgLyr.src = this.currentItem.imageSrc;
    }
    this.currentItem = null;
}

function RG_f_KeepInWindow() {
    var ExtraSpace     = 10;
	var WindowLeftEdge = document.body.scrollLeft;
	var WindowTopEdge  = document.body.scrollTop;
	var WindowWidth    = document.body.clientWidth;
	var WindowHeight   = document.body.clientHeight;
	var WindowRightEdge  = (WindowLeftEdge + WindowWidth) - ExtraSpace;
	var WindowBottomEdge = (WindowTopEdge + WindowHeight) - ExtraSpace;

	var MenuLeftEdge = this.xPos;
	var MenuRightEdge = MenuLeftEdge + this.style.pixelWidth;
	var MenuBottomEdge = this.yPos + this.style.pixelHeight;

	if (this.hasParent) {
		var ParentLeftEdge = this.parentItem.oL;
	}
	if (MenuRightEdge > WindowRightEdge) {
		if (this.hasParent) {
			this.xPos = ((ParentLeftEdge - this.parentItem.DistanceToLeftEdge) + this.parentItem.ChildOverlap) - this.offsetWidth;
		}
		else {
			dif = MenuRightEdge - WindowRightEdge;
			this.xPos -= dif;
		}
		this.xPos = Math.max(5,this.xPos);
	}

	if (MenuBottomEdge > WindowBottomEdge) {
		dif = MenuBottomEdge - WindowBottomEdge;
		this.yPos -= dif;
	}

	if (MenuLeftEdge < WindowLeftEdge) {
		if (this.hasParent) {
			this.xPos = (ParentLeftEdge + this.parentItem.DistanceToRightEdge) - this.parentItem.ChildOverlap;
			MenuRightEdge = this.xPos + this.style.pixelWidth;
			if(MenuRightEdge > WindowRightEdge) this.xPos -= (MenuRightEdge - WindowRightEdge);
		}
		else {this.xPos = 5}
	}
}

function RG_f_LinkIt() {
    if (this.linkText.indexOf("javascript:")!=-1) eval(this.linkText)
    else {
		RG_f_HideAll();
		location.href = this.linkText;
	}
}

function RG_f_PopDown(menuname){
    if (!RG_AreLoaded || !RG_AreCreated) return;
	menuname = menuname.replace("elMenu",RG_MenuIDPrefix);
    var MenuToHide = document.all(menuname);
	if(!MenuToHide)return;
    MenuToHide.isOn = false;
    if (!RG_ClickKill) MenuToHide.hideTop();
}

function RG_f_HideAll(callingmenu) {
	for(var i=0; i<RG_TotalTrees; i++) {
        var TopMenu = RG_a_TopMenus[i].tree.startChild;
		if(TopMenu == callingmenu)continue
        TopMenu.isOn = false;
        if (TopMenu.hasChildVisible) TopMenu.hideChildren();
        TopMenu.showIt(false);
    }    
}

function RG_f_HideTree() { 
    RG_HideAllTimer = null;
    if (RG_UserOverMenu) return;
    if (this.hasChildVisible) this.hideChildren();
    this.hideParents();
}

function RG_f_HideTop() {
	TopMenuToHide = this;
    (RG_ClickKill) ? TopMenuToHide.hideSelf() : (this.hideTimer = setTimeout("TopMenuToHide.hideSelf()",RG_TopMilliSecondsVisible));
}

function RG_f_HideSelf() {
    this.hideTimer = null;
    if (!this.isOn && !RG_UserOverMenu) this.showIt(false);
}

function RG_f_HideParents() {
    var TempMenu = this;
    while(TempMenu.hasParent) {
        TempMenu.showIt(false);
        TempMenu.parentMenu.isOn = false;        
        TempMenu = TempMenu.parentMenu;
    }
    TempMenu.hideTop();
}

function RG_f_HideChildren(callingitem) {
    var TempMenu = this.visibleChild;
    while(TempMenu.hasChildVisible) {
        TempMenu.visibleChild.showIt(false);
        TempMenu.hasChildVisible = false;
        TempMenu = TempMenu.visibleChild;
    }
	if((callingitem && (!callingitem.hasMore || this.visibleChild != callingitem.child)) || (!callingitem && !this.isOn)) {
		this.visibleChild.showIt(false);
		this.hasChildVisible = false;
	}
}

function RG_f_CancelSelect(){return false}

function RG_f_PageClick() {
    if (!RG_UserOverMenu && RG_CurrentMenu!=null && !RG_CurrentMenu.isOn) RG_f_HideAll();
}

popUp = RG_f_PopUp;
popDown = RG_f_PopDown;

function RG_f_ResizeHandler(){
	var mouse_x_position, mouse_y_position;
	for(var i=0; i<RG_TotalTrees; i++) {
        var TopMenu = RG_a_TopMenus[i].tree.startChild;
		if(TopMenu.style.visibility == "visible") {
			TopMenu.oldLeft = TopMenu.xPos;
			TopMenu.oldTop = TopMenu.yPos;
			mouse_x_position = TopMenu.mouseX;
			mouse_y_position = TopMenu.mouseY;
			TopMenu.xPos = eval(TopMenu.tree.MenuLeft);
			TopMenu.yPos = eval(TopMenu.tree.MenuTop);
			if(TopMenu.xPos == null) TopMenu.xPos = TopMenu.xIntended;
			if(TopMenu.yPos == null) TopMenu.yPos = TopMenu.yIntended;
			if(!TopMenu.tree.TopIsPermanent) TopMenu.keepInWindow();
			TopMenu.moveTo(TopMenu.xPos,TopMenu.yPos);
			var TempMenu = TopMenu;
		    while(TempMenu.hasChildVisible) {
				TempParent = TempMenu;
				TempMenu = TempMenu.visibleChild;
				TempMenu.xPos = TempParent.xPos + TempMenu.xDiff;
				TempMenu.yPos = TempParent.yPos + TempMenu.yDiff;
				if(!TopMenu.tree.TopIsPermanent || (TopMenu.tree.TopIsPermanent && !TopMenu.tree.PositionUnder)) TempMenu.keepInWindow();
				TempMenu.moveTo(TempMenu.xPos,TempMenu.yPos);
		    }
		}
    }
	RG_f_OtherResize();
}

RG_f_OtherResize = (window.onresize) ? window.onresize :  new Function;
window.onresize = RG_f_ResizeHandler;

RG_f_OtherOnLoad = (window.onload) ? window.onload :  new Function;
window.onload = function(){setTimeout("RG_f_StartIt()",10)};

//end