var jshover = function()
{
	var menuDiv = document.getElementById("horizontal-multilevel-menu")
	if (!menuDiv)
		return;

	var sfEls = menuDiv.getElementsByTagName("li");

	for (var i=0; i<sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function()
		{
			this.className+=" jshover";
		}
		sfEls[i].onmouseout = function() 
		{
			this.className = this.className.replace(new RegExp(" jshover\\b"), "");
		}
	}
}

if (window.attachEvent) 
	window.attachEvent("onload", jshover);

function setClassName(cn)
{
	cn = cn.replace(new RegExp(" jshover\\b"), "");
}

var TopMenuHandler = {
	
	activeButton: null,
	activeMenu: null,
	activeMenuPos: null,
	shadow: null,
	currentEvent: null,
	
	ShowShadow: function(id){
		var div = document.getElementById(id);
		this.activeMenu = div;
		this.activeButton = document.getElementById('img_' + id);
		var pos = GetRealPos(div);
		this.activeMenuPos = GetRealPos(div);
		var zIndex = 500;
		var dxShadow = 3;
		
		if(this.shadow != null)
			this.shadow.style.visibility = 'hidden';
	
		if(IsIE() && this.shadow != null)
		{
			this.shadow = document.createElement("DIV");
			this.shadow.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/layout/shadow.png',sizingMethod='scale')";
		}
		else
		{
			this.shadow = document.createElement("IMG");
			this.shadow.src = '/images/layout/shadow.png';
		}
	
		this.shadow.id = div.id+'_shadow';
		this.shadow.style.position = 'absolute';
		this.shadow.style.zIndex = zIndex-2;
		this.shadow.style.left = '-1000px';
		this.shadow.style.top = '-1000px';
		this.shadow.style.lineHeight = 'normal';
		document.body.appendChild(this.shadow);
		
		this.shadow.style.width = div.offsetWidth+'px';
		this.shadow.style.height = div.offsetHeight+'px';
		this.shadow.style.left = parseInt(pos["left"])+dxShadow+'px';
		this.shadow.style.top = parseInt(pos["top"])+dxShadow+'px';
		this.shadow.style.visibility = 'visible';
		
		document.onmousemove = this._menuHandler;
	},
	
	HideShadowOnButtonOut: function() {
	    e = TopMenuHandler.currentEvent;
	    if(e)
	    {
		if(e.clientY < TopMenuHandler.activeMenuPos["top"]-34)
		{
			document.onmousemove = null;
			TopMenuHandler.shadow.style.visibility = 'hidden';
		}

	    }
	},
	
	_menuHandler: function(e) {
	    e = e ? e : window.event;
	    TopMenuHandler.currentEvent = e;
	    var target = e.target || e.srcElement;
	    
	    if(target == TopMenuHandler.activeButton)
	    	return;

	    if(e.clientX < TopMenuHandler.activeMenuPos["left"]
	    	|| e.clientX > TopMenuHandler.activeMenuPos["right"]-1
	    	|| e.clientY < TopMenuHandler.activeMenuPos["top"]
	    	|| e.clientY > TopMenuHandler.activeMenuPos["bottom"]-1)
	    {
			TopMenuHandler.shadow.style.visibility = 'hidden';
			document.onmousemove = null;
	    }
	}
}

function GetRealPos(el)
{
	if(!el || !el.offsetParent)
		return false;

	var res = Array();
	res["left"] = el.offsetLeft;
	res["top"] = el.offsetTop;
	var objParent = el.offsetParent;

	while(objParent && objParent.tagName != "BODY")
	{
		res["left"] += objParent.offsetLeft;
		res["top"] += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}

	res["right"] = res["left"] + el.offsetWidth;
	res["bottom"] = res["top"] + el.offsetHeight;
	
	return res;
}

function IsIE()
{
	return (document.attachEvent && !IsOpera());
}
function IsOpera()
{
	return (navigator.userAgent.toLowerCase().indexOf('opera') != -1);
}