	
	var backgroundColors = Array('#BBBBBB', '#AAAAAA', '#999999', '#888888', '#777777', '#666666');
	var borderColors = Array('blue', 'red');
	
	var selectedMenuItem = Array();
	selectedMenuItem[0] = null;
	
	

	function clearMenu()
	{
		if(selectedMenuItem)
		{
			while(selectedMenuItem.firstChild) 
      				selectedMenuItem.removeChild(selectedMenuItem.firstChild);
			//selectedMenuItem.style.backgroundColor = backgroundColors[selectedMenuItem.indent];			
			selectedMenuItem.selected = false;
			selectedMenuItem.className = "menuItem";
		}
		
	}
	
	

	function menuItemMouseover(e)
	{
		//if(!sender.selected)
		//	sender.className = "menuItemHover";
	
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			if(e.className == "menuItem")
				e.className = "menuItemHover";
		}
		
		
	}
	
	function menuItemMouseout(e)
	{

		if(navigator.appName == "Microsoft Internet Explorer")
		{
			if(e.className == "menuItemHover")
				e.className = "menuItem";
		}

			
	}
	
	
	var running = 0;
	var queue = 0;
	
	var cache = new Array();
	
	function menuItemSelect(e, id, childs)
	{
		if(!pageLoaded)
			return;
		if(childs==0)
			return;

		var sender = document.getElementById('i'+id);
		var indent = sender.parentNode.indent;
		
		localSelectedMenuItem = selectedMenuItem[indent];
		
		
		
		
		/*if (!e) 
			e = window.event;
		if (e.target) 
			sender = e.target;
		else if (e.srcElement) 
			sender = e.srcElement;
		if (sender.nodeType == 3) 
			sender = sender.parentNode;
		*/
		
		if (localSelectedMenuItem) 
		{
			//alert(id);
			if(localSelectedMenuItem.className == "selectedMenuItem")
			{
		
				localSelectedMenuItem.removeChild($('#'+localSelectedMenuItem.id+" .activeSubmenu")[0]);	
				localSelectedMenuItem.removeChild($('#'+localSelectedMenuItem.id+" .h")[0]);
				var i;
				//alert(selectedMenuItem.length);
				//alert(indent+1);
				for(i = indent+1; i < selectedMenuItem.length; i++) 
					selectedMenuItem[i] = null;
			}
			if(localSelectedMenuItem.className == "unactiveSelectedMenuItem")
			{
				localSelectedMenuItem.removeChild($('#'+localSelectedMenuItem.id+" .submenu")[0]);	
				localSelectedMenuItem.removeChild($('#'+localSelectedMenuItem.id+" .unactiveh")[0]);
				var i;	
				//alert(selectedMenuItem.length);
				//alert(indent+1);
				for(i = indent+1; i < selectedMenuItem.length; i++) 
					selectedMenuItem[i] = null;	
			
			}
			
			
			
			
		//	if((tmp = $('#'+localSelectedMenuItem.id+" .submenu")).length > 0)
		//	{
		//		localSelectedMenuItem.removeChild(tmp);		
				
		//	}
		//	else
		//	if((tmp = $('#'+localSelectedMenuItem.id+" .activeSubmenu")).length > 0 )
		//		alert(tmp.length);
			//	localSelectedMenuItem.removeChild(tmp[0]);
		//	if(tmp = $('#'+localSelectedMenuItem.id+" .h")[0])
		//		localSelectedMenuItem.removeChild(tmp);
			

			//localSelectedMenuItem.removeChild($('#'+localSelectedMenuItem.id+" .h")[0]);
			//while(localSelectedMenuItem.firstChild)
			//{	
			//	localSelectedMenuItem.removeChild(localSelectedMenuItem.firstChild);
			//}
			
			//paskudna optymalizacja ;p
			
			/*to dziala*/
			//localSelectedMenuItem.removeChild(localSelectedMenuItem.childNodes[4]);
			//localSelectedMenuItem.removeChild(localSelectedMenuItem.childNodes[3]);
			
			localSelectedMenuItem.className = "menuItem";

			localSelectedMenuItem.selected = false;
			
			/*----*/
			
			
		}
		
	
		var isIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		
		//sender.parentNode.style.borderColor = borderColors[0];
		//if(sender.parentNode.parentNode.style)
		//	sender.parentNode.parentNode.style.borderColor = borderColors[0];
		
		sender.parentNode.className = "submenu";
		
		
		if(sender.parentNode.id != "menuRoot")
		{
			sender.parentNode.parentNode.className = "unactiveSelectedMenuItem";
			var h = $("#" + sender.parentNode.parentNode.id + " .h")[0];
			if(h)
				h.className = "unactiveh";
		}
		div = document.createElement("div");
				
		div.indent = indent + 1;
		div.className = "activeSubmenu";
		div.style.display = "none";
		div.style.left = (sender.offsetWidth - 1).toString() + "px";
		div.style.marginTop = "-1px";
	
		
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			if(isIE6)
			{
			    div.style.left = (sender.offsetWidth - 5 ).toString() + "px";
			    div.style.marginTop = "0";
			}
			else
			    div.style.left = (sender.offsetWidth).toString() + "px";
			//div.style.marginTop = "0";
		}
		
		//div.style.backgroundColor = backgroundColors[div.indent];
	//div.style.borderColor = borderColors[1];
		div.id = 'sm'+id;

	
		sender.className = "selectedMenuItem";
		//sender.style.backgroundColor = backgroundColors[div.indent];
	
		sender.selected = true;
		
		h = document.createElement("div");	
		h.className = "h";
		h.style.left = (sender.offsetWidth - 3).toString() + "px";
		h.style.top = "0";
		h.style.height = "100%";
		//h.style.border = "1px solid red";
		if(navigator.appName == "Microsoft Internet Explorer")
		{
		    if(isIE6)
		    {
			h.style.marginTop = "1px";
			h.style.marginLeft = "-4px";
			h.style.left  = (sender.offsetWidth - 3).toString() + "px";
		    
		    }
		    else
		    	h.style.left  = (sender.offsetWidth - 2).toString() + "px";
		    if(indent >0)
			h.style.height = "17px";
		    
		}
		
		
		//h.style.backgroundColor = backgroundColors[div.indent];
	
		sender.appendChild(div);
		sender.appendChild(h);
		
		selectedMenuItem[parseInt(indent)] = sender;

		if(cache[id] && cache[id] != "")
		{
			document.getElementById('sm'+id).innerHTML = cache[id];
			document.getElementById('sm'+id).style.display='block';
		}	
		else
		{
			
			if(id == running)
				return;
			running = id;
			
			if(queue > 1)
				return;
			
			queue++;

			var url = baseUrl + '/category/getchilds';
			
			
		

			
			
		    $.get(url, {kat_parent: id}, function(data) {
					cache[id] = data;
					if(document.getElementById('sm'+id))
					{
						document.getElementById('sm'+id).innerHTML = data;
						document.getElementById('sm'+id).style.display ='block';
						
					}
					queue--;
					});
		}

		if (!e)
			var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) 
			e.stopPropagation();


	}
	
	function closeMenu(e)
	{
		if (!e)
			var e = window.event;
			
			
			
			
		e.cancelBubble = true;
		if (e.stopPropagation) 
			e.stopPropagation();
	
		var target;
	
		if (e.target) target = e.target;
			else if (e.srcElement) target = e.srcElement;
		

		if(target.className != "menuItem"
			& target.className != "menuItemHover"
			& target.className != "menuItemContent"
			& target.className != "menuItemContentCh"
			& target.className != "menuItemContentA")

		{
		
			var menuRoot = document.getElementById('menuRoot');
			//alert(menuRoot.innerHTML);
			for(i=0;i<menuRoot.childNodes.length;i++)
			{
				//if(menuRoot.childNodes[i].childNodes.length > 3)
				//{
				
					if(menuRoot.childNodes[i].className == "selectedMenuItem")
					{
						menuRoot.childNodes[i].removeChild($("#" + menuRoot.childNodes[i].id + " .activeSubmenu")[0]);	
						menuRoot.childNodes[i].removeChild($("#" + menuRoot.childNodes[i].id + " .h")[0]);
					}
					
					if(menuRoot.childNodes[i].className == "unactiveSelectedMenuItem")
					{
						menuRoot.childNodes[i].removeChild($("#" + menuRoot.childNodes[i].id + " .submenu")[0]);	
						menuRoot.childNodes[i].removeChild($("#" + menuRoot.childNodes[i].id + " .unactiveh")[0]);
					
					}
					

				

					menuRoot.childNodes[i].selected = false;
					menuRoot.childNodes[i].className = "menuItem";
					
				//}
			}
			var j;	
			for(j = 0; j < selectedMenuItem.length; j++) 
				selectedMenuItem[j] = null;	
			//clearMenu();
		}
	}