/*
 * Simple drop-down menu. Only handles a single level.
 */

// Constructor for a menu controller.
menuController = function(sel, config) {
    var myName = sel;
    
    var ulObj = $("ul.menu", $(sel)).first();

    // In the next two functions, x is a JQuery object for an LI element.
    var hideSubmenu = function(that,d) {
	window.clearTimeout($(that).data("tId"));

	if (d>100) {
	    tId = window.setTimeout(function() { hideSubmenu(that, 0); }, d);
	    $(that).data("tId", tId);
	} else {
	    if (!config.hasOwnProperty('fadeOutSpeed')) {
		$("ul.submenu",$(that)).hide();
	    } else {
		$("ul.submenu",$(that)).fadeOut(config.fadeOutSpeed);
	    }
	}
    }

    var showSubmenu = function(that) {
	$(that)
	    .siblings()
	    .each(function() {hideSubmenu(this,0);});
	if (!config.hasOwnProperty('fadeInSpeed')) {
	    $(that)
		.children("ul.submenu").show();
	} else {
	    $(that)
		.children("ul.submenu").fadeIn(config.fadeInSpeed);
	}
	window.clearTimeout($(that).data("tId"));
    }

    $("ul.submenu",ulObj)
	.parent()
	.mouseover(function() {showSubmenu(this); })
	.mouseout(function() {hideSubmenu(this,config.timeout); });
}
	 
