var PopupManager = new Class({
    popups: [],

    add: function (popup) {
        this.popups.push(popup);
        popup.addEvent("onshow", function () {
            for (var i = 0; i < this.popups.length; i++) {
                var p = this.popups[i];
                if (p != popup && p.isOpen) {
                    p.hide();
                }
            }
        }.bind(this));

        return popup;
    },

    addAll: function(popups) {
        popups.each(function(popup) {
            this.add(popup);
        }.bind(this))
    }

});

/**
 * this class should be mixed to popup in order to add accessibility functionality
 * */
var PopupAccessibility = new Class({

    addSimpleAccessibility : function () {
        var links = this.targetEl.getElements("a");
        if (links && links.length > 0) {
            this.addAccessibility(links[0], links[links.length - 1]);
        }
    },

    /**
     *
     * @param firstLink
     * @param lastLink
     * */
    addAccessibility : function (firstLink, lastLink) {
        if (firstLink) {
            this._addFirstLinkEvents(firstLink);
        }

        if (lastLink) {
            this._addLastLinkEvents(lastLink);
        }
    },

    addKeyPressHandler :function () {
        this._triggerLink().addEvent("keypress", function (event) {
            if (event.key != 'enter' || this.inTransition) {
                return true;
            }

            if (this.isOpen) {
                this.hide();
            } else {
                this.show();
            }

            return true;
        }.bind(this));
    },

    _addFirstLinkEvents : function (firstLink) {
        this.addEvent('onshow', function() {
            firstLink.focus();
        });

        firstLink.addEvent('keypress', function(event) {
            if (event.key == 'tab' && event.shift) {
                this.hide();
                this._triggerLink().focus();
            }
        }.bind(this));
    },

    _addLastLinkEvents: function (lastLink) {
        lastLink.addEvent('keypress', function(event) {
            if (event.key == 'tab' && !event.shift) {
                this.hide();
                this._triggerLink().focus();
            }
        }.bind(this));
    },

    _triggerLink: function () {
        return this.triggerEl.nodeName == "A" ? this.triggerEl : this.triggerEl.getElement("a");
    }
});



/* UnCompressed - Reason: DISABLED_TARGET-LIVECWADEPLOYER# */

/*
Date: 12/4/2011 1:03:43 AM
All images published
*/
