window.onload = function () {
	document.getElementById('dropdown_menus').className = 'dropdown_js';
}

var showTimer;
var hideTimer;
var foHideTimer;
var showTimerRunning = false;
var hideTimerRunning = false;
var foHideTimerRunning = false;

function show_delayed(id) {
	if (hideTimerRunning){
		clearTimeout(hideTimer);		
		hideTimerRunning = false;
	}
	
	// The for loop below allows fast navigation when moving between main drop down menus.
	for (var i = 1; i<=5; i++) {
		if (document.getElementById('dd_menu_'+i) && 'dd_menu_'+i != id && document.getElementById('dd_menu_'+i).style.visibility == 'visible') {
			document.getElementById('dd_menu_'+i).style.visibility = 'hidden';
			return show(id);
		}
	}
	
	showTimer = setTimeout('show(\''+id+'\')',600);
	showTimerRunning = true;

}


function show(id) {
	showTimerRunning = false;
	var d = document.getElementById(id);

	
	if (d) {
		d.style.visibility='visible';
	}
}

function hide_delayed(id) {
	if (showTimerRunning){
		clearTimeout(showTimer);
		showTimerRunning = false;
	}
	
	hideTimerRunning = true;
	hideTimer = setTimeout('hide(\''+id+'\')',200);
}

function hide(id){
	hideTimerRunning = false;

	var d = document.getElementById(id);
	
	if (d) {
		d.style.visibility = 'hidden';
	}
}


function show_fo(id){
	var d = document.getElementById(id);
	
	if (foHideTimerRunning){
		foHideTimerRunning = false;
		clearTimeout(foHideTimer);		
	}
	
	for (var i = 1; i<=9; i++) {
		if (document.getElementById('fo_menu_'+i)) {
			document.getElementById('fo_menu_'+i).style.visibility='hidden';
		}
	}
	
	if (d) {
		d.style.visibility = 'visible';
	}
}

function hide_fo(id){
	var d = document.getElementById(id);
	
	if (d) {
		d.style.visibility = 'hidden';
	}
}

function hide_fo_delayed(id){
	foHideTimerRunning = true;
	foHideTimer = setTimeout('hide_fo(\''+id+'\')',200);
}

/*
 * @author Cagdas Cubukcu
 * @email cagdas.cubukcu@csueastbay.edu
 * @param link_name string The name of the link in the navigation menu to be highlighted.
 * @param number integer Default: 1. If there are more than one link with the same link_name, the number of the link that is wanted to be highlighted should be passed by this parameter.
 */
function highlightLink(link_name, number){
	
	link_name 	= link_name.replace(/^\s+|\s+$/g, ''); // Trim string
	
	var links 	= document.getElementById("navigation").getElementsByTagName("a");
	
	var number	= (number == null) ? 1 : number; // Default value is 1
	var count 	= 1;
	
	var length 	= links.length;
	
	for (i=0; i<length; i++){
		
		if (links[i].innerHTML.replace(/^\s+|\s+$/g, '') == link_name){
			
			if (count == number){
				links[i].id = "active";
				break; // Exit the for loop
			}
			else {
				count++;
			}	
		}
	}
}

// JavaScript Document
var container_div = document.createElement('div');

/*
LeftNavFollowingLink(LinkName, LinkLocation, AppearAfter)
Call this function if you want to have a link on the left hand navigation that follows page scroll.
- NOTE: Call this function only after the #contentarea div is closed.

LinkName: Name of the link.
LinkLocation: Location of the link.
AppearAfter: Enter the number of pixels for the link to appear in the page.

Ex.: LeftNavFollowingLink('Top of the list','#list_top',900);
<a href="#list_top">Top of the list</a> will appear when user scrolls 900 pixels down.
*/
function LeftNavFollowingLink(LinkName, LinkLocation, AppearAfter){
	var content_area = document.getElementById("contentarea");
	
	var newlink = document.createElement('a');
	newlink.setAttribute('href', LinkLocation);
	newlink.innerHTML = LinkName;
	container_div.appendChild(newlink);
	
	container_div.className = 'LeftNavFollowingLink';

	content_area.parentNode.insertBefore(container_div,content_area.nextSibling);
	
	setInterval("positionit("+AppearAfter+")",50);
}

function positionit(AppearAfter){
	//define reference to the body object in IE
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	//define universal dsoc left point
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
	//define universal dsoc top point
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;

	if ((document.all||document.getElementById) && (dsoctop > AppearAfter)){
		container_div.style.visibility="visible";
		//container_div.style.left=parseInt(dsocleft)+0+"px"; // Set the left
		container_div.style.top=dsoctop+0+"px"; // Set the top
	}
	else{
		container_div.style.visibility="hidden";
	}
}