var ShellExit = function() {

    var _self = this;

    var _shell_wrapper = null;
    var _exit_wraper = null;
    var _exit_wraper_content = null;
    var _btn_close = null;
    var _btn_no = null;
    var _btn_yes = null;
    var _parentIndex = 0;

    this.init = function() {
      //  console.log("ShellExit:   init...")
        _shell_wrapper = $("#shell_wrapper");
        _exit_wraper = $("#exit_wraper");
        _exit_wraper_content = $("#exit_wraper .modal-content");
        _parentIndex = parseInt(_exit_wraper.parent().attr('tabindex')) + 1 || 0;

        _btn_close = _exit_wraper_content.find(".close_btn");
        _btn_no = _exit_wraper_content.find("#no_btn");
        _btn_yes = _exit_wraper_content.find("#yes_btn");

        addEvents();
    }

    var addEvents = function() {
      //  console.log("ShellExit:   addEvents...")
        var _data = {
            "popupName": "Exit"
        }

        _btn_no.off("click").on("click", function(e) {
            e.stopPropagation();
            Utils.addTabIndex()
            _shell_wrapper.trigger("closeExitGlobalPopup", _data);
        });

        _btn_yes.off("click").on("click", function(e) {
            e.stopPropagation();
            _shell_wrapper.trigger("closeExitGlobalPopup", _data);
            _shell_wrapper.trigger("exitProject");
        });

        _shell_wrapper.off("openExit").on("openExit", function(e) {
            e.stopPropagation();

            Utils.removeTabIndex()

            _shell_wrapper.trigger("OffTranscript")

            var _btn_play_pause_timer = $("#btn_play_pause_timer")
            _btn_play_pause_timer.trigger("click");

            openExit();

        });

        _shell_wrapper.off("closeExit").on("closeExit", function(e) {
            e.stopPropagation();
            var _btn_play_pause_timer = $("#btn_play_pause_timer")
            _btn_play_pause_timer.trigger("click");
        });


    }
    var addTabIndex = function() {
        var _tabElements = {
            'elements': [{
                    'selector': _exit_wraper_content
                },
                {
                    'selector': _btn_yes,
                    'title': 'Yes',
                    'role': 'button'
                },
                {
                    'selector': _btn_no,
                    'title': 'No',
                    'role': 'button'
                },

            ],
            'sIndex': 1,
            'nIndex': 1
        };
        _shell_wrapper.trigger("addTabIndexing", _tabElements);
    }

    var openExit = function() {
        addTabIndex()
        setTimeout(function() {
            _exit_wraper_content.focus();
        }, 600)
    }

    return this;
};

$(document).ready(function() {
    var _shellExit = new ShellExit();
    _shellExit.init();
})