MJL.event.add(window, "load", function() {
    MJL.enable.tab("tabs");
    MJL.enable.tab("tabs-inner", {
        tabFocusControl : false
    });
});


// ----------------------------------------------------------------------------
// MJL Extensions (2.2.x ONLY)
// ----------------------------------------------------------------------------
/^2\.2(\.|$)/.test(MJL.version) && (function () {
    //
    // tabFocusControl オプションを追加
    // false にすると aria:true であっても次の状態になる:
    //   * タブのフォーカス制御が無効になる
    //   * タブの切替キーバインドが無効になる
    //
    MJL.Tab.prototype.setOptions = (function () {
        var origin = MJL.Tab.prototype.setOptions;
        return function () {
            // オプションに tabFocusControl を設定可能とする
            if (!("tabFocusControl" in this.options)) {
                this.options.tabFocusControl = true;
            }
            origin.apply(this, arguments);
        };
    }());

    MJL.Tab.prototype._EVENTS.keydown = (function () {
        var origin = MJL.Tab.prototype._EVENTS.keydown;
        return function () {
            if (this.options.tabFocusControl) {
                origin.apply(this, arguments);
            }
        };
    }());

    MJL.Tab.prototype._activeARIA = (function () {
        var origin = MJL.Tab.prototype._activeARIA;
        return function (aid, id) {
            origin.apply(this, arguments);
            // 一旦変更したタブのフォーカス制御を取消
            if (this.options.aria && !this.options.tabFocusControl) {
                this.items[aid].anchor.tabIndex = 0;
            }
        };
    }());

    MJL.Tab.prototype._setARIA = (function () {
        var origin = MJL.Tab.prototype._setARIA;
        return function (aid, id) {
            var items, id;
            origin.apply(this, arguments);
            // 一旦設定したタブのフォーカス制御を解除
            if (this.options.aria && !this.options.tabFocusControl) {
                items = this.items;
                for (id in items) {
                    items[id].anchor.tabIndex = 0;
                }
            }
        };
    }());
}());

