
var Nav = {
	Init : function(){
		navRoot = document.getElementById('menu').getElementsByTagName('UL');		
		for(i=0; i<navRoot.length; i++){
			//Check if the cookie value matches current id if so don't hide
			if(Cookie.Read('section') != navRoot[i].parentNode.id){
				navRoot[i].parentNode.className = 'closed'; //Set default class
			};
			navRoot[i].parentNode.onclick = Nav.Click; //Add Click event
		};
	},
	Click : function(){
		//Close all menus
		for(i=0; i<navRoot.length; i++){
			navRoot[i].parentNode.className = 'closed';
		};
		//Open clicked menu
		this.className = 'open';
		Cookie.Create('section', this.id, 0); //create open menu cookie save for 0 days
	}
};

window.onload = function() {
	Nav.Init();	
}

/* 
	General cookie function based on quirksmode examples
	http://www.quirksmode.org/js/cookies.html 
*/
var Cookie = {
	Create : function(name, value, days){
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	Read : function(name){
		var nameEQ = name.toLowerCase() + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i].toLowerCase();
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	Erase : function(){
		this.Create(name, "", -1);
	}
};