/*
	Department of Chemistry
	University of Rochester
	Author:	John Bertola
	Date:	May 15, 2008
	Javascript Functions
*/

var nav_default;
var nav_selection;
var return_call = false;
var nav_hover = false;
var NUM_LINKS = 8;			//the number of links in the primary navbar
var DELAY = 1000;			//time in msec after which the subnavbar can retract

/* Preps the navbar and scrollers */
function initialize(nav)
{
	nav_default = nav;
	show_nav(nav);
}

function search_swap()
{
	document.getElementById("search").getElementsByTagName("div")[0].style.display = "block";
	document.getElementById("search").getElementsByTagName("a")[0].style.display = "none";
	document.getElementById("search_box").focus();
}

/* BEGIN Functions for navbar */

/* Changes the color of a primary link */
function highlight(id)
{
	for (i=1; i<=NUM_LINKS; i++)
	{
		var name = "link" + i;
		if (i == id)
			document.getElementById(name).style.color = "#FFC400";
		else
			document.getElementById(name).style.color = "#FFFFFF";
	}
			
}

/* Changes the color of all primary links to white */
function unhighlight()
{
	for (i=1; i<=NUM_LINKS; i++)
	{
		var name = "link" + i;
		document.getElementById(name).style.color = "#FFFFFF";
	}
}

/* Hides all sub-navbar links */
function hide_all()
{
	objects = document.getElementById("nav_cont").getElementsByTagName("ul");
	for (i=0; i<objects.length; i++)
		objects[i].style.display = "none";
	subnav_hidden = true;
}

/* Shows a group of sub-navbar links */
function show_nav(id)
{
	nav_hover = true;	
	nav_selection = id;
	show_nav_helper();
}

function show_nav_helper()
{
	hide_all();
	highlight(nav_selection);
	var nav = "nav" + nav_selection;
	object = document.getElementById(nav);
	object.style.display = "block";
}

function return_nav()
{
	nav_hover = false;
	nav_selection = nav_default;
	if (!return_call)
	{
		return_call = true;
		setTimeout(check_hover, DELAY);
	}
}

function check_hover()
{
	return_call = false;
	if (!nav_hover)
		show_nav_helper();
}

function hover_nav()
{
	nav_hover = true;
}

/* END Functions for navbar */
	