// Menu deroulant par Griboval Cyril
//structure html :  div#navsite ->  div -> h2 + ul -> li -> a
//    sous-menu  :  div#navsite ->  div -> h2 + ul -> li(lastchild) -> div -> h3 + ul -> li -> a
// evenement (js/css) :  active , focus , blur , out , over , click 
// activation  : window->onload
	menuvert = function() {
	var subnode;
		if (document && document.getElementById) 
	{
		lemenu = document.getElementById("navsite");
		cleanWhitespace(lemenu); /* pour mettre tout les navs d'accord sur le parcours du dom */
		lecontenu = document.getElementById("texte");
		cleanWhitespace(lecontenu); /* pour mettre tout les navs d'accord sur le parcours du dom */		
		lecontenu.lastChild.style.padding='0 0 2em';
	var liens = lemenu.getElementsByTagName('A');
	for (var ii = 0 ; ii < liens.length ; ++ii)  {
	liens[ii].onfocus=function()  
					{
					
  					show(this);
   					}		
	liens[ii].onblur=function() 
					{

  					hide(this);					
   					}
				}
var sousmenus = lemenu.getElementsByTagName('DIV');
	for (var iii = 0 ; iii < sousmenus.length ; ++iii)  {
	
	if(sousmenus[iii].parentNode.nodeName=='LI'){
	sousmenus[iii].childNodes[1].lastChild.childNodes[0].onblur=function() 
					{
  					this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(" open", "");
 					this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className='';

					this.parentNode.parentNode.parentNode.style.position='relative';
					this.parentNode.parentNode.style.left='-9999px';	
					hide(this.parentNode.parentNode.parentNode);
					//hide(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode);

					
   					}

					sousmenus[iii].onfocus=function()  
					{
					
					show(this);
					
					}
					
				
				}
}				
		for (i=0; i<lemenu.childNodes.length; i++) 
		{
			node = lemenu.childNodes[i];
			
			
			if (node.nodeName=="DIV") 
				{	
  					node.onfocus=function() 
					{

					this.style.position='relative';				
					this.className=" open";					
  					opene(this);
					this.previousSibling.className=""	;	
					this.previousSibling.previousSibling.className=""	;
   					}
					node.onmouseover=function() 
					{					
					this.style.position='relative';
					this.className+=" open";
					opene(this);
  					}
									
					node.onblur=function() 
					{
  					this.className="open blur";							
					this.parentNode.lastChild.className="";
	
  					}		
					
  					node.onmouseout=function() 
					{
					close(this);
					this.style.position='static';
					this.className="";
					}
   				}
  		}
 	}
}
function opene(ele) {
			cleanWhitespace(ele);
		for (i=0; i<ele.childNodes.length; i++) 
		{
			subnode = ele.childNodes[i];
			if (subnode.nodeName=="UL") 
				{
				subnode.style.left='117px';
				if (subnode.previousSibling.nodeName=='H3') {subnode.style.left='20px';}
				}
		}
}
function close(ele,etat) {
			cleanWhitespace(ele);
		for (i=0; i<ele.childNodes.length; i++) 
		{
			subnode = ele.childNodes[i];
			if (subnode.nodeName=="UL") 
				{
				subnode.style.left='-9999px';	
				}
		}

}
function show(subele) {
subele.parentNode.parentNode.style.left='117px';
if (subele.parentNode.parentNode.parentNode.className=='sm') {subele.parentNode.parentNode.style.left='20px';}
subele.parentNode.parentNode.parentNode.className=subele.parentNode.parentNode.parentNode.className+=" open";
subele.parentNode.parentNode.parentNode.style.position='relative';

}
function hide(subele) {
subele.parentNode.parentNode.style.left='-9999px';
subele.parentNode.parentNode.parentNode.style.position='static';
subele.parentNode.parentNode.parentNode.className=subele.parentNode.parentNode.parentNode.className.replace(" open", "");


}
function cleanWhitespace(node)
{
  for (var i=0; i<node.childNodes.length; i++)
  {
    var child = node.childNodes[i];
    if(child.nodeType == 3 && !/\S/.test(child.nodeValue))
    {
      node.removeChild(child);
      i--;
    }
    if(child.nodeType == 1)
    {
      cleanWhitespace(child);
    }
  }
  return node;
}
window.onload=menuvert;
