var parentElement1 = "", parentElement2 = "";

function onMenuHover(el, cl) {
	if (!cl)
		cl = "MENU";

	el.className=cl+'_HOVER';
	
	if (el.rows[0].cells[0].children.length)
		el.rows[0].cells[0].firstChild.className=cl+'_HOVER';
	else
		el.rows[0].cells[0].className=cl+'_HOVER';
	
	if (el.rows[0].cells.length==2)
		el.rows[0].cells[1].firstChild.src= el.rows[0].cells[1].firstChild.src.replace("arrow0","arrow1");
		
}

function onMenuLeave(el, cl) {
	if ((el.uniqueID == parentElement1 && PopupElement.style.visibility == "visible") || (el.uniqueID == parentElement2 && SubPopupElement.style.visibility == "visible"))
		return;

	if (!cl)
		cl = "MENU";

	el.className=cl;

	if (el.rows[0].cells[0].children.length)
		el.rows[0].cells[0].firstChild.className=cl;
	else
		el.rows[0].cells[0].className=cl;
	
	if (el.rows[0].cells.length==2)
		el.rows[0].cells[1].firstChild.src = el.rows[0].cells[1].firstChild.src.replace("arrow1","arrow0");
}


function openPopup(index, parent) {
	retainPopup();
	
	if (PopupElement.style.visibility == "visible" && PopupElement.activeIndex == index)
		return;

	if (PopupElement.style.visibility == "visible") {
		PopupElement.style.visibility = "hidden";
		
		if (parentElement1 != '' && document.all(parentElement1)) {
			onMenuLeave(document.all(parentElement1),'MENU');
			parentElement1='';
		}
	}
	
	PopupElement.style.top = parent.parentElement.offsetTop+BodyElement.offsetTop+1;
	PopupElement.style.left = BodyElement.offsetLeft+parent.offsetWidth+container.offsetLeft;
	PopupElement.activeIndex = index;
	
	if (index < popupObj.length) {
		var popupContent = "<TABLE cellSpacing=0 cellPadding=0 border=0 width=\"100%\">";
		
		for(var i = 0;i < popupObj[index].length;i ++)
			popupContent += "<TR><TD><TABLE cellSpacing=0 cellPadding=0 border=0 class=\"POPUP\" style=\""+(i ? "border-top: none;" : "")+"\" onMouseOver=\"onMenuHover(this,'POPUP');"+(popupObj[index][i][2] ? "openSubPopup("+(popupObj[index][i][2]-1)+", this);" : "")+"\" onMouseOut=\"onMenuLeave(this,'POPUP');closeSubPopup();\" onClick=\"window.location='"+unescape(popupObj[index][i][1])+"';\"><TR><TD noWrap class=\"POPUP\">"+unescape(popupObj[index][i][0])+"</TD>"+(popupObj[index][i][2] ? "<TD><IMG src=\"interface/_arrow0.gif\" hSpace=5 border=0></TD>" : "")+"</TR></TABLE></TD></TR>";
	
		popupContent += "</TABLE>";
		
		if (popupAllowFilters) {
			PopupElement.filters[0].apply();
			PopupElement.filters[0].motion = "forward";
		}
		
		PopupElement.innerHTML = popupContent;
		PopupElement.style.visibility = "visible";
		SubPopupElement.style.visibility = "hidden";
		
		parentElement1 = parent.uniqueID;
		
		if (popupAllowFilters)
			PopupElement.filters[0].play();
	}
}

function closePopup(now) {
	if (PopupElement.style.visibility == "visible")
		PopupElement.timeout = window.setTimeout("if (popupAllowFilters) { PopupElement.filters[0].apply();PopupElement.filters[0].motion='reverse'; } PopupElement.style.visibility='hidden';SubPopupElement.style.visibility='hidden';if (popupAllowFilters) PopupElement.filters[0].play();if(parentElement1!='' && document.all(parentElement1)){onMenuLeave(document.all(parentElement1),'MENU');parentElement1='';}", now ? 0 : 3000);
}

function retainPopup() {
	if (PopupElement.timeout)
		window.clearTimeout(PopupElement.timeout);
}

function openSubPopup(index, parent) {
	retainSubPopup();
	
	if (SubPopupElement.style.visibility == "visible" && SubPopupElement.activeIndex == index)
		return;
	
	if (SubPopupElement.style.visibility == "visible") {
		SubPopupElement.style.visibility = "hidden";
		
		if (parentElement2 != '' && document.all(parentElement2)) {
			onMenuLeave(document.all(parentElement2),'POPUP');
			parentElement2='';
		}
	}

	
	if (index < popupObj.length) {
		var popupContent = "<TABLE cellSpacing=0 cellPadding=0 border=0 width=\"100%\">";
		
		for(var i = 0;i < popupObj[index].length;i ++)
			popupContent += "<TR><TD><TABLE cellSpacing=0 cellPadding=0 border=0 class=\"POPUP\" style=\""+(i ? "border-top: none;" : "")+"\" onMouseOver=\"onMenuHover(this,'POPUP');\" onMouseOut=\"onMenuLeave(this,'POPUP');\" onClick=\"window.location='"+unescape(popupObj[index][i][1])+"';\"><TR><TD noWrap class=\"POPUP\">"+unescape(popupObj[index][i][0])+"</TD></TR></TABLE></TD></TR>";
	
		if (popupAllowFilters) {
			SubPopupElement.filters[0].apply();
			SubPopupElement.filters[0].motion = "forward";
		}
		
		popupContent += "</TABLE>";

		SubPopupElement.innerHTML = popupContent;
		SubPopupElement.style.visibility = "visible";
		SubPopupElement.style.left = parseInt(PopupElement.style.left)+PopupElement.clientWidth-1;
		SubPopupElement.style.top = parseInt(PopupElement.style.top)+parent.parentElement.offsetTop;
		SubPopupElement.activeIndex = index;
		
		parentElement2 = parent.uniqueID;

		if (popupAllowFilters)
			SubPopupElement.filters[0].play();
	}
}

function closeSubPopup(now) {
	if (SubPopupElement.style.visibility == "visible")
		SubPopupElement.timeout = window.setTimeout("closePopup();if (popupAllowFilters) { SubPopupElement.filters[0].apply();SubPopupElement.filters[0].motion='reverse'; } SubPopupElement.style.visibility='hidden';if (popupAllowFilters) SubPopupElement.filters[0].play();if(parentElement2!='' && document.all(parentElement2)){onMenuLeave(document.all(parentElement2),'POPUP');parentElement2='';}", now ? 0 : 3000);
}

function retainSubPopup() {
	if (SubPopupElement.timeout) {
		window.clearTimeout(SubPopupElement.timeout);
	
		retainPopup();
	}
}
