/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there. 
   ==> Comment added on 09/23/09: ID is no longer needed
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic
   ==> Comment added on 09/23/09: This script has been exported to jQuery plugin, so it will takes an expression of elements that want to be built as accordion menu.

Optional extra classnames:

noaccordion : no accordion functionality (no longer supported)
collapsible : menu works like an accordion but can be fully collapsed (no longer supported)
expandfirst : first menu item expanded at page load (no longer supported)

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>

Copyright 2008 by Marco van Hylckama Vlieg; Modified by Ricky Lie

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

(function($) {
  
  $.fn.accordionMenu = function(o) {
    return this.each(function() {
      $(this).find("ul").hide();
      $(this).find("li a").click(
        function() {
          var checkElement = $(this).next();
          var siblings = $(this).parent().siblings().children("ul:visible");

          if(checkElement.is('ul') && checkElement.is(':visible')) {
            checkElement.slideUp('normal');
            return false;
          }
          if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            siblings.slideUp('normal');
            checkElement.slideDown('normal');
            return false;
          }
        }
      );
    });
  };

})(jQuery);
