function Menu(divs){
	this.node=new Array();
	this.divs=divs;
	this.current=null;
	this.host=null;

	
	
	this.show=function(){

		this.showContext(this.node[0].child[1]);
	}

	this.replaceUrl=function(link,node){
		if(!this.host) this.host=window.location.host;

		link.href='http://'+this.host+'/heading/heading'+node.id+'.html';
		link.firstChild.nodeValue=node.name;
	}
	

	
	this.showContext=function(main){
		var div=document.getElementById(this.divs['context']);
		if(!div) return;
		var title=document.getElementById(this.divs['context']+'Title');
		var template=document.getElementById(this.divs['context']+'Template');
		var selectedTemplate=document.getElementById(this.divs['context']+'SelectedTemplate');
		var subtemplate=document.getElementById(this.divs['context']+'SubTemplate');
		var selectedSubtemplate=document.getElementById(this.divs['context']+'SelectedSubTemplate');
		var div=template.parentNode;
		div.removeChild(template);
		div.removeChild(selectedTemplate);
		div.removeChild(subtemplate);
		div.removeChild(selectedSubtemplate);
		template.style.display='';
		selectedTemplate.style.display='';
		subtemplate.style.display='';
		selectedSubtemplate.style.display='';
		
		title.innerHTML='Bibliothécaires et partenaires';
		for(var i in main.child){
			var node=main.child[i];
			var cell=(this.hasChildSelected(node))?selectedTemplate.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
			
			if(this.hasChildSelected(node) || true){
				for(var j in node.child){
					var subnode=node.child[j];
					cell=(this.hasChildSelected(subnode))?selectedSubtemplate.cloneNode(true):subtemplate.cloneNode(true);
					this.replaceUrl(cell.firstChild,subnode);
					div.appendChild(cell);
				}
			}
			
		}
	}
	
	this.findNode=function(id,level,node,parent){
		if(!node) node=this.node;
		for(var i in node){
			var child=node[i];
			if(parent) child.parent=parent.id;
			if(child.id==id) return child;
			var n=this.findNode(id,level,child.child,node);
			if(n!=null){
				if(level==child.level) n=child;
				return n;
			}
		}
		return null;
	}
	
	this.hasChildSelected=function(node){
		if(node.id==this.current) return true;
		for(var i in node.child){
			var child=node.child[i];
			if(this.hasChildSelected(child)) return true;
		}
		return false;
	}
	
	this.selected=function(obj,id){
		obj.mem=obj.id;
		obj.id=id;
	}
	
	this.deselected=function(obj){
		obj.id=obj.mem;
	}
}