fnz.bootstrap.modal = (function () {

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

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