(function ($) {
    $.fn.jsAccordion = function (options) {
        var settings = $.extend({
            className: '',
            openPanels: null
        }, options);

        return this.each(function () {
            var $this = $(this),
                $li = $this.children('li'),
                showPanels = function (panels) {
                    if (panels) {
                        panels.show().parent().addClass('expanded');
                    }
                };

            // add the style class to each accordion
            $this.addClass(settings.className);

            // hide all of the accordion's panels
            $li.children('ul, div').each(function () {
                var $panel = $(this),
                    width = $panel.width();

                // hide panels and make animation smoother by defining a width
                $panel.hide().width(width);
            });

            // expand the panels that should be open when the page loads
            showPanels(settings.openPanels);

            // find all non-empty, top-level text nodes and wrap them with span tags
            $li.contents().filter(function () {
                return this.nodeType === 3 && $.trim(this.nodeValue) !== '';
            }).wrap('<span />');

            // if an anchor precedes a hidden section, don't treat it as a link
            $li.children('a').each(function () {
                var $a = $(this);

                if ($a.next('ul, div').length > 0) {
                    $a.click(function (e) {
                        e.preventDefault();
                    });
                }
            });

            $li.children('a, span').click(function () {
                var $label = $(this);

                if ($label.next('ul, div').is(':visible')) {
                    // if the corresponding panel is visible, collapse it
                    $label.next('ul, div').slideUp();
                    $label.parent().removeClass('expanded');
                } else {
                    window.a = $li;
                    // otherwise, if a panel is being opened, collapse all others
                    $li.filter('.expanded').removeClass('expanded')
                        .children('ul:visible, div:visible').slideUp();
                    $label.next('ul, div').slideDown();
                    $label.parent().addClass('expanded');
                }
            });
        });
    };
}(jQuery));
@@ -142,16 +142,48 @@
 ls: null
+,%0A            autoCollapse: true
 %0A       
@@ -2058,85 +2058,63 @@
     
-window.a = $li;%0A                    // otherwise, if a panel is being opened,
+if (settings.autoCollapse) %7B%0A                        //
  col
@@ -2128,18 +2128,27 @@
 ll other
-s%0A
+ panels%0A   
         
@@ -2155,24 +2155,25 @@
             
+ 
 $li.filter('
@@ -2232,16 +2232,20 @@
         
+    
 .childre
@@ -2276,32 +2276,54 @@
 le').slideUp();%0A
+                    %7D%0A
                 

Add option to prevent collapsing panels (Fixes #18)