/* -----------------------------------------------
Title: Menu Script (Legacy) see main_dom_souce.js for source
Author: Jarid Love
Modified: 08 Sep 2005
----------------------------------------------- */

cMT = null; // current menu tree
cM = null; // current menu
mHT = null; // menu hide timer
mST = null; // menu show timer
mOM = false; // mouse on menu boolean
tM = []; // top menus array
isHC = false; // is header created boolean
hiddenElmnts = false; // to identify if flash and form elements have been hidden
fc = ["#333","#333","#FFF"]; // font color
fc_o = ["#333","#FFF","#FFF"]; // font color on mouseover
bg = ["#EEE","#BABDB6","#6B6C69","#2E3436"]; // background color
bg_o = ["#BABDB6","#6B6C69","#2E3436","#000"]; // background color on mouseover

// left navigation creation function
function createLeftNav(menuId) {
	cM = null;
	var mArray = eval("menu_" + menuId);
	cMT = { width:173,x:11 };
	tM[tM.length] = cMn(menuId,false);
	if(typeof lnavTrail != "undefined") {
		var lnavTrailObj = document.createElement("div");
		lnavTrailObj.innerHTML = lnavTrail;
		tM[tM.length-1].appendChild(lnavTrailObj);
	}
};

// header navigation creation function
function createHdrNav() {
	cHM("prod",154);
	cHM("serv",308);
	cHM("partner",462);
	isHC = true;
};

// cHM = create header menu (creates individual header menus)
function cHM(menuId,xPos) {
	cM = null;
	var mArray = eval("menu_" + menuId);
	cMT = { width:148,x:xPos };
	tM[tM.length] = cMn(menuId,true);
};

function showHdrMenu(navId) {
	if(isHC) {
		if(mHT) clearTimeout(mHT);
		mOM = true;
		var h_m = document.getElementById("menu" + navId.substring(10));
		if(h_m && !h_m.isOn) {
			cM = h_m;
			var t_tp = cM.tree.treeParent;
			if(!t_tp) t_tp = cM;
			if(t_tp == cM) hidetM(cM);
			mST = setTimeout("cM.showL()",400);
		}
	}
};

function hideHdrMenu(navId) {
	if(isHC) {
		clearTimeout(mST);
		clearTimeout(mHT);
		mOM = false;
		var h_m = document.getElementById("menu" + navId.substring(10));
		if(!h_m.isOn) {
			if(hiddenElmnts) mHT = setTimeout("showF()",800);
		}
		else mHT = setTimeout("cM.hideT()",800);
	}
};

// cMn = create menu (creates individual menu items)
function cMn(menuId,isHdr) {
	var lyr = document.createElement("DIV");
	lyr.id = "menu" + menuId;
	lyr.className = (isHdr)?"ddmnu-mnu-hdr":"ddmnu-mnu-sub";
	lyr.a = eval("menu_" + menuId);
	lyr.isHdrMenu = isHdr;
	lyr.itemCount = 0;
	lyr.tree  = cMT;
	lyr.showL = showL;
	lyr.hideL = hideL;
	lyr.onmouseover = menuOn;
	lyr.onmouseout = menuOut;
	lyr.hideT = hideT;
	lyr.hideChildren = hideCM;
	lyr.hasCVisible = false;
	lyr.isOn = false;
	lyr.currentItem = null;
	
	// set style attributes
	var l_s = lyr.style;
	l_s.width = cMT.width + "px";
	if(cM) {
		// if current menu exists, this is not a top level menu so set arributes differently
		l_s.left = l_s.top = "-200px";
		lyr.parentMenu = cM;
		lyr.level = cM.level+1;
		lyr.parentRow = cM.row;
		lyr.parentRow.child = lyr;
		lyr.hasParent = true;
	}
	else {
		// top level menu
		l_s.left = cMT.x + "px";
		lyr.hasParent = false;
		cMT.treeParent = lyr;
		if(isHdr) {
			lyr.className += " ddmnu-mnu-l" + 2;
			lyr.level = 2;
			l_s.top = "77px";
		}
		else {
			lyr.level = 1;
			lyr.isOn = true;
			if(!document.getElementById("contentcontainer")) l_s.top = eval("menu_" + menuId)[0][2];
			else if(document.getElementsByTagName("h1").length > 0 && document.getElementsByTagName("h1")[0].id.indexOf("bar") >= 0) {
				if(document.getElementById("lnavlogo")) l_s.top = "76px";
				else l_s.top = "20px";
			}
		} 
	}
	
	// if header menu, identify corresponding header link
	if(isHdr && lyr.level == 2) {
		lyr.hdrElement = document.getElementById("hdr-lnks2-" + menuId);
		l_s.backgroundColor = "#C8C8C8";
	}
	else l_s.backgroundColor = bg[lyr.level-1];
	
	// for each menu item create a row & set it's position
	cM = lyr;
	var itr = (isHdr)?lyr.a.length:lyr.a.length-1;
	while(itr--) {
		cM.itemCount++;
		var row = createRow(menuId);
		if(row) {
			cM.row = row;
			cM.appendChild(row);
			if(row.hasMore) {
				var childMenu = cMn(menuId+"_"+cM.itemCount,isHdr);
				if(childMenu) cM = cM.parentMenu;
			}
		}
	}
	
	// add new menu to page in predefined div
	document.getElementById((isHdr)?"hdr":"subnav").appendChild(lyr);
	return cM;
};

function createRow(menuId) {
	// create row div object and basic variables
	var row = document.createElement("DIV");
	row.className = "ddmnu-row ddmnu-row-l" + cM.level;
	row.id = "row" + menuId + "_" + cM.itemCount;
	row.menu = cM;
	row.tree = cMT;
	row.index = cM.itemCount - 1;
	row.child = null;
	
	// set colors depending on whether or not it's a header menu or left nav
	if(cM.isHdrMenu) {
		row.a = cM.a[cM.itemCount-1];
		if(row.a[2] == "2") {
			row.className += " ddmnu-hdr-heading";
			if(cM.itemCount == 1) row.className += " ddmnu-hdr-heading-top";
			row.hasMore = false;
		}
		else {
			row.hasMore = row.a[2];
		}
		row.fc = "#333";
		row.fc_o = fc_o[cM.level-1];
		row.bg = (cM.level == 2) ? "#C8C8C8" : bg[cM.level-1];
		row.bg_o = bg_o[cM.level-1];
	}
	else {
		row.a = cM.a[cM.itemCount];
		if(row.a[9] == 2) {
			row.hasMore = false;
			//row.className += " ddmnu-keylnk";
		}
		else row.hasMore = row.a[9];
		row.fc = fc[cM.level-1];
		row.fc_o = fc_o[cM.level-1];
		row.bg = bg[cM.level-1];
		row.bg_o = bg_o[cM.level-1];
	}
	//if(row.className.indexOf("ddmnu-keylnk") < 0) {
		row.onmouseover = rowOn;
		row.onmouseout = rowOut;
		row.showCM = showCM;
	//}

	// set div object style attributes
	var r_s = row.style;
	if(row.hasMore) {
		row.imageSrc = (cM.isHdrMenu || cM.level > 3) ? "/common/img/lnav_arrow_light.gif" : "/common/img/lnav_arrow.gif";
		r_s.background = row.bg + " url(" + row.imageSrc + ") no-repeat " + (row.tree.width-16) + "px 3px";
	}
	else r_s.backgroundColor = row.bg;
	r_s.color = row.fc;
	
	// set row text & link
	var linktxt = (typeof row.a[1] == 'undefined') ? "" : row.a[1];
	
	// create interior text of div object
	if(linktxt.length>0 && linktxt != "#") row.innerHTML = '<a class="ddmnu-link" href="'+linktxt+'" style="color:'+r_s.color+';"><span>'+row.a[0]+'</span></a>';
	else row.innerHTML = '<div class="ddmnu-empty">'+row.a[0]+'</div>';
	if(cM.level == 1) row.innerHTML = '<div class="ddmnu-inner">'+row.innerHTML+'</div>';

	return row;
};

function menuOn() {
	var t_tp = this.tree.treeParent;
	if(!t_tp) t_tp = this;
	if(t_tp == this) hidetM(this);
	mOM = true;
	cM = this;
	if(mHT) clearTimeout(mHT);
};

function menuOut() {
	mOM = false;
	mHT = setTimeout("cM.hideT()",800);
};

// hidetM = hide tree menu
function hidetM(callingmenu) {
	for(var i = tM.length-1; i >= 0; i--) {
		var topMenu = tM[i].tree.treeParent;
		if(topMenu == callingmenu) continue;
		if(topMenu.hasCVisible) topMenu.hideChildren();
		if(topMenu.isOn) topMenu.hideL();
	}
};

function rowOn() {
	this.style.backgroundColor = this.bg_o;
	if(this.getElementsByTagName('a').length == 1) this.getElementsByTagName('a')[0].style.color = this.fc_o;
	else this.style.color = this.fc_o;
	if(this.menu.hasCVisible) {
		var v_c = this.menu.visibleChild;
		if(v_c == this.child && v_c.hasCVisible) v_c.hideChildren(this);
		else this.menu.hideChildren(this);
	}
	if(this.menu.currentItem && this.menu.currentItem != this) {
		var current = this.menu.currentItem;
		current.style.backgroundColor = current.bg;
		if(current.getElementsByTagName('a').length == 1) current.getElementsByTagName('a')[0].style.color = current.fc;
		else current.style.color = current.fc;
		if(current.hasMore) current.style.backgroundImage = "url(" + current.imageSrc + ")";
	}
	this.menu.currentItem = this;
	if(this.hasMore) {
		this.style.backgroundImage = "";
		this.showCM();
	}
};

function rowOut() {
	if(!this.menu.hasCVisible) {
		this.style.backgroundColor = this.bg;
		if(this.getElementsByTagName('a').length == 1) this.getElementsByTagName('a')[0].style.color = this.fc;
		else this.style.color = this.fc;
		if(this.hasMore) this.style.backgroundImage = "url(" + this.imageSrc + ")";
	}
};

// showL = show links
function showL() {
	if(this.tree.treeParent != this || this.isHdrMenu) {
		if(!hiddenElmnts) hideF();
		
		if(this.hdrElement) {
			var hdrEmt = this.hdrElement;
			hdrEmt.className = hdrEmt.className + " menuon";
		}
		this.style.visibility = "visible";
		this.isOn = true;
	}
};

// hideL = show links
function hideL() {
	if(this.tree.treeParent != this || this.isHdrMenu) {
		this.style.visibility = "hidden";
		this.isOn = false;
	}
	if(this.currentItem) {
		var current = this.currentItem;
		current.style.backgroundColor = current.bg;
		if(current.getElementsByTagName('a').length == 1) current.getElementsByTagName('a')[0].style.color = current.fc;
		else current.style.color = current.fc;
		if(current.hasMore) current.style.backgroundImage = "url(" + current.imageSrc + ")";
	}
	this.currentItem = null;
	if(this.isHdrMenu && this.tree.treeParent==this) {
		var hdrEmt = this.hdrElement;
		hdrEmt.className = hdrEmt.className.replace("menuon","");
	}
};

// hideT = hide tree
function hideT() {
	clearTimeout(mHT);
	if(mOM) return;
	if(this.hasCVisible) this.hideChildren(this);
	var menu = this;
	menu.hideL();
	while(menu.hasParent) {
		menu = menu.parentMenu;
		menu.hideL();
	}
    if(hiddenElmnts) showF();
};

// showCM = show child menu
function showCM() {
	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.tree.width)) + "px";
	menu.hasCVisible = true;
	menu.visibleChild = this.child;
	this.child.showL();
};

// hide child menu
function hideCM(caller) {
	var menu = this.visibleChild;
	while(menu.hasCVisible) {
		menu.visibleChild.hideL();
		menu.hasCVisible = false;
		menu = menu.visibleChild;
	}
	if((caller && (!caller.hasMore || this.visibleChild != caller.child)) || (!caller && this.isOn)) {
		this.visibleChild.hideL();
		this.hasCVisible = false;
	}
};

// hide form fields that show through menus when menu made visible
function hideF() {
	for(var i = document.forms.length-1; i >= 0; i--) {
		var form = document.forms[i];
		if(form.id != "hdr_ww") {
			for(var j = form.elements.length-1; j >=0 ; j--) {
				var elmt = form.elements[j];
				if((elmt.type == "select-one" || elmt.type == "select-multiple")) elmt.style.visibility = "hidden";
			}
		}
	}
	// hide flash content because it shows through navigation
	if(typeof flash != "undefined") {
		// if flash.forcehide, hide property has been manually set
		// if not windows, wmode not supported, so hide flash
		// if flash version is less than 6,0,79,0 hide flash because wmode not supported widely
		if(flash.forcehide || !isWin || (flash.version <= 6 && flash.rev < 79) || isOperaGoodDom) hideFlashDivs();
	}
	hiddenElmnts = true;
};

function hideFlashDivs() {
	for(var i = 0; i < flash.movies.length; i++) {
		var elmt = document.getElementById("flash_"+i);
		elmt.style.visibility = 'hidden';
	}
};

// show form fields that have been hidden because they show through menus
function showF() {
	for(var i = document.forms.length-1; i >= 0; i--) {
		var form = document.forms[i];
		for(var j = form.elements.length-1; j >=0 ; j--) {
			var elmt = form.elements[j];
			if((elmt.type == "select-one" || elmt.type == "select-multiple")) elmt.style.visibility = "inherit";
		}
	}
	// show flash content that was hidden because it shows through navigation
	if(typeof flash != "undefined") {
		if(flash.forcehide || !isWin || (flash.version <= 6 && flash.rev < 79) || isOperaGoodDom) showFlashDivs();
	}
	hiddenElmnts = false;
};

function showFlashDivs() {
	for(var i = 0; i < flash.movies.length; i++) {
		var elmt = document.getElementById("flash_"+i);
		elmt.style.visibility = 'visible';
	}
};