(function ($) {
    $(document).ready(function () {
        $('.auto-collapse').on('click', function () {
            $('.auto-collapse').not(this).removeAttr('open');
        });

        $('details summary').each(function () {
            var animationTime = 1000;
            var $Wrapper = $(this).nextAll().wrapAll('<div></div>').parent();

            if (!$(this).parent('details').attr('open')) {
                $Wrapper.hide();
            }

            $(this).click(function (Event) {
                Event.preventDefault();

                if ($(this).parent('details').attr('open')) {
                    $Wrapper.slideUp(animationTime, function () {
                        $(this).parent('details').removeAttr('open');
                    });
                } else {
                    $(this).parent('details').attr('open', true);
                    $Wrapper.slideDown(animationTime);
                }
            });
        });

        $('details').each(function () {
            if ($(this).css('marginBottom') === '0px') {
                $(this).addClass('no-gap');
            }
        });
    });
})(jQuery);