/* String variables to write the menus */
var menuBarStart = "<div id='menuBar'><ul id='navMain' class='menu'> ";
var menuBarEnd = "</li></ul></div>";
var stMenuBar = "";

/* TVS: edit menu here */
var menuItems = [
	["HOME","/"],
	["PRODUCTS","/"],
		["|Laptop Battery","/index.php?cPath=1"],
		["|External Battery","/index.php?cPath=40"],
		["|Adapter","/index.php?cPath=2"],
		["|Power Cord","/index.php?cPath=34"],
			["||2-Pin Power Cord","/index.php?cPath=34_35"],
			["||3-Pin Power Cord","/index.php?cPath=34_36"],
		["|Others","/index.php?cPath=39"],
		["|All Brands","/index.php?manufacturers=all"],
		["|",""],  // must have?
	["CUSTOMERS",""],
		["|Login Your Account","/login.php"],
		["|Advanced Search","/advanced_search.php"],
		["|Shipping & Handling","/info.php?info_id=Shipping%20And%20Handling"],
		["|Track Your Order","/account_history.php"],
		["|Request An RMA","/info.php?info_id=RMA%20Form"],
	["ABOUT",""],
		["|Mission Statement","/info.php?info_id=Mission%20Statement"],
		["|Company History","/info.php?info_id=Company%20History"],
		["|News","/info.php?info_id=News"],
		["|Management","/info.php?info_id=Management"],
	["POLICIES",""],
		["|Warranty","/info.php?info_id=Warranty"],
		["|Return Policy","/info.php?info_id=Return%20Policy"],
		["|Privacy Policy","/info.php?info_id=Privacy%20Policy"],
		["|Legal","/info.php?info_id=Legal"],
	["HELP",""],
		["|Battery Technology","/info.php?info_id=Battery%20Technology"],
		["|Battery Safety","/info.php?info_id=Battery%20Safety"],
		["|FAQ's","/info.php?info_id=FAQs"],
	["CONTACT",""],
		["|Customer Service","/info.php?info_id=Customer%20Service"],
		["|Affiliates","/info.php?info_id=Affiliates"],
		["|Contact Us","/info.php?info_id=Contact%20Us"]
]

initNavSubs = function() {
	var navList = document.getElementById("navMain").getElementsByTagName("LI");
	for (var i=0; i<navList.length; i++) {// assign white arrow class to indicate sub menu except for top items			
		navList[i].onmouseover=function(){this.className+=" itemHover";}
		navList[i].onmouseout=function(){this.className=this.className.replace(new RegExp(" itemHover\\b"), "");}
	}	
}

if (window.attachEvent) window.attachEvent("onload", initNavSubs);
window.onload = function(){
	var navList = document.getElementById("navMain").getElementsByTagName("LI");
	for (var i=0; i<navList.length; i++) {// assign white arrow class to indicate sub menu except for top items
		if(navList[i].childNodes[0].nextSibling != null && navList[i].childNodes[0].nextSibling.tagName == "UL" && navList[i].parentNode.id != "navMain" ){
			navList[i].className+="expand";
		}
	}
}

var previousItemLevel = null;
function writeMenus(){// parse + process/convert menu array into HTML
	for(i=0; i<menuItems.length; i++){
		var itemUrl = menuItems[i][1];
		var itemTitle = menuItems[i][0];	
		currentItem =  menuItems[i].toString();
		currentItemLevel = currentItem.substring(0,3);
		currentItemLevel = currentItemLevel.lastIndexOf("|")+1; 
		itemTitle = itemTitle.substring(currentItemLevel);
		if(currentItemLevel == 0 && currentItemLevel != previousItemLevel){ /* process top items */
			if(currentItemLevel == previousItemLevel){
				stMenuBar += "</li><li><a href='" + itemUrl + "'>" + itemTitle + "</a>";			
			}else if(currentItemLevel < previousItemLevel){				
				stMenuBar +=  "</li></ul></li><li><a href='" + itemUrl + "'>" + itemTitle + "</a>";				
			}else if(currentItemLevel != previousItemLevel){
				stMenuBar +=  "<li><a href='" + itemUrl + "'>" + itemTitle + "</a>";
			}		
		}else{ // process sub hovered menus
			if(currentItemLevel== previousItemLevel){				
				stMenuBar += "</li><li><a href='" + itemUrl + "'>" + itemTitle + "</a>";	
			}else if(currentItemLevel < previousItemLevel){
				stMenuBar +=  "</li></ul></li><li><a href='" + itemUrl + "'>" + itemTitle + "</a>";				
			}else if(currentItemLevel > previousItemLevel){
				stMenuBar +=  "<ul><li><a href='" + itemUrl + "'>" + itemTitle + "</a>";
			}				
		}
		previousItemLevel = currentItemLevel;
	}
	stMenuBar = menuBarStart + stMenuBar + menuBarEnd;
	document.write(stMenuBar);
}

