/**
 * Cross browser event listener addition function
 * @param obj Object DOM node
 * @param evType String event type (click, mouseOver, etc)
 * @param fn Function reference to callback function
 * @param useCapture Boolean to determine event capture vs event bubble behavior
 * @return Object DOM node 
 */
function addEvent(obj, evType, fn, useCapture)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

/**
 * Add an onload function to the document, keeps existing onLoad functions
 * @param fn Function reference to function to execute onLoad
 */
function addLoadEvent(fn)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = fn;
	} else {
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			fn();
		}
	}
}

/**
 * Cross browser back-compatible getElementById function
 * @param id String containing DOM node ID
 * @return Object DOM node 
 */
function getElementById(id)
{
	if (document.all)
	{
		return document.all[id];
	}
	else if (document.getElementById)
	{
		return document.getElementById(id);
	}
	return null;
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

var menuTimeout = 250;
var hTimer = null;
var hObj=null;
sfHover = function() {
	var listRef = document.getElementById("quicklinks");
	if (typeof listRef != undefined && listRef != null)
	{
		var sfEls = listRef.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				clearTimeout(hTimer);
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				//this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				hObj = this;
				clearTimeout(hTimer);
				hTimer = setTimeout('closeHover()',menuTimeout);
			}
		}
	}
	
	listRef = document.getElementById("related_projects");
	if (typeof listRef != undefined && listRef != null)
	{
		var sfElsrp = listRef.getElementsByTagName("LI");
		for (var i=0; i<sfElsrp.length; i++) {
			sfElsrp[i].onmouseover=function() {
				clearTimeout(hTimer);
				//alert(this.className);
				this.className+=" sfhover";
			}
			sfElsrp[i].onmouseout=function() {
				//this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				hObj = this;
				clearTimeout(hTimer);
				hTimer = setTimeout('closeHover()',menuTimeout);
			}
		}
	}
}

function closeHover()
{
	hObj.className=hObj.className = '';
}

if (window.attachEvent) window.attachEvent("onload", sfHover);