var nodes = new Array();
var nodesCount = -1;
var timeout = 0;
var inMenu = false;
var clmenu ="hauteur1";
if (!new_menu) var new_menu;
if(document.getElementById)  {
 var menu = document.getElementById('menu');


}


function startMenuHover() {
  if(document.getElementById)  {
    var menu = document.getElementById('menu');
if (document.getElementById('nav_secteur'))
{
/*alert ('toto');*/
menu.style.height='70px';
}
    menu.onmouseover = function (e) {
    	inMenu = true;
var clmenu=menu.className;    


}
    
    menu.onmouseout = function (e) {
      inMenu = false;
    }

	if (new_menu==1)
    var niveau2 = getElementsWithClassName('a', 'n2');
else
    var niveau2 = getElementsWithClassName('a', 'niveau-2');
    for (var i = 0; i < niveau2.length; i++) {
      onMouseOver(niveau2[i]);
      onMouseOut2(niveau2[i], nodesCount++);
    }
	if (new_menu==1)	
    var niveau3 = getElementsWithClassName('a', 'n3');
    else var niveau3 = getElementsWithClassName('a', 'niveau-3');
    for (var i = 0; i < niveau3.length; i++) {
      onMouseOver(niveau3[i]);
      onMouseOut(niveau3[i], nodesCount++);
    }
  }
}

function onMouseOver(node) {
  node.onmouseover = function(e) {
    
	var s=document.getElementsByTagName('select');
	for (i=0; i<s.length; i++) {
	s[i].style.visibility='hidden';

	} 
  
    var li = this.parentNode.parentNode;

    var items = li.parentNode.childNodes;
    for (var i = 0; i < items.length; i++) {
      var lists = items[i].childNodes;
      for (var j = 0; j < lists.length; j++) {
        var ul = lists[j];
        if (ul.nodeName == "UL") {
          items[i].className=items[i].className.replace(" over", "");
        }
      }
    }
    
    if (hasClass(li, 'niveau-2') || hasClass(li,'n2')) {
if (li.id && li.id=='nav_secteur') 
document.getElementById('nav_secteur').className=document.getElementById('nav_secteur').className.replace("cache", "Secteurs");
else if (document.getElementById('nav_secteur')) document.getElementById('nav_secteur').className=document.getElementById('nav_secteur').className.replace("Secteurs", "cache");

	if (new_menu==1)
      var niveau4 = getElementsWithClassName('li', 'n3');
      else var niveau4 = getElementsWithClassName('li', 'niveau-3');
      for (var i = 0; i < niveau4.length; i++) {
        var item = niveau4[i];
        item.className = item.className.replace(" over", "");
      }

	if (new_menu==1)
      var niveau4 = getElementsWithClassName('li', 'n4');
      else var niveau4 = getElementsWithClassName('li', 'niveau-4');

      for (var i = 0; i < niveau4.length; i++) {
        var item = niveau4[i];
        item.className = item.className.replace(" over", "");
      }


	menu=document.getElementById("menu");
	if (hasClass(li,"Secteurs")) {
	menu.className="menu_secteurs";
	} 

	else { menu.className="hauteur1";  }




    }
    
	

    var children = li.childNodes;
    for (var j = 0; j < children.length; j++) {
      var ul = children[j];
      if (ul.nodeName == "UL") {
        li.className += " over";
        break;
      }
    }
  }
}

function onMouseOut(node, index) {
	

nodes[index] = node.parentNode.parentNode;
menu=document.getElementById("menu");
  var lists = nodes[index].childNodes;
  for (var j = 0; j < lists.length; j++) {
    var ul = lists[j];
    if (ul.nodeName == "UL") {
      ul.onmouseout = function(e) {
        if (!isAncestor(ul, target(e))) {
          timeout = setTimeout("replace(" + index + ");", 2073);
        }
      }
      break;
    }
  }

}

function target(e) {
  var result;
  if (e != null) {
    result = e.relatedTarget;
  }
  else {
    result = window.event.toElement;
  }
  return result;
}

function onMouseOut2(node, index) {

	var s=document.getElementsByTagName('select');
	for (var i=0; i<s.length; i++) {
	s[i].style.visibility='visible';
	} 

menu=document.getElementById("menu");
menu.className=clmenu;
  var li = node.parentNode.parentNode;
  nodes[index] = li;
  
  nodes[index].onmouseout = function(e) {
    if (!isAncestor(li, target(e))) {
      timeout = setTimeout("replace(" + index + ");  ", 1973);
    }
  }
}

function isAncestor(parent, node) {
  if (parent == node.parentNode) {
    return true;
  }
  else if (node.parentNode != null) {
    return isAncestor(parent, node.parentNode);
  }
  return false;
}

function replace(index) {
  var li = nodes[index];
  
	if (inMenu) {

  	return;
  }

  
  var children = li.childNodes;
  for (var j = 0; j < children.length; j++) {
    var ul = children[j];
    if (ul.nodeName == "UL") {
      li.className=li.className.replace(" over", "");
      inMenu = false;
menu.className=clmenu;
	var s=document.getElementsByTagName('SELECT');
	for (i=0; i<s.length; i++) {
	s[i].style.visibility='visible';
	} 
      break;
    }
  }
var sec="";
if (sec=document.getElementById('nav_secteur')) {
if (hasClass(sec,'courant')) {
sec.className=sec.className.replace("courant"," courant  over ");
}

}

if (document.getElementById('nav_secteur'))
{
menu.className+=' menu_secteurs ';
if (new_menu==1)
document.getElementById('nav_secteur').className="Defaut  n2  Secteurs  courant over ";
else document.getElementById('nav_secteur').className="Defaut  niveau-2  Secteurs  courant over ";
}

}


function getElementsWithClassName(elementName, className) {
	var allElements = document.getElementsByTagName(elementName);
	var elemColl = new Array();
	for (var i = 0; i< allElements.length; i++) {
		if (hasClass(allElements[i], className)) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}


function hasClass(object, className) {
	if (!object.className) return false;
	return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
}




