var menuDiv = null;
var debugOn = null;
debugOn = false;
//window.onload = initMenu;

	function init() {
		// quit if this function has already been called
		if (arguments.callee.done) return;
		
		// flag this function so we don't do the same thing twice
		arguments.callee.done = true;
		
		// kill the timer
		if (_timer) {
			clearInterval(_timer);
			_timer = null;
		}
		
		// create the "page loaded" message
		initMenu();
	};
	
	/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	}
	
	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				init(); // call the onload handler
			}
		};
	/*@end @*/
	
	/* for Safari */
	if (/WebKit/i.test(navigator.userAgent)) { // sniff
		var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				init(); // call the onload handler
			}
		}, 10);
	}
	
	/* for other browsers */
	window.onload = init;


function initMenu(){

	debug("here");
	 menuDiv = document.getElementById("menubar");
	 lastElement = menuDiv;
	
	var thisSection = null;
	
	thisSection = createMenuSection("main");
	createMenuHeader(thisSection,"Basics");
	createMenuEntry(thisSection,"Front page","index.html","_self");
	createMenuEntry(thisSection,"Mission statement","mission.html","_self");
	createMenuEntry(thisSection,"Site map","sitemap.html","_self");
	createMenuEntry(thisSection,"Contact me","contact.html","_self");

	thisSection = createMenuSection("hobbies")
	createMenuHeader(thisSection,"Hobbies");
	createMenuEntry(thisSection,"About me","christine.html","_self");
	createMenuEntry(thisSection,"My music","mymusic.html","_self");
	createMenuEntry(thisSection,"The band","fatboa.html","_self");
	createMenuEntry(thisSection,"Writings","writings.html","_self");
	createMenuEntry(thisSection,"Sketches","artwork.html","_self");
	createMenuEntry(thisSection,"Natural skincare","natural_skincare.html","_self");
	createMenuEntry(thisSection,"Kev's kitchen","kevs_kitchen.html","_self");
	createMenuEntry(thisSection,"Christine's kitchen","christines_kitchen.html","_self");
	createMenuEntry(thisSection,"Links","links.html","_self");
	
	thisSection = createMenuSection("cats")
	createMenuHeader(thisSection,"The cats");
	createMenuEntry(thisSection,"Seamus & Gizmo","seamusandgizmo.html","_self");
	createMenuEntry(thisSection,"Cats of the past","pastcats.html","_self");
	createMenuEntry(thisSection,"Cat care","catcare.html","_self");
	createMenuEntry(thisSection,"Feeding pets pills","feedingpills.html","_self");
	
	thisSection = createMenuSection("our photos")
	createMenuHeader(thisSection,"Our photos");
	createMenuEntry(thisSection,"2010","2010.html","_self");
	createMenuEntry(thisSection,"2009","2009.html","_self");
	createMenuEntry(thisSection,"Wedding 2009","2009wedding.html","_self");
	createMenuEntry(thisSection,"2008","2008.html","_self");
	createMenuEntry(thisSection,"2007","2007.html","_self");
	createMenuEntry(thisSection,"2006","2006.html","_self");
	createMenuEntry(thisSection,"2005","2005.html","_self");

	thisSection = createMenuSection("pretty places")
	createMenuHeader(thisSection,"Pretty places");
	createMenuEntry(thisSection,"Magical garden","2009magicalgarden.html","_self");
	createMenuEntry(thisSection,"Scotland 2010","scotlandphotos10.html","_self");
	createMenuEntry(thisSection,"Scotland 2007-09","scotlandphotos0709.html","_self");
	createMenuEntry(thisSection,"Scotland 2005-06","scotlandphotos0506.html","_self");
	createMenuEntry(thisSection,"Aarhus","aarhus.html","_self");
	debug("end");
}

function debug(message){
	if(debugOn == true){
		alert(message)
	}
}

function createMenuSection(id){
	var section = document.createElement("ul")
	section.setAttribute("id",id);
	section.setAttribute("class", "menuSection")
	menuDiv.appendChild(section);
	debug("Section of id "+id+" created");
	return id;
	
}

function createMenuHeader(sectionID, content){
	var section = document.getElementById(sectionID);
	var header = document.createElement("li");
	header.setAttribute("class", "menuHeader")
	var textNode = document.createTextNode(content);
	header.appendChild(textNode);
	section.appendChild(header);
	debug("Header of id "+sectionID+" created");
}
//<a href="http://www.microsoft.com/">This text</a>
function createMenuEntry(sectionID,content,linkHref,linkTarget){
	var section = document.getElementById(sectionID);
	var link = document.createElement("a");
	link.setAttribute("href", linkHref)
	link.setAttribute("target", linkTarget)
	var entry = document.createElement("li");
	entry.setAttribute("class", "menuEntry")
	var textNode = document.createTextNode(content)
	entry.appendChild(link)
	link.appendChild(textNode);
	section.appendChild(entry);
	debug("entry create with a content of  "+content+" created");
}



