/*
 *  Copyright 2005-2010 Flight Path Creative L.L.C.
 *	$Date: 2011-07-27 11:11:30 -0400 (Wed, 27 Jul 2011) $
 *	$Revision: 642 $
 *	$URL: svn://10.0.1.100/general/Stuff/trunk/js/menu.js $
 */

var onloadEvents = new Array();
window.onload = function()
{
	for(var i = 0; i < onloadEvents.length; i++)
		onloadEvents[i]();
}

onloadEvents.push(function() { navigationInitIds("nav"); });

function navigationInitIds()
{
	for(var i = 0; i < navigationInitIds.arguments.length; i++)
	{
		if(navigationInitIds.arguments[i].indexOf("#") != 0)
			navigationInitElement(document.getElementById(navigationInitIds.arguments[i]));
	}
}

function navigationInitElements()
{
	for(var i = 0; i < navigationInitElements.arguments.length; i++)
	{
		if(navigationInitElements.arguments[i].indexOf("#") != 0)
			navigationInitElement(navigationInitElements.arguments[i]);
	}
}

function navigationInitElement(element)
{
	if(!element)
		return false;

	var lis = element.getElementsByTagName("LI");
	for(var i = 0; i < lis.length; i++)
	{
		lis[i].oldClassName = lis[i].className ? lis[i].className : "";
		lis[i].onmouseover = navigationMouseOver;
		lis[i].onmouseout = navigationMouseOut;

		var as = lis[i].getElementsByTagName("A");
		for(var j = 0; j < as.length; j++)
			as[j].onclick = navigationClick;
	}
	return true;
}

function navigationMouseOver()
{
	if(this.oldClassName !== undefined)
		this.className = this.oldClassName + " hover";
}

function navigationMouseOut()
{
	if(this.oldClassName !== undefined)
		this.className = this.oldClassName;
}

function navigationClick()
{
	if(this.parentNode)
	{
		if(this.parentNode.oldClassName !== undefined)
			this.parentNode.className = this.parentNode.oldClassName;

		if(this.parentNode.parentNode && this.parentNode.parentNode.parentNode)
		{
			if(this.parentNode.parentNode.parentNode.oldClassName !== undefined)
				this.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.oldClassName;

			if(this.parentNode.parentNode.parentNode.parentNode && this.parentNode.parentNode.parentNode.parentNode.parentNode)
			{		
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.oldClassName !== undefined)
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.parentNode.parentNode.oldClassName;
			}
		}
	}

	if(this.href.substr(this.href.length-1) == "#")
		return false;

	if(this.className.match(/^(.*[ ]+)?newwindow([ ]+.*)?$/))
	{
		window.open(this.href);
		return false;
	}

	return true;
}

function clearFieldOnFocus(o, p)
{
	if(p)
	{
		if(o.value == o.title)
		{
			o.style.display = "none";
			p.style.display = "block";
			if(!p.onblur)
				p.onblur = function() { clearFieldOnBlur(o, this); };
			p.focus();
			p.className = "set";
		}
	}
	else
	{
		o.className = "set";
		if(!o.onblur)
			o.onblur = function() { clearFieldOnBlur(this); };
		if(o.value == o.title)
		{
			o.value = "";
		}
	}
}

function clearFieldOnBlur(o, p)
{
	if(p)
	{
		if(p.value == "")
		{
			o.value = o.title;
			o.style.display = "block";
			p.style.display = "none";
			p.className = "";
		}
		else
		{
			p.className = "set";
		}
	}
	else
	{
		if(o.value == "")
		{
			o.value = o.title;
			o.className = "";
		}
		else
		{
			o.className = "set";
		}
	}
}
