/**
 * CollapseMenu
 *
 * @author    Ian Eure <ieure@blarg.net>
 * @copyright (c) 2005
 * @version   SVN: $Revision: 14445 $
 */


/**
 * Initialize a menu
 *
 * This will generate id attributes for each li element which is a child of
 * the element param. You may also set ids on them directly.
 *
 * @param   HTMLElement  element  The element to initialize
 * @return  void
 */
function initMenu(element)
{
	// Add click handler for the <a> element...
    $(element).find("li.expand > a").click(function()
    {
        if (this.className.match("expandable")) {
            $(this).next("ol").toggle();
            if ($(this).next("ol:first").css("display") == "none") {
                $(this.parentNode).removeClass("expanded");
            } else {
                $(this.parentNode).addClass("expanded");
            }
            return false;
        }
    });

	// Hide everything
	$(element).find("li.expand > ol.menu").hide();

	// Find selected links, walk back up the tree
	$(element).find("a.selected").each(function()
    {
		// Show everything up to the parent menu
		var cn = this.parentNode;
		while (cn != element) {
			if (cn.style.display == "none") {
				$(cn).show();
			}
			if (cn.tagName.toLowerCase() == "ol") {    
				$(cn.parentNode).addClass("expanded");
			}
			cn = cn.parentNode;
		}
	});
}
