(function ($) {
    $.fn.extend({
        accordion: function (action) {
            return this.each(function () {
            	$(this).children().removeClass("active");
                //if ($(this).data('accordiated')) return false;
                $.each($(this).find('li>div'), function () {
                    $(this).data('accordiated', true);
                    $(this).hide();
                });
                $.each($(this).find('a.panel-title'), function () {
                    $(this).unbind();
                    $(this).click(function (e) {
                        activate(e.target);
                    	return false;
                    });
                });

                var active = false;
                //if (location.hash) active = $(this).find('a[href=' + location.hash + ']')[0];
                //else if ($(this).find('li.current')) active = $(this).find('li.current a')[0];
                if ($(this).find('li.current')) active = $(this).find('li.current a')[0];
                
                if (active) {
                    activate(active, 'toggle', 'parents');
                    $(active).parents().show();
                }

                function activate(el, effect, parents) {
                    $(el)[(parents || 'parent')]('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');
                    $(el).siblings('ul, div')[(effect || 'slideToggle')]((!effect) ? 'fast': null);
                }

            });
        }
    });
})(jQuery);