///////////////////////////////////////////////////////////////////////////////
// navFader.js -
//  @author: Jeff Lambert
//
// Provides the functionality to allow hidden subnavigation div elements to 
// fade in when they're main category is pointed to by the cursor.
//
//  Methods:
//      To show the subnav (from the main category link): show(elementId)
//      When the main category loses the cursor: fadeEnter()
//
//      onmouseover the (now displayed) subnav div: lock(elementId)
//      onmouseout the (now displayed) subnav div: unlock();
//
//  All positioning handled in the html, the list of all of the subnav div 
//  id's below needs to be edited to change.
////////////////////////////
//
var DEBUG = false;
if(DEBUG)
    alert("Inside navFader, Browser: " + curBrowser);

////////
// ** EDIT ME **
var subnavs = [ "about_sub", "programs_sub",        // value of the id 
                "resources_sub", "memorium_sub" ];  // attribute of subnav divs
////////
var TIMEOUT_T = 35;     // # ms between successive opacity changes
var WAIT_T = 2200;      // # ms to wait before fading out a subnav div when
                        // the cursor leaves

var curEl = 'about_sub';
var timer;
var locked = 'none';
//////////////////////////////////////////////////
// function show(el) -
//  'Unhides' the specified element and sets it's z-index above 
//  the main content's.
    function show(el) {
	    if(DEBUG)
	        alert("Showing: " + el);
		hideAll();
		if(curBrowser == "Microsoft Internet Explorer") {
			document.getElementById(el).style.filter = "alpha(opacity=100)";
		} else if(curBrowser == "Netscape") {
			document.getElementById(el).style.MozOpacity = 1;
		}
		document.getElementById(el).style.zIndex = 4;
		curEl = el;
	}
//////////////////////////////////////////////////
// function hideAll() -
//  Hides all subnav div elements by setting their 
//  opacity to 0 and their z-index to -1.
    function hideAll() {
		var el;
		if(curBrowser == "Microsoft Internet Explorer") {
			for(var i = 0; i < subnavs.length; i++) {
				el = document.getElementById(subnavs[i]);
				el.style.filter = "alpha(opacity=0)";
				el.style.zIndex = -1;
			}
		} else if(curBrowser == "Netscape") {
			for(var i = 0; i < subnavs.length; i++) {
				el = document.getElementById(subnavs[i]);
				el.style.MozOpacity = 0;
				el.style.zIndex = -1;
			}
		}
	}
//////////////////////////////////////////////////
// function lock(el) -
//  locks a subnav div to keep it from being faded out.
		function lock(el) {
            if(DEBUG)
			    alert("Locking: " + el);
			locked = el;
		}
//////////////////////////////////////////////////
// function unlock() -
//  Unlocks the current element, allowing it to be faded out.
//  Sets the timer for the fadeout.
    function unlock() {
        if(DEBUG)
		    alert("Unlocking: " + curEl);
		locked = 'none';
		timer = setTimeout('navFadeOut()', WAIT_T);
		
	}
//////////////////////////////////////////////////
// function faderEnter() -
//  Helper function used to allow the main category 
//  links to stop the fadeout timer of the current 
//  active subnav div when the mouse has left it's 
//  main category for another.
	function faderEnter() {
		clearTimeout(timer);
		timer = setTimeout('navFadeOut()', WAIT_T);
	}
//////////////////////////////////////////////////
// function navFadeOut() -
//  Recursively loops
	function navFadeOut() {
		if(locked == curEl || curEl == 'none')
			return;
		if(curBrowser == "Netscape") {
			document.getElementById(curEl).style.MozOpacity -= 0.08;
			if(document.getElementById(curEl).style.MozOpacity >= 0) {
				setTimeout('navFadeOut()', TIMEOUT_T);
			} else {
				hideAll();
				curEl = 'none';
			}
		} else if(curBrowser == "Microsoft Internet Explorer") {
			var curOpacity = document.getElementById(curEl).filters[0].opacity;
			document.getElementById(curEl).style.filter = "alpha(opacity=" + 
			    (curOpacity - 8) + ")";

			if(curOpacity - 8 >= 0) {
				setTimeout('navFadeOut()', TIMEOUT_T);
			} else {
				hideAll();
				curEl = 'none';
			}
		}
    }
///////////////////////////////////////////////////////////////////////////////
