function Menu(divs){
	if(navigator.userAgent.substring(25,33)=="MSIE 7.0") {
		// Detecter IE 7
		// alert("IE7");
	}
	this.node=new Array();
	this.divs=divs;
	this.current=null;
	this.host=null;

	
	
	this.show=function(){
		if(this.node[0] && this.node[0].child){
			this.showMainMenu(this.node[0].child);
		}
		if(this.node[0] && this.node[0].child[0])
			this.showCible(this.node[0].child[0].child);
			
		if(this.node[0] && this.node[0].child[1])
			this.showCible1(this.node[0].child[1].child);
			
		if(this.node[0] && this.node[0].child[2])
			this.showCible2(this.node[0].child[2].child);

		if(this.node[0] && this.node[0].child[3])
			this.showCible3(this.node[0].child[3].child)

		if(this.node[0] && this.node[0].child[4])
			this.showCible4(this.node[0].child[4].child);
		
		if(this.node[0] && this.node[0].child[5])
			this.showCible5(this.node[0].child[5].child);
		
		if(this.node[0] && this.node[0].child[6])
			this.showCible6(this.node[0].child[6].child);		
			
		this.showContext(this.findNode(this.current,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.showMainMenu=function(nodes){
		var div=document.getElementById(this.divs['mainMenu']);
		var template=document.getElementById(this.divs['mainMenu']+'Template');
		var templateSelected=document.getElementById(this.divs['mainMenu']+'SelectedTemplate');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='';
		templateSelected.style.display='';
		
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			cell.id='mainMenuRowTemplate'+i+'';
			var menuID = 'menuID'+i;
			cell.name = menuID; 
			cell.onmouseover=function() {showId(this.name);};
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);

		}
	}

		
this.showCible=function(nodes){
		var div=document.getElementById(this.divs['cible']);
		var template=document.getElementById(this.divs['cible']+'Template');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}
this.showCible1=function(nodes){
		var div=document.getElementById(this.divs['cible1']);
		var template=document.getElementById(this.divs['cible']+'Template1');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate1');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}
this.showCible2=function(nodes){
		var div=document.getElementById(this.divs['cible2']);
		var template=document.getElementById(this.divs['cible']+'Template2');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate2');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}	

this.showCible3=function(nodes){
		var div=document.getElementById(this.divs['cible3']);
		var template=document.getElementById(this.divs['cible']+'Template3');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate3');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}	

this.showCible4=function(nodes){
		var div=document.getElementById(this.divs['cible4']);
		var template=document.getElementById(this.divs['cible']+'Template4');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate4');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}	

this.showCible5=function(nodes){
		var div=document.getElementById(this.divs['cible5']);
		var template=document.getElementById(this.divs['cible']+'Template5');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate5');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}	
this.showCible6=function(nodes){
		var div=document.getElementById(this.divs['cible6']);
		var template=document.getElementById(this.divs['cible']+'Template6');
		var templateSelected=document.getElementById(this.divs['cible']+'SelectedTemplate6');
		div.removeChild(template);
		div.removeChild(templateSelected);
		template.style.display='block';
		templateSelected.style.display='block';
		for(var i in nodes){
			var node=nodes[i];
			var cell=(this.hasChildSelected(node))?templateSelected.cloneNode(true):template.cloneNode(true);
			this.replaceUrl(cell.firstChild,node);
			div.appendChild(cell);
		}
	}	
	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=main.name;
		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)){
				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;
	}
}