var Popup = new Object();

Popup.Open = function(p, index) {
	var oPopup = document.getElementById('oPopup');
	
	if (oPopup && Popup.Data.length >= index && Popup.Data[index-1].length) {
		var x = 0;
		var y = p.offsetHeight+5;
		var dx = p.parentNode.offsetWidth-2;
		var s = "";
		
		if (Popup.pSource && p.uniqueID && p.uniqueID != Popup.pSource.uniqueID)
			Popup.Close(1);
			
		Popup.pSource = p;
		
		while(p) {
			if (typeof(p.tagName) == "string" && (p.tagName.toLowerCase() == "td" || p.tagName.toLowerCase() == "table" || p.tagName.toLowerCase() == "div") && typeof(p.offsetLeft) == "number") {
				x += p.offsetLeft;
				y += p.offsetTop;
			}
			
			p = p.parentNode;
		}
		
		for(var i = 0;i < Popup.Data[index-1].length;i ++)
			s += "<tr><td nowrap=\"nowrap\" class=\"popup\" onmouseover=\"this.className+='_hover';\" onmouseout=\"this.className=this.className.replace('_hover','');\" onclick=\"window.location=unescape('"+Popup.Data[index-1][i][1]+"');\">"+unescape(Popup.Data[index-1][i][0])+"</td></tr>";

		if (s != "") {
			Popup.Retain();
			
			if (oPopup.filters && oPopup.filters.length)
				oPopup.filters[0].apply();
			
			oPopup.innerHTML = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\""+dx+"\">"+s+"</table>";
			oPopup.style.left = x+"px";
			oPopup.style.top = y+"px";
			oPopup.style.visibility = "visible";
			oPopup.onmousemove = Popup.Retain;
			oPopup.onmouseout = Popup.Close;
			
			if (oPopup.filters && oPopup.filters.length)
				oPopup.filters[0].play();

			if (Popup.pSource.parentNode && Popup.pSource.parentNode.className.indexOf(" menu_selected") == -1) {
				Popup.pSource.className += " menu_selected";
				Popup.pSource.parentNode.className += " menu_selected";
			}
		}
	}
}

Popup.Retain = function() {
	if (typeof(Popup.nEvent) == "number" && Popup.nEvent) {
		window.clearTimeout(Popup.nEvent);
		Popup.nEvent = 1;
	}
}

Popup.Close = function(t) {
	if (t == 1) {
		var oPopup = document.getElementById('oPopup');
		
		if (oPopup && oPopup.style.visibility == "visible") {
			if (Popup.pSource && Popup.pSource.parentNode && Popup.pSource.parentNode.className.indexOf(" menu_selected") != -1) {
				Popup.pSource.className = Popup.pSource.className.replace(" menu_selected", "");
				Popup.pSource.parentNode.className = Popup.pSource.parentNode.className.replace(" menu_selected", "");
				Popup.pSource = null;
			}

			oPopup.style.visibility = "hidden";
		}
	} else Popup.nEvent = window.setTimeout("Popup.Close(1);", 500);
}
