(function() {
    var overlay = undefined;
    Anno.classes.Overlay  = Anno.classes.Positioner.extend({
        constructor: function(element, options) {
            element.classList.add("overlay");
            Anno.classes.Overlay._super.constructor.call(this, element, options);
            this.event = "click.overlay{0} touchstart.overlay{0}".f(this.classId);
            this.keyEvent = "keypress.overlay{0}".f(this.classId);
        },
        visibleToggled: function(value, settings) {
            if (value) {
                if (settings.backdrop) {
                    document.querySelector(Anno.view).classList.add("block");
                }
                var self = this;
                if (!!overlay) overlay.model.visible = false;
                overlay = this;
                document.on(this.event, function(ev) {
                    if (!Anno.isChild(self.getPositionElement(), ev.target) && !Anno.isChild(self.element, ev.target)) {
                        ev.preventDefault();
                        self.model.visible = false;
                    }
                }).on("keydown", function(ev) {
                    if (ev.keyCode == 27) {
                        self.model.visible = false;
                    }
                })
            } else {
                overlay = null;
                document.off(this.event+" "+this.keyEvent);
                document.querySelector(Anno.view).classList.remove("block");
            }
        }
    });
})();
