Dropdowns = new Object();
// Editable Start
// this only updates the dropdowns that show / hide, the dropdowns that stay open on a section are
// in /templates/static_dropdowns
//                    format is "first label", "first link", "second label", "second link", etc
Dropdowns["program"] = Array("Description", "program/", "Courses", "program/course_of_study.php");
Dropdowns["news"] = Array("Recent", "news/", "Archive", "news/archive.php");
Dropdowns["students"] = Array("Recent", "students/", "Archive", "students/archive.php");
// Editable End


DropdownTimer = new Object();
for ( var NavName in Dropdowns )
{
//alert(NavName);
	DropdownTimer[NavName] = 0;
//alert(DropdownTimer[NavName]);
}
	
//////////////////////////////
function loadMenus()
{
//alert("Loading menus!");	
	// loop through dropdowns and add to corresponding a
	for ( var NavName in Dropdowns )
	{
		//alert("nav "+NavName);
		var MenuLink = document.getElementById("nav_"+NavName);
		if (MenuLink == null)
			continue;
			
		// create menu div
		var Dropdown = document.createElement("div");
		Dropdown.id = NavName+"_dropdown";
		Dropdown.className = "nav_dropdown";
		Dropdown.style.display = "none";

		var MouseOverFunc = new Function('showDropdown("'+NavName+'")'); 
		var MouseOutFunc = new Function('hideDropdown("'+NavName+'")'); 

		// verify valid menu
		if (Dropdowns[NavName].length % 2 != 0)
			alert('Dropdowns['+NavName+'] should be Array(Name, Link, Name, Link, etc)');

		for (i=0; i<Dropdowns[NavName].length; i+=2)
		{	
			var WrapperDiv = document.createElement("div");
			var Link = document.createElement("a");
			Link.href = Dropdowns[NavName][i+1];
			Link.onmouseover = MouseOverFunc;
			Link.onmouseout = MouseOutFunc;
			Link.innerHTML = Dropdowns[NavName][i];
			WrapperDiv.appendChild(Link);
			Dropdown.appendChild(WrapperDiv);
		}
		
		MenuLink.onmouseover = MouseOverFunc;
		MenuLink.onmouseout = MouseOutFunc; 
		insertAfter(MenuLink, Dropdown);
	}
}

//////////////////////////////
function insertAfter(referenceNode, node) 
{
	if (referenceNode.parentNode == null)
		alert("referenceNode does not have parent node, so can't do an insert after");
	referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
}

//////////////////////////////
function hasDropdown(_Name)
{
	var Dropdown = document.getElementById(_Name+"_dropdown");
//alert(_Name+", "+Dropdown);	
	return (Dropdown != null);
}

//////////////////////////////
function showDropdown(_Name)
{
	if ( ! hasDropdown(_Name) || DontDisplayDropdown == _Name)
		return;

	clearTimeout(DropdownTimer[_Name]);	

	// hide all other dropdowns
	for ( var NavName in Dropdowns )
		if (NavName != _Name)
			performHideDropdown(NavName);
	
	var Dropdown = document.getElementById(_Name+"_dropdown");
	Dropdown.style.display = "block";
}

//////////////////////////////
function hideDropdown(_Name)
{
	if ( ! hasDropdown(_Name))
		return;

	clearTimeout(DropdownTimer[_Name]);
	DropdownTimer[_Name] = setTimeout('performHideDropdown("'+_Name+'")', 800);
}

//////////////////////////////
function performHideDropdown(_Name)
{
	if ( ! hasDropdown(_Name))
		return;
	
	clearTimeout(DropdownTimer[_Name]);
	
	var Dropdown = document.getElementById(_Name+"_dropdown");
	Dropdown.style.display = "none";	
}


// Debugging functions
function debug(_Msg)
{
	var Debug = document.getElementById('debug_console');
  if (Debug == undefined)
  	addDebugConsole();

  var Debug = document.getElementById('debug_console');

  Time = new Date();
  //_Msg = Time.getMinutes()+Time.getSeconds()+": "+ _Msg;
  _Msg = ": "+ _Msg;

  Debug.innerHTML = _Msg+"<br>"+Debug.innerHTML;
}
function addDebugConsole()
{
  // add debug div
  var DebugConsole = document.createElement('div');
  DebugConsole.id = "debug_console";
  DebugConsole.style.position = "absolute";
  DebugConsole.style.top = 0;
  DebugConsole.style.left = 0;
  DebugConsole.style.width = "300px";
  DebugConsole.style.height = "600px";

  // add debug window to top left of browser
  document.body.insertBefore(DebugConsole, document.body.firstChild);
}

/*
 * (c)2006 Jesse Skinner/Dean Edwards/Matthias Miller/John Resig
 * Special thanks to Dan Webb's domready.js Prototype extension
 * and Simon Willison's addLoadEvent
 */ 
addDOMLoadEvent = (function(){
    // create event function stack
    var load_events = [],
        load_timer,
        script,
        done,
        exec,
        old_onload,
        init = function () {
            done = true;

            // kill the timer
            clearInterval(load_timer);

            // execute each function in the stack in the order they were added
            while (exec = load_events.shift())
                exec();

            if (script) script.onreadystatechange = '';
        };

    return function (func) {
        // if the init function was already ran, just run this function now and stop
        if (done) return func();

        if (!load_events[0]) {
            // for Mozilla/Opera9
            if (document.addEventListener)
                document.addEventListener("DOMContentLoaded", init, false);

            // for Internet Explorer
            /*@cc_on @*/
            /*@if (@_win32)
                document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
                script = document.getElementById("__ie_onload");
                script.onreadystatechange = function() {
                    if (this.readyState == "complete")
                        init(); // call the onload handler
                };
            /*@end @*/

            // for Safari
            if (/WebKit/i.test(navigator.userAgent)) { // sniff
                load_timer = setInterval(function() {
                    if (/loaded|complete/.test(document.readyState))
                        init(); // call the onload handler
                }, 10);
            }

            // for other browsers set the window.onload, but also execute the old window.onload
            old_onload = window.onload;
            window.onload = function() {
                init();
                if (old_onload) old_onload();
            };
        }

        load_events.push(func);
    }
})();
addDOMLoadEvent(loadMenus);
//window.onDomReady(loadMenus);
//window.onload=loadMenus; 
