var ShellHelp = function() {

    var _self = this;

    var _shell_wrapper = null;
    var _help_wraper = null;
    var _parentIndex = -1;
    var _btn_close = null;

    this.init = function() {
       // console.log("ShellHelp:   init...")
        _shell_wrapper = $("#shell_wrapper");
        _help_wraper = $("#help_wraper");
        _parentIndex = parseInt(_help_wraper.parent().attr('tabindex')) + 1 || -1;
        _btn_close = _help_wraper.find(".close_btn")
        addEvents();
    }



    var addEvents = function () {
       // console.log("ShellHelp:   addEvents...")
        _btn_close.off("click").on("click", function () {
            _shell_wrapper.trigger("closePopup")
            var _data = {
                'popupName': 'Help'
            }
            _shell_wrapper.trigger("closePopupGlobalPopup", _data);
            // $("#shell_wrapper").trigger("closeGlobalPopup");
        })

        _shell_wrapper.off("openHelp").on("openHelp", function (e) {
            e.stopPropagation();
            Utils.removeTabIndex()
            openHelp();
        });

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


    }


    var addTabIndex = function () {
        var _tabElements = {
            'elements': [{
                    'selector': "#help_popup_holder .modal-content"
                },
                {
                    'selector': "#help_popup_holder ul li>a"
                },
                {
                    'selector': _btn_close,
                    'title': 'Close'
                }
            ],
            'sIndex': 1,
            'nIndex': 1
        };
        _shell_wrapper.trigger("addTabIndexing", _tabElements);
    }

    var openHelp = function () {

      //  addTabIndex()

        let _help_popup_holder = $("#help_popup_holder .modal-content")

        let _lis_a = $("#help_popup_holder ul li>a")

        _help_popup_holder.trigger('focus');

        _btn_close.blur(function () {
            _help_popup_holder.focus();
        })

        // Utils.pauseTimer();
    }

    var closePopup = function () {
       // Utils.addTabIndex();        
        $("#shell_wrapper").trigger("closeGlobalPopup");
       // Utils.resumeTimer();
    }
 

    return this;
};

$(document).ready(function() {
    var _shellHelp = new ShellHelp();
    _shellHelp.init();
});