﻿var newActive = -1;
$.accordian = function(options) {

    options = jQuery.extend({
        titles: '.category',
        contents: '.list_menu',
        active: 'none',
        onClick: function() { },
        onShow: function() { },
        onHide: function() { },
        showSpeed: 'slow',
        hideSpeed: 'fast'
    }, options);

    function activate(item) {
        $(options.titles).each(function(i) {
            if (item == i) {
                if (i == newActive) {
                    $(this).next(options.contents).slideUp(options.hideSpeed).each(options.onHide);
                    newActive = -1;
                } else {
                    $(this).next(options.contents).slideDown(options.showSpeed).each(options.onShow);
                    newActive = i;
                }
            } else {
                $(this).next(options.contents).slideUp(options.hideSpeed).each(options.onHide);
            }
        });
    }

    function hidesParts() {
        $(options.contents).each(function() {
            $(this).hide();
        });
        $(options.titles).each(function() {
        });
    }

    $(options.titles).each(function(i) {
        $(this).click(function() {
            activate(i);
        });
    });

    if (options.active == 'none') {
        hidesParts();
    } else {
        activate(options.active);
    }
};
