var isIE = document.all ? true : false;

function startMenu(sMenuId){
	var menu = document.getElementById(sMenuId);
	//menu.normalize();
	
	var dds = menu.getElementsByTagName('dd');
	for( var i=0; i<dds.length; i++ ){
		var dd_open = false;
		
		var ul = first_child(dds[i]);
		if( ul && ul.nodeName=='UL' ){
			
			var niv2li = first_child(ul);
			while( niv2li ){

				var niv3 = last_child(niv2li);
				if( niv3.nodeName=='A' ){
					// Pas de niveau 3
					if( !dd_open )
						dd_open = isCurrentPage( last_child(niv2li) );
				}else if( niv3.nodeName=='UL' ){
					// Menu de niveau 3
					ul_open = false;
					var niv3a = niv3.getElementsByTagName( 'a' );
					for( var j=0; j<niv3a.length && !ul_open; j++ ){
						if( isCurrentPage(niv3a[j]) )
							dd_open = ul_open = true;
						niv3a[j].onclick = function(){
							window.location.href = this.href;
							this.parentNode.parentNode.parentNode.cancelClick = true;
							this.href = '';
							return false;
						}
					}
					
					// Mets le script qui ouvre/ferme le menu sur le LI de niveau 2
					niv3.style.display = ul_open ? 'block' : 'none';
					niv2li.onclick = function(){
						if( !this.cancelClick )
							last_child( this ).style.display = last_child( this ).style.display=='block' ? 'none' : 'block';
					}
				}
				
				niv2li = node_after( niv2li );
			}
			
		}
		dds[i].style.display = dd_open ? 'block' : 'none';
		
		// Attache le script d'ouverture/fermeture au dd
		node_before(dds[i]).onclick = function(){
			var after = node_after(this);
			if( after ) after.style.display = after.style.display=='block' ? 'none' : 'block';
		}
	}
}
function isCurrentPage(a){
	if( isIE && window.location.href==a.href ){
		return true;
	}else if( !isIE && window.location.href.search(a.attributes['href'].value)>=0  ){
		return true;
	}
	return false;
}

window.onload = function(){ startMenu('menu'); };