var ShellBookmark = function() {

    var _self = this;

    var _shell_wrapper = null;
    var _bookmark_wraper = null;
    var _bookmark_wraper_content = null;
    var _btn_close = null;
    var _btn_no = null;
    var _btn_yes = null;

    var _parentIndex = 0;

    this.init = function() {

      //  console.log("ShellBookmark:   init...")
        _shell_wrapper = $("#shell_wrapper");

        _bookmark_wraper = $("#bookmark_wraper");
        _bookmark_wraper_content = $("#bookmark_wraper .g_popup_Container");

        _parentIndex = parseInt(_bookmark_wraper.parent().attr('tabindex')) + 1 || 0;

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

        addEvents();
    }

    var addEvents = function() {

      //  console.log("ShellBookmark:   addEvents...")

        _btn_no.off("click").on("click", function(e) {
            e.stopPropagation();
            var _data = {
                "popupName": "Bookmark",
                "isYes": false
            }
            _shell_wrapper.trigger("bookmarkHandler", _data);
        })

        _btn_yes.off("click").on("click", function(e) {
            e.stopPropagation();
            var _data = {
                "popupName": "Bookmark",
                "isYes": true
            }
            _shell_wrapper.trigger("bookmarkHandler", _data);
        });

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

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

    }

    var addTabIndex = function() {
        var _tabElements = {
            'elements': [{
                    'selector': _bookmark_wraper_content
                },
                {
                    'selector': _btn_yes,
                    'title': 'Yes'
                },
                {
                    'selector': _btn_no,
                    'title': 'No'
                }
            ],
            'sIndex': 1,
            'nIndex': 1
        };
        _shell_wrapper.trigger("addTabIndexing", _tabElements);
    }

    var openBookmark = function() {
        addTabIndex()
        setTimeout(function() {
            _bookmark_wraper_content.focus();
        }, 600)
    }

    return this;
};


$(document).ready(function() {
    var _shellBookmark = new ShellBookmark();
    _shellBookmark.init();
})