/* 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","/"],
	["Resources","#"],
		["|Alameda Girls Softball Association","http://www.alamedagsa.com"],
		["|Albany Berkeley Girls Softball League","http://www.abgsl.org"],
		["|Oakland Girls Softball League","http://www.ogsl.org"],
		["|San Lorenzo Girls Softball League","http://www.leaguelineup.com/slz/"],
		["|ASA Softball","http://www.asasoftball.com/"],
		["|Piedmont Baseball","http://www.piedmontbaseball.org"],
	["Game Publicity","http://www.piedmontsoftball.com/PSF-Game-Publicity-Report.html"],
	["Schedules","#"],		
		["|PSF Schedules","schedules.html"],
		["|Field Directions","field_directions.html"],
		["|PHS JV & Varsity Schedules","PHS_softball_schedules.html"],
	["Coaches Kit","coaches_kit.html"],
	["Sponsors","sponsors.html"],
	["Contact Us","#"],
		["|PGS Board Members","contact.html"],
		["|Coach Contacts","coaches.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);
}



