// ----------------------------------------------
var lastE='';
// ----------------------------------------------
function onMouseOut(e) {

if (e.className.match(/(^| )menuitem($| )/)) {
  var cn="mouseover";
  if (e.parentNode.className.match(/(^| )menuroot($| )/)) {
    var iii=new RegExp("(^| )rootmouseover rootmouseover" + e.id +"($| )", "g");
	
//    alert(iii);
    e.className=e.className.replace(iii, ' '); //удаляем класс
    } else {
      var iii=new RegExp("(^| )mouseover mouseover" + e.id + "($| )", "g");
      e.className=e.className.replace(iii, ' '); //удаляем класс
      };
  e.className=e.className.replace(/\s+$/, ''); //удаляем вконце пробелы
//   e.className+=" mouseout"; //добавляем новый класс к элементу
   };
};
// ----------------------------------------------
function onMouseOver(e) {
if (typeof(e) == 'undefined') {return};
if (typeof(e.className)=='undefined') {return};
if (e.className.match(/(^| )menuitem($| )/)) {
//  e.className=e.className.replace(/(^| )mouseout($| )/, ' '); //удаляем класс из списка классов, назначенных элементу
//  e.className=e.className.replace(/\s+$/, ''); //удаляем вконце пробелы

  var cn="mouseover mouseover" + e.id;
  if (e.parentNode.className.match(/(^| )menuroot($| )/)) {cn="rootmouseover rootmouseover" + e.id};
  e.className+=" " + cn; //добавляем новый класс к элементу
  };
//------------------------

var isNew=1;
var e2=lastE;
while (e2) {
    if (/(^| )menuroot( |$)/.test(e2.className)) {break};
    if (e2==e) {isNew=0; return;};
    e2=e2.parentNode;
    };

if (lastE!='') {
    //Скрыть всех своих childrenов (1 поколение)
    if (typeof(lastE.childNodes)!='undefined') {
      for(var i = 0; i < lastE.childNodes.length; i++){
	if (/(^| )menulist( |$)/.test(lastE.childNodes[i].className)) {
		lastE.childNodes[i].style.display="none";
		};
	};
      };
    //Скрыть себя и всех своих предков (все поколения)
    while (lastE) {
	if (/(^| )menuroot( |$)/.test(lastE.className)) {break};
	if (/(^| )menulist( |$)/.test(lastE.className)) {
		lastE.style.display="none";
		}; 
	lastE=lastE.parentNode;
	};
    };

lastE=e;

if (/(^| )menuitem( |$)/.test(e.className)) {} else {return};

var zi=100;

//Показать всех своих childrenов (1 поколение)
if (typeof(e.childNodes)!='undefined') {
  for(var i = 0; i < e.childNodes.length; i++){
   if (typeof(e.childNodes[i].style)!='undefined') {
      e.childNodes[i].style.display="block";
      e.childNodes[i].style.zIndex=zi;
      };
    };
  };

zi--;

//Показать себя и всех своих предков (все поколения)
var e2=e; 
while (e2) {
   if (/(^| )menuroot( |$)/.test(e2.className)) {break};
   if (typeof(e2.style)=='undefined') {break};

   e2.style.display="block";
   e2.style.zIndex=zi;
   zi--;

   for(var i = 0; i < e2.parentNode.childNodes.length; i++){
     if ((e2.parentNode.childNodes[i]!=e2)&&(typeof(e2.parentNode.childNodes[i].style)!='undefined')) {
       e2.parentNode.childNodes[i].style.display="block";
       e2.parentNode.childNodes[i].style.zIndex=zi;
       };
     };
   zi--;

   e2=e2.parentNode;
   };

};
// ----------------------------------------------
// ----------------------------------------------
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
// ----------------------------------------------
var timer = null;
// ----------------------------------------------
function initEvents() {
var obj = getElementsByClass('menuitem',null,null);
for(var i=0;i<obj.length;i++){
   obj[i].onmouseover=function() {onMouseOver(this)}
   obj[i].onmouseout=function() {onMouseOut(this)};
//   obj[i].onclick=function() {var e=document.getElementById('emptyDiv'); onMouseOver(e);};
   obj[i].onclick=function() {onMouseOver(document.body);};
   };

var obj = getElementsByClass('menuroot',null,null);
for(var i=0;i<obj.length;i++){
   obj[i].onmouseout = function() {
//       object = {func: function() {var e=document.getElementById('emptyDiv'); onMouseOver(e); }  };
       object = {func: function() {onMouseOver(document.body); }  };
       timer = window.setTimeout(function() {object.func.call(object)}, 100); 
       };
   obj[i].onmouseover = function() { window.clearTimeout(timer); }
   };


};
// ----------------------------------------------

//document.write("<div id='emptyDiv'></div>");
initEvents();

