var MenuService=null;
var MenuService_debug=null;
var MenuService_SetEventsOnCurrentItem=0;
/* Параметр	MenuService_SetEventsOnCurrentItem
	Определяет обработку события перекрытия (over)
	Для текущих разделов.
	MenuService_SetEventsOnCurrentItem=1 - событие обрабатывается как и у осталных разделов.
	MenuService_SetEventsOnCurrentItem=0 - обработка события отключена.
*/
function CMenuService(pDebug)
{
	var me=this;
	var debug=pDebug;
	var f=0;
	var OldSetOver=new Array();
	var fLockOver=0;
	CMenuService.prototype.MSG=function(Mes)
	{
		if(!debug) return;
		debug.MSG(Mes);
	}
	CMenuService.prototype.SetOver=function(El)
	{
		El.OldClass=El.style.className;
		El.className='menu_over';
		me.MSG(El.OldClass+' '+El.className);
	}
	CMenuService.prototype.SetOver4=function(El)
	{
		me.ClearOver3(null);
		El.className='menu_over';
		OldSetOver.push(El);
		me.MSG('SetOver4 '+OldSetOver.length());
	}
	CMenuService.prototype.SetOver3=function(e)
	{
		if(fLockOver) return;
		fLockOver=1;
		var ev=e;
		var el=this;
		
		if(window.event)
		{
			ev=window.event;
			el=ev.srcElement;
			//Вызывает торможение в IE зато отображает всё корректно.
			//	
			/*if(ev.toElement.tagName=='LI') el=ev.toElement;
			if(ev.fromElement.tagName=='LI') el=ev.fromElement;
			if (el.tagName!='LI')
			{
				var tmpEl=el;
				while (tmpEl.tagName!='LI' && tmpEl.tagName!='UL')
					tmpEl=tmpEl.parentNode;
				if(tmpEl.tagName=='LI') el=tmpEl;
			}
			*/
		}
		while (OldSetOver.length>0) me.ClearOver(OldSetOver.pop());
		//if(OldSetOver) me.ClearOver(OldSetOver)
		el.OldClass=el.className;
		el.className='menu_over';
		OldSetOver.push(el);
		me.MSG('SetOver3 '+el.OldClass+' '+el.className);
	}
	CMenuService.prototype.SetOver4=function(el)
	{
		if(fLockOver) return;
		fLockOver=1;
		while (OldSetOver.length>0) me.ClearOver(OldSetOver.pop());
		//if(OldSetOver) me.ClearOver(OldSetOver)
		el.OldClass=el.className;
		el.className='menu_over';
		OldSetOver.push(el);
		me.MSG('SetOver3 '+el.OldClass+' '+el.className);
	}
	CMenuService.prototype.ClearOver=function(El)
	{
		if(typeof(El.OldClass)!='undefined')
			El.className=El.OldClass;
		else
			El.className='';
		me.MSG('Clear '+El.OldClass+' '+El.className);
	}
	
	CMenuService.prototype.ClearOver3=function()
	{
		fLockOver=0;
		me.MSG(OldSetOver.length);
		while (OldSetOver.length>0) me.ClearOver(OldSetOver.pop());
	}	
	CMenuService.prototype.AddEvents=function()
	{
		var ul=getElementsByClassName('menu_root');
		var i,j,li;
		for(i=0;i<ul.length;i++)
			for(j=0;j<ul[i].childNodes.length;j++)
				if(ul[i].childNodes[j].tagName=='LI')
				{
					
					//addEvent(ul[i].childNodes[j], 'mouseover', me.SetOver3, false);
					//addEvent(ul[i].childNodes[j], 'mouseout', me.ClearOver3, false);
					ul[i].childNodes[j].onmouseover=new Function("return MenuService.SetOver4(this);");
					//ul[i].childNodes[j].onmouseover=me.SetOver3;
					ul[i].childNodes[j].onmouseout=me.ClearOver3;
					//ul[i].childNodes[j].onmouseover=new Function("","return MenuService.SetOver4(this);");
					//ul[i].childNodes[j].onmouseout=new Function("","return MenuService.ClearOver3();");
				}
	}
	CMenuService.prototype.SetActiveMenu=function()
	{
		  if(!rubricl2) rubricl2='';
		  if(!rubricl3) rubricl3='';
		  if(!rubricl4) rubricl4='';
		  if ( rubricl2 || rubricl3 || rubricl4 )
		  {
		  var menu=document;
			  if (menu && menu.getElementsByTagName('LI'))
			  {
				var lis = menu.getElementsByTagName('LI');
				for (var i=0; i<lis.length; i++)
				{
					if (lis[i].className == rubricl2 || lis[i].className == rubricl3 || lis[i].className == rubricl4)
					{
					   lis[i].className='menu_active';
					   lis[i].onmouseover=new Function('');
					   lis[i].onmouseout=new Function('');
					   lis[i].onclick=new Function('');
					}
				}
			  }
		  }
	}
}
function MenuService_InitDebug()
{
	//MenuService_debug=new CDebug(500,500,300,0,'MenuService',2000);
	MenuService=new CMenuService(MenuService_debug);
	if(MenuService_SetEventsOnCurrentItem)
	{
		MenuService.SetActiveMenu();
		MenuService.AddEvents();	
	}
	else
	{
		MenuService.AddEvents();	
		MenuService.SetActiveMenu();
	}
}

addEvent(window, 'load', MenuService_InitDebug, false);