
/* ************************************************************************** */
// Contains common Javascript functions.
/* ************************************************************************** */


/* ************************************************************************** */
$(document).ready(function()
{
	$("#navigation ul li").not(".active").mouseover(function()
	{
		$(this).addClass("hover");
	});
	$("#navigation ul li").not(".active").mouseout(function()
	{
		$(this).removeClass("hover");
	});
});
/* ************************************************************************** */


/* ************************************************************************** */
// Add event function
/* ************************************************************************** */
function addEvent(elm, evType, fn, useCapture)
{
	if(elm.addEventListener)
	{
		elm.addEventListener(evType, fn, useCapture);
	}
	else if(elm.attachEvent)
	{
		r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else
	{
		elm['on' + evType] = fn;
	}
}
/* ************************************************************************** */


/* ************************************************************************** */
// Add event listeners 
/* ************************************************************************** */
function addListeners()
{
	if(!document.getElementsByTagName){ return; }
	if(!document.getElementById){ return; }
}
/* ************************************************************************** */




/* ************************************************************************** */
// Loads links in a new window, either a full browser or a sized popup.
// Usage:
// <a href="..." rel="external">
// <a href="..." rel="popup|200|300"> (200 is width, 300 is height)
/* ************************************************************************** */
function windowLinks()
{
	if(!document.getElementsByTagName){ return; }
	
	var anchors = document.getElementsByTagName("a");
	for(var i = 0; i < anchors.length; i++)
	{ 
		var anchor = anchors[i];
		var relIndex = anchor.rel;
		if(relIndex)
		{
			var relSplit = relIndex.split("|");          
			if(relSplit[0] == "external")
			{
				anchor.target = "_blank";
				anchor.title = "Loads in new window: "+ anchor.href;  
			}
			else if(relSplit[0] == "popup")
			{
				anchor.title = "Loads in a Popup Window";
				anchor.popupWidth = relSplit[1];
				anchor.popupHeight = relSplit[2];
				anchor.onclick = function(){ winPop(this.href, 'console', this.popupWidth, this.popupHeight); return false; };
			}
		}
	}
}
/* ************************************************************************** */


/* ************************************************************************** */
// Opens new windows
/* ************************************************************************** */
function winPop(strURL, strType, strWidth, strHeight)
{
	var strOptions = "";
	if(strType == "console"){ strOptions = "scrollbars=yes,resizable,height=" + strHeight + ",width=" + strWidth; }
	window.open(strURL, '', strOptions);
}
/* ************************************************************************** */



/* ************************************************************************** */
// Simon Willison's addLoadEvent function allows you to stack up 'window.onload' events 
// without them stepping on each other's toes. 
// It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578
/* ************************************************************************** */
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}
/* ************************************************************************** */


/* ************************************************************************** */
// Initialize list of onload functions
/* ************************************************************************** */
addLoadEvent
(
	function()
	{
		windowLinks();
	}
);

/* ************************************************************************** */
