// unobtrusive javascript to enhanve browsing experience, uses functions.js

function goHome()
{
	document.location = '/index.php';
}

attachClick = function()
{
	var logo = document.getElementById("logo-box");
	addEvent(logo, 'click', goHome);
}

buildHover = function()
{
	navRoot = document.getElementById("top-nav");
	for (i=0; i<navRoot.childNodes.length; i++)
	{
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI")
		{
			node.onmouseover=function()
			{
				addClass(this, "menuhover");
  		}
			node.onmouseout=function()
			{
				removeClass(this, "menuhover");
			}
		}
	}
}

function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
		}
	}
}

var supernovaTimer = null;

function moveSupernova()
{
	var x = 0;
	var y = 0;
	var e = document.getElementById('supernova');
	if (!e) return;
	if (pageWidth() < 850)
	{
		// hide it
		e.style.display = 'none';
	}
	else
	{
		x = Math.random() * (pageWidth() - 800) / 2;
		y = Math.random() * (pageHeight() - 256);
		if (Math.round(Math.random() * 100) % 2 == 1)
		{
			x = pageWidth() - x - 256;
		}
		e.style.left = x + 'px';
		e.style.top = y + 'px';
		e.style.display = 'block';
	}
}

function setSupernovaTimer()
{
	supernovaTimer = setInterval(moveSupernova, 7200);
}

addEvent(window, 'load', buildHover);
addEvent(window, 'load', attachClick);
addEvent(window, 'load', externalLinks);
addEvent(window, 'load', moveSupernova);
addEvent(window, 'load', setSupernovaTimer);
