var cm         = null;
var hide_delay = 70;
var tstat      = 0;
var timer1     = null;
var timer2		= null;

// Определяем браузер пользователя
var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

// Функция отображающая и скрывающая слои

function switchDiv(objElement,bolVisible){
  if(isNS4||isIE4) {
    if(!bolVisible) {
      objElement.visibility ="hidden"
    } else {
      objElement.visibility ="visible"
    }
  } else if (isIE5 || isNS6) {
    if(!bolVisible) {
       objElement.style.display = "none";
    } else {
        objElement.style.display = "";
    }
  }
  return 1;
}

// Функция возвращающая значение указанного ей свойства объекта.

function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos
}

// Функция выдаёт объект с указанным ей названием.

function getelementbyid(myid) {
  var objElement;
  if (isNS4){
     objElement = document.layers[myid];
  }else if (isIE4) {
     objElement = document.all[myid];
  }else if (isIE5 || isNS6) {
     objElement = document.getElementById(myid);
  }
  return(objElement);
}

// Функция отображающая|скрывающая слои.
function show(el,m) {
 if (cm!=null) {
   switchDiv(cm,false);
 }
 if (m!=null) {
   if (getelementbyid(m)) {
     m=getelementbyid(m);
     m.style.left = getPos(el,"Left")+"px";
     m.style.top =  getPos(el,"Top")+el.offsetHeight+"px";
     switchDiv(m,true);
     cm=m;
   }
	timer2 = setTimeout("hidemenu()",3000);
 }
}

// Функция "закрывающая" меню.
function hidemenu(stat) {
	if (stat == 2)
		hide_delay = 1000;
  timer1 = setTimeout("show(null,null)",hide_delay);
  //tstat  = 1;
  return 1;
}

// Функция останавливающая таймер запущенный прошлой функцией.
function cancelhide() {
  //if (tstat==1) {
    clearTimeout(timer1);
    //tstat=0;
  //}
	clearTimeout(timer2);

  return 1;
}
