var isOpen = 0;
var closeTimer = 0;

function openPopup(p, i) {
	closePopup();
	
	if (document.getElementById('PopupElement') && i < popupObj.length) {
		var c = document.getElementById('PopupElementInner');

		if (c) {
			var htmlStr = "<TABLE cellSpacing=0 cellPadding=0 border=0 width='100%'><TR><TD><IMG src=\"interface/_trans.gif\" width=1 height=13 border=0></TD></TR>";
			
			for(var j = 0;j < popupObj[i].length;j ++)
				htmlStr += "<TR><TD class=\"POPUP\" noWrap onMouseOver=\"this.className='POPUP_HOVER';retainPopup();\" onMouseOut=\"this.className='POPUP';retainPopup();\" onClick=\"window.location='"+unescape(popupObj[i][j][1])+"';\">"+unescape(popupObj[i][j][0])+"</TD></TR>";
			
			
			htmlStr += "</TABLE>";

			c.innerHTML = htmlStr;

			document.getElementById('PopupElement').style.left = 220+p.offsetLeft;
			document.getElementById('PopupElement').style.visibility = "visible";
			
			isOpen = 1;
		}
	}
}

function closePopup(p) {
	retainPopup();
	
	if (!p) {
		if (isOpen) {
			isOpen = 0;
		
			document.getElementById('PopupElement').style.visibility = "hidden";
		}
	} else closeTimer = window.setTimeout("closePopup();", 3000);
}

function retainPopup() {
	if (closeTimer) {
		window.clearTimeout(closeTimer);
		closeTimer = 0;
	}
}

document.body.onclick = closePopup;