/// class PD

(function () {

    var callBootFunctions = function () {
        for (var i = 0; i < PD.bootFunctions.length; i++) {
            PD.bootFunctions[i](PD);
        }
        PD.hasBooted = true;
    };

    PD = {
        ENVIRONMENT: {},
        messageStack: null,
        hasBooted: false,
        bootFunctions: [],
        context: null
    };

    PD.namespace = function (fqn) {

        var root = window,
            names = fqn.split("."),
            i = 0;

        for (i = 0; i < names.length; i++) {

            if (root[names[i]] === undefined) {
                root[names[i]] = {};
            }

            root = root[names[i]];

        }

        return root;

    };

    PD.boot = function (options) {

        PD.ENVIRONMENT = options;
        PD.context = new PD.Context.ContextManager();

        $(window).resize(PD.BCL.Util.debounce(function () {
            PD.context.get_global().get_events().publish("Window:Resized");
        }, 100));

        callBootFunctions();

    };

    PD.scope = function (element) {
        if (element !== undefined) {
            PD.ENVIRONMENT.SCOPE = element;
        }
        return PD.ENVIRONMENT.SCOPE;
    };

    PD.onBoot = function (fn) {

        if (this.hasBooted) {
            fn(this);
        }
        else {
            this.bootFunctions[this.bootFunctions.length] = fn;
        }

    };
    
    PD.namespace("PD.Web");
    PD.namespace("PD.Web.UI");
    PD.namespace("PD.Web.UI.Controls");
    PD.namespace("PD.Web.UI.Controls.Security");

})();

PD.onBoot(function (e) {
    PD.Commands.CommandRegistrar.registerGroup("pd/view-grid", PD.Web.UI.Controls.ViewGridCommands);
    PD.Commands.CommandRegistrar.registerGroup("pd/view-grid/context-menu", PD.Web.UI.Controls.ViewGridCommands);
    PD.Commands.CommandRegistrar.registerGroup("pd/view-grid/column/context-menu", PD.Web.UI.Controls.ViewGridColumnCommands);
});

PD.onBoot(function (e) {
    
    $.extend(Tipped.Skins, {
        "white": {
            radius: false
        },
        maxWidth: "300",
        hideAfter: 500,
        hideDelay: 0,
        showDelay: 500
    });

    $.extend(Tipped.Skins, {
        "white-no-padding": {
            radius: false
        },
        maxWidth: "300",
        hideAfter: 500,
        hideDelay: 0,
        showDelay: 500
    });

    $.extend(Tipped.Skins, {
        "validation-error": {
            radius: false,
            position: {
                target: "topleft",
                tooltip: "bottomleft"
            },
            maxWidth: "300",
            hideAfter: 500,
            hideDelay: 0,
            showDelay: 500
        }
    });
    
});