// $Id: dhtml_menu.js,v 1.18.2.8 2008/11/09 23:03:35 arancaytar Exp $

 

/**
 * Initialize the module's JS functions
 */
$(document).ready(function() {  
  $('a[rel*=facebox]').facebox({overlay:false});
  $('.collapsed').removeClass('expanded');

  /* Add jQuery effects and listeners to all menu items.
   * The ~ (sibling) selector is unidirectional and selects 
   * only the latter element, so we must use siblings() to get 
   * back to the link element.
   */
   $('ul.menu li:not(.leaf)').each(function() {
    var li = this;

    $(li).find('a:first').click(function(e) {
      toggleHelpMenu($(li));
      return false;
    });
  });
});

/**
 * Toggles the menu's state between open and closed.
 *
 * @param li
 *   Object. The <li> element that will be expanded or collapsed.
 */
toggleHelpMenu = function(li) {


  // If the menu is expanded, collapse it.
  if($(li).hasClass('expanded')) {
    

		  $(li).find('ul:first').animate({height: 'hide', opacity: 'hide'}, '1000');
    
      

      $(li).find('li.expanded').removeClass('expanded').addClass('collapsed')

    $(li).removeClass('expanded').addClass('collapsed');
  }

  // Otherwise, expand it.
  else {
    
      $(li).find('ul:first').animate({height: 'show', opacity: 'show'}, '1000');
    
    $(li).removeClass('collapsed').addClass('expanded');

    
      var id = $(li).find('a:first').attr('id');

      // Siblings are all open menus that are neither parents nor children of this menu.
      $(li).find('li').addClass('own-children-temp');
	  
      // If the relativity option is on, select only the siblings that have the same parent
      
        var siblings = $('ul.menu li.expanded').not('.own-children-temp').not(':has(#' + id + ')');
      

      

      $('.own-children-temp, .sibling-children-temp').removeClass('own-children-temp').removeClass('sibling-children-temp');

      
        $(siblings).find('ul:first').animate({height: 'hide', opacity: 'hide'}, '1000');
      

      $(siblings).removeClass('expanded').addClass('collapsed');
  }

}

