
// compatibilité -----------------------------------------------
var ns4= (document.layers);
var ie4= (document.all && !document.getElementById);
if(ie4) {
	document.getElementById= function(id) { return(document.all(id)); }
	document.getElementsByTagName= function(id) { return(document.all.tags(id)); }
}
if(ns4) {
	document.getElementById= function(id) { return(document.layers[id]); }
}


var newCount=0;
var menuType=1;

function main(type) {
	var intCount = newCount++;
	var id='ID' + intCount;
	
	if((type==null)||((type!=1)&&(type!=2))) {type=1;}
	menuType=type;
	this.id=id;
	this.count=intCount;
	this.text = '<div id=' + id + '></div><input type="hidden" id=h' + intCount + ' value="0">';
	if(type==1) {this.text += '<input type="hidden" id=posMenu value="">';}
	document.write(this.text);
	this.parent=null;
}


function addNode(caption,pNode,act,classe,img1,img2) {
	if(act==null) {act='';}
	if(classe==null) {classe='';}
	if(img1==null) {img1='';}
	if(img2==null) {img2='';}
	// Crée le contenu du noeud : le niveau permet l'indentation
	this.niv = 1;
	intCount = newCount++;
	sText =  '<div title="">';
	sText += '<div class="struct" id=ID' + intCount;
	sText += ' onClick="Collapse(' + intCount + ');"  >';
	sText += '<img src="icones/tr_menuempty.gif" height="9" width="9" id="imgID' + intCount + '" alt="">';
	if(act=='') {
		sText += '&nbsp;' + caption;
	} else {
		sText += '&nbsp;<a href="#pos=ID' + intCount + '" id=aID' + intCount + ' class="' + classe + '" ';
		sText += ' onclick="Collapse(' + intCount + ',false); ';
		sText += 'setPos(' + intCount + ',posCurrent()); ';
		sText += act +'">' + caption + '</a>';
	}
	if(img1!='') { sText += '&nbsp;<img src="' + img1 + '">'; }
	if(img2!='') { sText += '&nbsp;<img src="' + img2 + '">'; }
	sText += '</div>';
	sText += '<div id="SUB' + intCount + '" style="display:none"></div>';
	sText += '<input type="hidden" id=h' + intCount + ' value="' + pNode.count + '" alt="' + classe + '">';
	sText += '</div>';
	document.getElementById(pNode.id).innerHTML += sText
	this.id = 'ID' + intCount;
	this.count = intCount;
	this.imgID= 'imgID' + intCount;
	this.subID= 'SUB' + intCount;
	this.hID= 'h' + intCount;
	this.parent = pNode;
	document.getElementById('h0').value = parseInt(document.getElementById('h0').value) + 1;
	return (this);
}

function addSubNode(caption,pNode,act,classe,classe2,img1,img2) {
	if(classe==null) {classe=' ';}
	if(img1==null) {img1='';}
	if(img2==null) {img2='';}
	// Modifie l'image et le alt de l'image du titre du noeud parent
	document.getElementById(pNode.imgID).src='icones/tr_menuplus.gif';
	document.getElementById(pNode.imgID).alt='+';
	this.niv = parseInt(pNode.niv) + 1;
	// contenu du noeud
	intCount = newCount++;
	sText =  '<div  class='+classe+'>';
	sText += '<div id=ID' + intCount;
	sText += ' onClick="Collapse(' + intCount + ');" ';
	sText += ' onmouseover="this.className=\'divmenu divmenuhover\';" ';
	sText += ' onmouseout="this.className=\'divmenu\';">';
	sText += '<img src="icones/tr_menuempty.gif" height="9" width="9" id="imgID' + intCount + '" alt="">';
	if(act=='') {
		sText += '&nbsp;' + caption;
	} else {
		sText += '&nbsp;<a href="'+act;
		if(menuType==2) {sText += 'pos=ID' + intCount;}
		sText +='" id=aID' + intCount + '  class=' + classe;
		sText += '  onclick="Collapse(' + intCount + ',false); ';
		sText += 'setPos(' + intCount + ',posCurrent()); ';
		sText +='">' + caption + '</a>';
	}
	if(img1!='') { sText += '&nbsp;<img src="' + img1 + '">'; }
	if(img2!='') { sText += '&nbsp;<img src="' + img2 + '">'; }
	sText += '</div>';
	sText += '<div id="SUB' + intCount + '" style="display:none"></div>';
	sText += '<input type="hidden" id=h' + intCount + ' value="' + pNode.count + '" alt="' + classe + '">';
	sText += '</div>';
	document.getElementById(pNode.subID).innerHTML += sText
	this.id = 'ID' + intCount;
	this.count = intCount;
	this.imgID= 'imgID' + intCount;
	this.subID= 'SUB' + intCount;
	this.hID= 'h' + intCount;
	this.parent = pNode;
	document.getElementById('h0').value = parseInt(document.getElementById('h0').value) + 1;
	return (this);
}

function Collapse(snode,open) {
	node=document.getElementById('SUB' + snode);
	img=document.getElementById('imgID' + snode);
	if (img.alt!='') {
		if (open==null) {
			if (node.style.display=='none') {
				node.style.display='block';
				img.src='icones/tr_menuminus.gif';
				img.alt='-';
		
			} else {
				node.style.display='none';
				img.src='icones/tr_menuplus.gif';
				img.alt='+';
			}
		} else if (open==false) {
			node.style.display='none';
			img.src='icones/tr_menuplus.gif';
			img.alt='+';	
		} else if (open==true) {
			node.style.display='block';
			img.src='icones/tr_menuminus.gif';
			img.alt='-';
		}
	}
}

function CollapseAll(snode,open) {
	var node=document.getElementById('h' + snode);
	var img=document.getElementById('imgID' + snode);
	if (open==true) {
		while(node.value != 0) {
			Collapse(node.value,open);
			img=document.getElementById('imgID' + node.value);
			node=document.getElementById('h' + node.value);
		}
	} else if (open==false) {
		Collapse(snode,true);
		for (i=1;i<=parseInt(document.getElementById('h0').value);i++) {
			if (isChild(i,snode)) {
				Collapse(i,true);
			}
		}
	}
}
function CollapseOnly(snode,open) {
	if (open==true) {
		CollapseOnly(getRoot(snode),false);
		CollapseAll(snode,true);
	} else if (open==false) {
		Collapse(snode,false);
		for (i=1;i<=parseInt(document.getElementById('h0').value);i++) {
			if (isChild(i,snode)) {
				Collapse(i,false);
			}
		}
	}
}
function getRoot(snode) {
	var node = document.getElementById('SUB' + snode);
	var root = parseInt(snode);
	for (i=1;i<=parseInt(document.getElementById('h0').value);i++) {
		if ((isChild(root, i)) && (parseInt(document.getElementById('h' + i).value)==0)) {
			root=i;
		}
	}
	return (root);
}

function isChild(cNoeud,pNoeud) {
	var bool = false;
	if ((parseInt(cNoeud)>1) && (parseInt(pNoeud)>0)) {
		var nParent = document.getElementById('h' + cNoeud).value;
		while ((bool==false) && (parseInt(nParent) > 0)) {
			if (parseInt(nParent) == parseInt(pNoeud)) {
				bool=true
			}
			nParent = document.getElementById('h' + nParent).value;
		}
	}
	return (bool);
}

function posCurrent() {
	if(menuType==1){
		return (document.getElementById('posMenu').value);
	} else if(menuType==2) {
		var temp=location.hash;
		var bool=temp.lastIndexOf('pos=ID');
		if(bool==-1) {
			return ('');
		} else {
			i= 0;
			var pos=temp.substring(bool + 6,temp.length)
			while(isInteger(temp.substring(bool + 6,temp.length - i))==false) {
				pos=temp.substring(bool + 6,temp.length - i);
				i++;
			}
			return (pos);
		}
	}
}

function setPos(newPos,oldPos) {
	// ClassPosition est la classe de l'élément actif du menu
	var ClassPosition = 'posmenu';

	if (menuType==1) {document.getElementById('posMenu').value=newPos;}
	if (oldPos!='') {
		document.getElementById('aID' + oldPos).className=document.getElementById('h' + oldPos).alt;
	}
	document.getElementById('aID' + newPos).className=ClassPosition;
}

function isInteger(sText)
{
	var ValidChars = "0123456789";
	var isNumber=true;
	var Char;
	for (i = 0; i < sText.length && isNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			isNumber = false;
		}
	}
	return isNumber;
}

function buildMenu() {
	// <!> : Ne pas oublier les 'new' sinon il se basera toujours le même objet Node
	//       Pour les actions utiliser des : \'
	var mainMenu=new main(1);
	var node10=new addNode('Documentation',mainMenu);

	var node11=new addSubNode('Biographie',node10,'','titreSection');		
	var node12=new addSubNode('Résumé',node11,'moteur.asp?head=0&lng=fr&body=15','lien');	
	var node14=new addSubNode('Chronologie',node11,'moteur.asp?head=0&lng=fr&body=14','lien');
	var node15=new addSubNode('Distinctions',node11,'moteur.asp?head=0&lng=fr&body=16','lien');

	var node3=new addSubNode('Evènements expositions',node10,'','titreSection');		
	var node31=new addSubNode('Expositions solos',node3,'moteur.asp?head=0&lng=fr&body=12','lien');
	var node32=new addSubNode('Expositions collectives',node3,'moteur.asp?head=0&lng=fr&body=20','lien');
	var node33=new addSubNode('Performances',node3,'moteur.asp?head=0&lngf=r&body=21','lien');

	var node4=new addSubNode('Collections',node10,'','titreSection');		
	var node41=new addSubNode('Art public',node4,'moteur.asp?head=0&lng=fr&body=19','lien');
	var node42=new addSubNode('Collections publiques',node4,'moteur.asp?head=0&lng=fr&body=18','lien');
	var node43=new addSubNode('Collections d\'entreprises',node4,'moteur.asp?head=0&lng=fr&body=11','lien');

	var node5=new addSubNode('Références',node10,'','titreSection');		
	var node51=new addSubNode('Bibliographie',node5,'moteur.asp?head=0&lng=fr&body=17','lien');
	var node52=new addSubNode('Commentaires critiques',node5,'moteur.asp?head=0&lng=fr&body=23','lien');
	var node53=new addSubNode('Ecrits de l"artiste',node5,'moteur.asp?head=0&lng=fr&body=24','lien');
	
	var node6=new addNode('Galerie',mainMenu);
	var node61=new addSubNode('Accueil',node6,'moteur.asp?head=2&lng=fr&body=1','lienA');
	var node62=new addSubNode('Salle principale',node6,'moteur.asp?head=2&lng=fr&body=2&no=1','lienA');
	var node63=new addSubNode('Coin des jeunes colllectionneurs',node6,'moteur.asp?head=2&lng=fr&body=2&no=2','lienA');
	var node64=new addSubNode('Coin des connaisseurs',node6,'moteur.asp?head=2&lng=fr&body=2&no=3','lienA');
	var node65=new addSubNode('Salles des grandes collectionneurs',node6,'moteur.asp?head=2&lng=fr&body=2&no=4','lienA');
	var node66=new addSubNode('Jardin des sculptures',node6,'moteur.asp?head=2&lng=fr&body=2&no=5','lienA');
	var node67=new addSubNode('Librairie',node6,'moteur.asp?head=2&lng=fr&body=2&no=6','lienA');
	var node68=new addSubNode('Liste des prix',node6,'moteur.asp?head=2&lng=fr&body=3','lienA');

	var node7=new addNode('Agenda',mainMenu);
	var node71=new addSubNode('A l\'agenda',node7,'moteur.asp?head=1&lng=fr&body=4','lienA');
	var node72=new addSubNode('Demande d\'informations',node7,'moteur.asp?head=1&lng=fr&body=7','lienA');
	var node73=new addSubNode('A propos du site',node7,'moteur.asp?head=1&lng=fr&body=0#coord','lienA');
	var node74=new addSubNode('Nos coordonnées',node7,'moteur.asp?head=1&lng=fr&body=0#coord','lienA');
	var node75=new addSubNode('Contacter Marcel Barbeau',node7,'mailto:marcelbarbeau@yahoo.fr?subject=[Marcel Barbeau] ','lienA');
	var node76=new addSubNode('Contacter Ninon Gauthier',node7,'mailto:ninongauthier@yahoo.fr?subject=[Marcel Barbeau]','lienA');
	
	var node8=new addNode('Salles intéractives',mainMenu);
	var node81=new addSubNode('Les Salles',node8,'moteur.asp?head=2&lng=fr&body=13','lienA');
	var node82=new addSubNode('Expositions virtuelles',node8,'/expo/','lienA');
	var node83=new addSubNode('Film Barbeau libre comme  l\'art',node8,'film/','lienA');
	var node84=new addSubNode('Forum de discussion',node8,'forum/','lienA');
	
}