/* String variables to write the menus */
var menuBarStart = "<div id='menuBar'><ul id='navMain' class='menu'> ";
var menuBarEnd = "</li></ul></div>";
var stMenuBar = "";

/* EDIT MENU HERE */
/* Use pipe to indicate hierarchy */
var menuItems = [
	["Home","index.html"],
	["About","#"],
		["|Mission","mission_statement.html"],
		["|FAQs","FAQs.html"],
		["|League Guidelines","league_guidelines.html"],
		["|Divisions","division_descriptions.html"],
			["||Shetland","division-shetland.html"],
			["||Pinto","division-pinto.html"],
			["||Mustang","division-mustang.html"],
			["||Bronco","division-bronco.html"],
			["||Pony","division-pony.html"],
		["|Locations","field_directions.html"],
		["|League Calendar","calendar.html"],
 		["|",""],   /* hack to get submenus to work */
	["Game Publicity","#"],
		["|Baseball","PBF-Game-Publicity-Report.html"],
	["Bronco Standings","standings.html"],
	["Resources","#"],
		["|Coaches Kit","coaches_kit.html"],
		["|Team Planning Guide","team_planning_guide.html"],
		["|Youth Umpires","Umpire_Program.html"],
		["|Pony Baseball","PONY_Baseball.html"],
		["|Piedmont Softball","http://www.piedmontsoftball.org"],
	["Register","registration.html"],
	["Sponsors","sponsors.html"],
	["Contact Us","contact.html"]
]

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);
}



