/*The variable used to keep track of the timeout for the hover 
(allows you to have the delay on the hover of the menu, so that the menu sticks around after you moved off the li's)*/
var currentTimeout;

/*an array to hold the li's that you want held in hover mode*/
var LIs_To_Hover = new Array();


/*sets up the functions for the mouseover and mouse out for the li's with class of 'top_li' and a parent container with the id 'nav'*/
function enableMenuImageRollovers()
{
	/*get the surrounding container with the id of 'nav'*/
	var container = document.getElementById('main_nav');

	/*return if the id is not found*/
	if (!container)
	{
		return;
	}
	
	/*get a list of all the li's in that surrounding div*/
	var lis = container.getElementsByTagName('li');


	for(x=0; x< lis.length; x++)
	{
		var li=lis[x];

		/*indexOf is the same as str_pos in php (this is looking to see if the string "top_li" is in the class name of the li)
		this is to make sure the li that are under the top level li's are not given these functions*/
		if(li.className.indexOf("top_li")!=-1)
		{
			//push the li's id onto the array of li's able to be hovered*/
			LIs_To_Hover.push(li.id);
			li.onmouseover=function() 
			{
				RollOver(this);
			}
			li.onmouseout=function() 
			{
				RollOff(this);
			}
		}
	}
}

/*what do do when the li is rolled over*/
function RollOver(li)
{
	//go through the list of lis that can be hovered and turn off hover*/
	TurnOffAll();
	clearTimeout(currentTimeout);

	li.className=li.className.replace("hover_off","hover_on");

	var a_list = li.getElementsByTagName('a');

	for(var i = 0; i < a_list.length; i++)
	{
		a_list[i].className = a_list[i].className.replace("normal", "rollover");

	}

}

/*what do do when the li is rolled off*/
function RollOff(li)
{
	currentTimeout = setTimeout("RemoveSynHover('" + li.id + "')",500);
}

/*remove the hover attributes of an li*/
function RemoveSynHover(LI_Id)
{
	var li = document.getElementById(LI_Id);

	li.className=li.className.replace("hover_on","hover_off");

	var a_list = li.getElementsByTagName('a');

	for(var i = 0; i < a_list.length; i++)
	{
		a_list[i].className = a_list[i].className.replace("rollover", "normal");

	}
}

/*go through each li in the list of "hoverable" li's and remove their hover attributes */
function TurnOffAll()
{
	for(var i = 0; i < LIs_To_Hover.length; i++)
	{
		RemoveSynHover(LIs_To_Hover[i]);
	}
}

function bindBehaviors()
{
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  enableMenuImageRollovers();
}


if (window.addEventListener)
{
  window.addEventListener('load', bindBehaviors, false);

}
else if (window.attachEvent)
{
  window.attachEvent('onload',bindBehaviors);

}

/**********************************************************
 *  JavaScript for Label-less Mini-forms.
 *   Add this to your input fields:
 *   onfocus="default_value(this);" onblur="new_value(this);"
 ***********************************************************/

// Trims all whitespace from a text string.
function trim(str) 
{
    str = str.replace(/^\s+/, '');
    
    for (var i = str.length - 1; i > 0; i--) 
    {
        if (/\S/.test(str.charAt(i))) 
        {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return str;
};

// Sets an element's value to nothing if it matches the default.
function default_value(content)
{
    if (trim(content.value) == content.defaultValue)
    {
        content.value = '';
    }
};

// Sets an element's value to default if it is blank.
function new_value(content)
{
    if (trim(content.value) == '')
    {
        content.value = content.defaultValue;
    }	
};
/**********************************************************/