/**
 * Note: it is required to set "topmenuUrlPrefix" before using the top menu on a specific page.
 */
 				//title,				URL,										Help text (optional), css-class	
 				//------------------------------------------------------------------------------------------------------------------------
topmenuItems = [ ["forside", 			topmenuUrlPrefix + "index.html", 			"Åbner forsiden", "frontpage"]  						// item 0
                 ,["børnefilmklub", 	topmenuUrlPrefix + "kids/index.html", 		"Åbner børnefilmklubbens område","kids"] 				// item 1
                 ,["ungdomfilmklub",	topmenuUrlPrefix + "youth/index.html", 		"Åbner ungdomsfilmklubbens område", "youth"]			// item 2
                 ,["bestyrelsen", 		topmenuUrlPrefix + "board/index.html", 		"Åbner bestyrelsens område", "board"] 					// item 3
                ];


Menu = {
	/**
	 * Loads top and left menus. 
	 * PRECON: It is required that the JS variables 
	 *	        - "topmenuUrlPrefix"  - Prefix to adjust the path
	 *          - "leftmenuItems"     - the items in the left menu
	 *          - "topmenuItem"       - The index of the top menu item (starting with 0)
	 *         has been defined BEFORE calling this method.
	 * POSTCON: The menus are displayed
	 */
	loadMenus : function(){
		var cssClass = topmenuItems[topmenuItem][3];
		var heading = topmenuItems[topmenuItem][0];
		
		var containerDiv = document.getElementsByTagName('body');
		containerDiv[0].className=cssClass;
		
		containerDiv = document.getElementById('leftmenu');
		menuContent = this.parseMenuArray(leftmenuItems, 'left');
		containerDiv.innerHTML =  menuContent

		containerDiv = document.getElementById('topmenu');
		menuContent = this.parseMenuArray(topmenuItems, 'top');
		containerDiv.innerHTML =  menuContent
		
		containerDiv = document.getElementById('topLink' + topmenuItem);
		// Styles are defined in main.css
		containerDiv.className="selectedTopmenuitem";
		
		containerDiv = document.getElementById('header');
		containerDiv.className=cssClass; 
	},
	
	parseMenuArray : function(menuArray, idPrefix){
		s = "<ul\>";
		var docUrl = new String(document.URL);
		// Get the name of the currently loaded page
		var currentDoc = docUrl.substring(docUrl.lastIndexOf("/")+1);
		for (i=0;i<menuArray.length;i++){
			menuDoc = menuArray[i][1];
			highlightClass = "";
			// Highlight the currently loaded page in the left menu 
			// Styles are defined in main.css
			if (idPrefix=="left" && menuDoc==currentDoc){
				highlightClass = " class=\"selectedLeftmenuitem\"";
			}
			help = menuArray[i][2]
			help = help ? " title=\"" + help + "\"" : "";
			s += "<li" + " id=\"" + idPrefix + i + "\">";
			s += "<a href=\"" + menuDoc + "\" id=\"" + idPrefix + "Link" + i + "\"" + help + highlightClass + ">" + menuArray[i][0] + "</a>";
			s+="</li>";
		}
		s += "</ul>";
		return s;
	}
}

