(function($) {

    $.fn.accordion = function(options) {
        return this.each(function() {
            new $.accordion(this, options);
        });
    };

    $.accordion = function(e, options) {
        this.options = $.extend({
            header: 'a'
        }, options);

        this.$ul = $(e);

        if ($.browser.msie) {
            $('a', this.$ul).css('zoom', '1');
        }

        this.$headers = $(this.options.header, this.$ul);
        this.$contents = $('li > div', this.$ul).hide();
        this.$opened = null;

        this.init();
    };

    $.accordion.fn = $.accordion.prototype = {};

    $.accordion.fn.extend = $.accordion.extend = $.extend;

    $.accordion.fn.extend({

        init: function() {
            var self = this;
            this.$headers.click(function() {
                var $this = $(this);
                if ($this.hasClass('selected')) {
                    $this.toggleClass('selected');
                    $this.next().slideUp({ duration: 500, easing: "easeOutCirc" });
                    self.$opened = null;
                }
                else {
                    if (self.$opened != null) {
                        self.$opened.prev().toggleClass('selected');
                        self.$opened.slideUp({ duration: 500, easing: "easeOutCirc" });
                    }
                    self.$opened = $this.next().slideDown({ duration: 500, easing: "easeOutCirc" });
                    $this.toggleClass('selected');
                }
            });
        }

    });

})(jQuery);
