// Popup Window
// James Barberousse

var popUpWindowDelay = null;
var openWindow = null;

function initPopupWindows()
{
	if (!document.getElementsByTagName) return false;

	var anchorTags = document.getElementsByTagName("a");
	var linkObj, windowObj, closeObj;

	for (var i=0; i < anchorTags.length; i++)
	{
		linkObj = anchorTags[i];
		if (linkObj.className == "popuplinknojs") // linkObj.getAttribte("class", "popuplink") doesn't work in IE
		{
			linkObj.className = "popuplink";

			linkObj.onmouseover = openPopUpWindow;
			//linkObj.onmouseout = setDelay;

			windowObj = document.getElementById("popupwindow" + linkObj.id.substring(9, linkObj.id.length));
			//windowObj.onmouseover = clearDelay;
			//windowObj.onmouseout = setDelay;

			closeObj = windowObj.getElementsByTagName("p")[0];
			closeObj.onclick = closePopUpWindow;
		}
	}
}

function openPopUpWindow()
{
	if (openWindow != null)
		closePopUpWindow();

	var linkObj = document.getElementById("popuplink" + this.id.substring(9, this.id.length));

	var windowObj = document.getElementById("popupwindow" + this.id.substring(9, this.id.length));
	if (document.all) // specific to IE
	{
		//var xPos = linkObj.offsetLeft; // proprietary DOM
		var yPos = linkObj.offsetTop + linkObj.offsetHeight+3; // proprietary DOM
		//windowObj.style.left = xPos + "px";
		windowObj.style.top = yPos + "px";
	}
	windowObj.style.zIndex = "100";
	windowObj.style.visibility = "visible";
	openWindow = windowObj;
	//return false;
}

function closePopUpWindow()
{
	//clearDelay();
	openWindow.style.visibility = "hidden";
	openWindow = null;
	return false;
}

function setDelay()
{
	popUpWindowDelay = setTimeout("closePopUpWindow();", 250);
}

function clearDelay()
{
	clearTimeout(popUpWindowDelay);
}



// Open New Browser Window
// James Barberousse

function openExternalWindow(obj)
{
	var nw = window.open(obj.getAttribute("href"), "", "left=200,top=200,width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes,toobar=yes,location=yes,status=yes");
	if (nw)
	{
		nw.focus();
		return false;
	}
	else
	{
		return true;
	}
}



// Load Event Manager
// Simon Willison

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

// Add onload events

addLoadEvent(initPopupWindows);
