
// ------------------------------------------------------------------
// Работа с выпадающими меню
var elem = null, timer = 0;
function mouseOver(toShow,id,elName,toTop)
{
	var a = null;
	if (elName) {
		a = document.getElementById ? document.getElementById(elName) : document.all ? document.all[elName] : null;
	}
	
	var open;
	if(!id) return;
	if(document.getElementById) open = document.getElementById(id);
	else if(document.all) open = document.all[id];
	else return;
	
	if(!open)return;

	if(timer){
		clearTimeout(timer);
		timer=0;
	}

	if (toShow && (!open.c_state || open.c_state == 2)) {
		if(elem && open!=elem)hideNow();
		if(a) {open.style.left = menuLeft(id,a,open,toTop); open.style.top = menuTop(id,a,open,toTop);}
		elem = open;
		if (a && a.alt) {
			elem.c_a = a;
			elem.c_alt = a.alt;
			a.alt = '';
		}
		timer = setTimeout('showNow()',100);
	}
}
function mouseOut()
{
	if (timer)
		clearTimeout(timer);
	timer = setTimeout('hideNow()',100);
}

function showNow()
{
	if (elem) {
			elem.style.visibility = 'visible';
	}
}
function hideNow()
{
	if (elem) {
			elem.style.visibility = 'hidden';
	}
	elem = null;
}
function menuLeft(id,a,el,toTop) 
{
	var pos = a.offsetLeft;
	while (a.offsetParent != null) {
		a = a.offsetParent;
		pos += a.offsetLeft;
		if (a.tagName == 'BODY') break;
	}
	if (pos+el.offsetWidth>=document.body.scrollLeft+document.body.clientWidth)
		pos=document.body.scrollLeft+document.body.clientWidth-el.offsetWidth;
	if (pos<document.body.scrollLeft) pos=document.body.scrollLeft;
	return pos;
}
function menuTop(id,a,el,toTop) 
{
	var pos = a.offsetTop;
	while (a.offsetParent != null) {
		a = a.offsetParent;
		pos += a.offsetTop;
		if (a.tagName == 'BODY') break;
	} return toTop?pos-el.offsetHeight:pos+17;
}

