MENU_PREFIX = "submenu-";
NAV_PREFIX = "nav-";

var cMenuArray = null;
var cMenuTree = null;
var cMenu = null;
var cMenuLink = null;
var nHideTimer = null;
var nShowTimer = null;
var mouseOnMenu = false;
var topMenus = new Array();
var navInitializedP = false;

function initializeNavigation() {
	initNavMenu('eligibility');
	navInitializedP = true;
};

function initNavMenu(menuId) {
	cMenu = null;
	cMenuTree = [];
	topMenus[topMenus.length] = initMenu(menuId, true);
};

function showMyMenu() {
	showMenu(this.menuId);
};

function showMenu(navId) {
	if (navInitializedP) {
		var h_m = document.getElementById(MENU_PREFIX + navId);
		if (h_m) {
			cMenu = h_m;
			if (h_m.level == 2) {
				hidetopMenus(cMenu);
			}
			cMenu.isOn = true;
			mouseOnMenu = true;
			if (cMenu.nHideTimer) {
				clearTimeout(cMenu.nHideTimer);
			}
			nShowTimer = setTimeout("cMenu.showLinks()", 100);
		}
	}
	
};

function initMenu(menuId, isHdr) {
	var lyr = document.getElementById(MENU_PREFIX + menuId);
	var l_s = lyr.style;
	l_s.zIndex = 1000;
	if (cMenu) {
		l_s.zIndex = 1001;
		lyr.parentMenu = cMenu;
		lyr.parentMenu.child = lyr;
		lyr.hasParent = true;
		lyr.level = lyr.parentMenu.level + 1;
	} else {
		cMenuTree.treeParent = cMenuTree.startChild = lyr;
		lyr.level = 2;
	}
	
	lyr.isHdrMenu = isHdr;
	lyr.tree  = cMenuTree;
	lyr.itemCount = 0;
	lyr.showLinks = showLinks;
	lyr.hideLinks = hideLinks;
	lyr.onmouseover = onMenuOver;
	lyr.onmouseout = onMenuOut;
	lyr.hideTree = hideTree;
	lyr.hideChildren = hideChildMenus;
	lyr.hasChildVisible = false;
	lyr.isOn = false;
	lyr.nHideTimer = null;
	lyr.currentItem = null;
	
	
	if (isHdr) {
		lyr.navElement = document.getElementById(NAV_PREFIX + menuId);
		lyr.navElement.menuId = menuId;
		lyr.navElement.onmouseout = lyr.onmouseout;
		lyr.navElement.onmouseover = showMyMenu;
	}
	cMenu = lyr;
//	document.getElementById("navMenus").appendChild(lyr);
	return cMenu;
};

function onMenuOver() {
//	hidetopMenus(this);
	this.isOn = true;
	mouseOnMenu = true;
//	cMenu = this;
	if (this.nHideTimer) {
		clearTimeout(this.nHideTimer);
	}
};

function hidetopMenus(callingmenu) {
	for (var i = 0; i < topMenus.length; i++) {
		var topMenu = topMenus[i].tree.startChild;
		if (topMenu == callingmenu) {
			continue;
		}
		topMenu.isOn = false;
		if (topMenu.hasChildVisible) {
			topMenu.hideChildren();
		}
		topMenu.hideLinks();
	}
};

function onMenuOut() {
	this.isOn = false;
	mouseOnMenu = false;
	clearTimeout(nHideTimer);
	nHideTimer = null;
	nHideTimer = setTimeout("cMenu.hideTree()",100);
};

function showChildMenu() {
	var menu = this.menu;
	var c_s = this.child.style;
	c_s.top = (parseInt((menu.style.top) ? menu.style.top : menu.offsetTop) + this.offsetTop) + "px";
	c_s.left = (parseInt((menu.style.left) ? menu.style.left : menu.offsetLeft) + parseInt(this.style.width)) + "px";
	menu.hasChildVisible = true;
	menu.visibleChild = this.child;
	this.child.showLinks();
};

function rowMouseOver() {
	this.style.backgroundColor = this.bgColorOver;
	this.style.color = this.fontColorOver;
	if (this.menu.hasChildVisible) {
		var visibleChild = this.menu.visibleChild;
		if (visibleChild == this.child && visibleChild.hasChildVisible) {
			visibleChild.hideChildren(this);
		} else {
			this.menu.hideChildren(this);
		}
	}
	if (this.menu.currentItem && this.menu.currentItem != this) {
		var current = this.menu.currentItem;
		current.style.backgroundColor = current.bgColor;
		current.style.color = current.fontColor;
		if(current.hasMore) {
			current.imageLayer.src = current.imageSrc;
		}
	}
	this.menu.currentItem = this;
	if (this.hasMore) {
		this.imageLayer.src = this.imageSrcOver;
		this.showChild();
	}
	status = this.linkText;
};

function rowMouseOut() {
	if ((this.tree.treeParent == this) && !this.menu.hasChildVisible) {
		this.style.backgroundColor = this.bgColor;
		this.style.color = this.fontColor;
		if(this.hasMore) {
			this.imageLayer.src = this.imageSrc;
		}
	}
};

function showLinks() {
	this.style.visibility = "visible";
	this.navElement.setAttribute("class", "down");
	this.navElement.setAttribute("className", "down");
};

function hideLinks() {
	this.style.visibility = "hidden";
	this.navElement.setAttribute("class", "");
	this.navElement.setAttribute("className", "");

	if (this.currentItem) {
		var current = this.currentItem;
		current.style.backgroundColor = current.bgColor;
		current.style.color = current.fontColor;
		if(current.hasMore) {
			current.imageLayer.src = current.imageSrc;
		}
	}
	this.currentItem = null;
};

function hideTree() {
	nHideTimer = null;
	if(mouseOnMenu) {
		return;
	}
	if(this.hasChildVisible) {
		this.hideChildren(this);
	}
	var menu = this;
	while(menu.hasParent) {
		menu.hideLinks();
		menu.parentMenu.isOn = false;
		menu = menu.parentMenu;
	}
	if ((!menu.hasParent && menu.isHdrMenu) || !menu.isOn) {
		menu.hideLinks();
	}
};

function hideChildMenus(caller) {
	var menu = this.visibleChild;
	while (menu.hasChildVisible) {
		menu.visibleChild.hideLinks();
		menu.hasChildVisible = false;
		menu = menu.visibleChild;
	}
	if ((caller && (!caller.hasMore || this.visibleChild != caller.child)) || (!caller && !this.isOn)) {
		this.visibleChild.hideLinks();
		this.hasChildVisible = false;
	}
};
