function headerMenuHandler(eThis, action)
{
	/*if (action == 'hover' && eThis.className == 'hmLeft')
	{
		hmh_prev_class = eThis.className;
		eThis.className = 'hmLeftHover';
	}
	else if (action == 'hover')
	{
		hmh_prev_class = eThis.className;
		eThis.className = 'hmFieldHover';
	}
	
	if (action == 'out')
	{
		eThis.className = hmh_prev_class;
	}*/
}
call_eThis = null;
call_menu_name = null;
call_menu_type = null;
menu_timeout = null;
function headerMenuPop(eThis,menu_name, menu_type)
{
	call_eThis = eThis;
	call_menu_name = menu_name;
	call_menu_type = menu_type;
	if (enable_hide_menu)
	{clearTimeout(menu_timeout);}
	//alert(22);
	enable_hide_menu = false;
	menu_timeout = setTimeout('headerMenuPop_call();',100);
	//headerMenuPop_call();
}

menu_storage_skip = new Array();
function headerMenuPop_call()
{
	eThis = call_eThis;
	menu_name = call_menu_name;
	menu_type = call_menu_type;
	
	if (enable_hide_menu)
	{
		//alert(11); 
		return false;
	}
	
	if (menu_type == undefined)
		menu_type = 1;

	pos = getAbsolutePos(eThis);

	if (cpx > pos.x && cpx < pos.x+eThis.offsetWidth && cpy > pos.y && cpy < pos.y+eThis.offsetHeight) // Ибо иногда не отлавливает увод курсора
	{
		// EMPTY
	}
	else
	{
		//return false;
	}
	menu_name = (menu_name==11111)? 89972 : menu_name;	
	m = menu_storage[menu_name];
	out = '<div style="width: 99%;   margin-right: 1px;">'+(menu_name==89972 ? '<table cellpadding="0" cellspacing="2px" width="100%"><tr>'+'<td colspan="2"><a href="/allgoods/" style="color: white; font-weight: bold; text-decoration: underline;">Все категории</a></td><td colspan="2"><a href="/departments/" style="color: white; font-weight: bold; text-decoration: underline;">Отделы больницы</a></td></tr><tr><td>': '')+'<ul class="hmList">';
	skipped=0;
	
	
	for (i=0; i<m.length; i++)
	{
		if (m[i] == undefined)
			continue;

		is_show = true;
		
		if (menu_name==89972 && i>(m.length/2)-1 && skipped==0)
		{
			out += '</ul></td><td><ul class="hmList">';
			skipped=1;
		}
		for (ii=0; ii<menu_storage_skip.length; ii++)
		{
			if (menu_storage_skip[ii] == m[i][1])
			{
				is_show = false;
			}
		}
		
		if (is_show)
		{
			out += '<li onMouseOver="this.className=\'hmHover\'" onMouseOut="this.className=\'hmli\'" onсlick="location=\''+m[i][1]+'\';" class="hmli"><a class="hmlink" href="'+m[i][1]+'">'+m[i][0]+'</a></li>';
		}
	}
	if (menu_name==89972)
	{
		skipped=0;
		out += '</ul></td><td><ul class="hmList">';
		menu_name=11111;
		m = menu_storage[menu_name];
		
		for (i=0; i<m.length; i++)
	{
		if (m[i] == undefined)
			continue;

		is_show = true;
		
		if (menu_name==11111 && i>(m.length/2)-1 && skipped==0)
		{
			out += '</ul></td><td><ul class="hmList">';
			skipped=1;
		}
		for (ii=0; ii<menu_storage_skip.length; ii++)
		{
			if (menu_storage_skip[ii] == m[i][1])
			{
				is_show = false;
			}
		}
		
		if (is_show)
		{
			out += '<li onMouseOver="this.className=\'hmHover\'" onMouseOut="this.className=\'hmli\'" onсlick="location=\''+m[i][1]+'\';" class="hmli"><a class="hmlink" href="'+m[i][1]+'">'+m[i][0]+'</a></li>';
		}
	}
	
	out += '</ul></td></tr></table></div>';
	
	}
	
	else
	{
	out += '</ul></div>';
	}
	
	hm = document.getElementById('header_menu');
	pos_hm = getAbsolutePos(hm);
	
	allowed_width = pos_hm.x+hm.offsetWidth;
	//page_width = document.body.clientWidth
	
	pop_x = pos.x;
	pop_y = pos.y+eThis.offsetHeight;
	
	pop = document.getElementById('header_menu_pop');
	pop.style.overflow='hidden';
	if (menu_type == 2)
		pop.className = 'headerMenuPop2';
	else
		pop.className = 'headerMenuPop';
	pop.innerHTML = out;
	pop.style.display = '';
	
	pop.style.top = pop_y;
		
	if ((pop_x+pop.offsetWidth)>978+((screen.width-978)/2))
	{
	pop.style.right=((screen.width-(pop_x+eThis.offsetWidth))-4)+"px"; 
	pop.style.left='';
	}
	else
	{
	pop.style.left = (menu_name!=11111 &&  (pop_x+pop.offsetWidth)<978+((screen.width-978)/2) )? pop_x+"px" : (((screen.width-978)/2+970)-pop.offsetWidth)+"px";
	pop.style.right='';
	}
	pop_width = 'auto';//pop.offsetWidth;
	if (allowed_width < pop_x+pop_width)
	{
			pop_x = pos.x + eThis.offsetWidth - pop.offsetWidth;
	}
	
	if (menu_type == 2)
	{
		pop_x = pop_x+7;
		pop_y = pop_y+5;
	}
	//alert(pop.style.left);
	//pop.style.top = pop_y;
	//pop.style.left = pop_x;
}

timerID = null;
function headerMenuPopHide()
{
	enable_hide_menu = true;
	clearTimeout(timerID);
	timerID = setTimeout('headerMenuPopHideDo();',4);
	
	
}

function headerMenuPopHideDo(im)
{
	if (!im)
			im=false;
	
	
	main_ms=document.getElementById('header_menu').getElementsByTagName('table')[0].rows[0].cells;
	for (y=0; y<main_ms.length; y++)
	{
		if (document.getElementById('header_menu_pop').style.display != 'none' || y==0)
	{
		if (main_ms[y].className=='hmtd_o')
		{
			main_ms[y].className='';
			hide_divs(main_ms[y],false);
			if (main_ms[y].getElementsByTagName('img')[0] && im==false)
			{
				main_ms[y].getElementsByTagName('img')[0].src='/i/header1/menu_ar_o.png';
			}
			break;
		}
	}
	}
	
	if (enable_hide_menu)
	{
		pop = document.getElementById('header_menu_pop');
		pop.style.display = 'none';
	}
	
	
}




enable_hide_menu = true;
