fnz.bootstrap.collapse = (function () {

    function getInst(id) { return bootstrap.Collapse.getInstance(fnz.getEl(id)); }

    return {
        init: function (id, jsonOptions, dotNetRef) {
            var options = JSON.parse(jsonOptions);
            var el = fnz.getEl(id);
            new bootstrap.Collapse(el, options);
            el.addEventListener('shown.bs.collapse', function () { dotNetRef.invokeMethodAsync("OnShown"); })
            el.addEventListener('hidden.bs.collapse', function () { dotNetRef.invokeMethodAsync("OnHidden"); })
        },
        dispose: function (id, dotNetRef) {
            var inst = getInst(id);
            if (inst) inst.dispose();
        },
        sync: function (id, options, dotNetRef) { },
        show: function (id, dotNetRef) { getInst(id).show() },
        hide: function (id, dotNetRef) { getInst(id).hide() },
        toggle: function (id, dotNetRef) { getInst(id).toggle() }
    }
})();
