ProspectDirector.Modules.Personalization.Preferences = (function (options) {

    var 

        PRIVATE = {

            init: function () {

                PRIVATE.init_splitter();
                PRIVATE.init_menu();

            },

            //---------------------------
            //--- PROPERTIES
            //---------------------------

            get_splitter: function () {
                return $("DIV[data-id=outer][data-role=splitter]");
            },

            get_menu: function () {
                return $("UL[data-id=menu]");
            },

            get_form: function () {
                return $("FORM[data-id=preferences]");
            },

            //---------------------------
            //--- INTIALIZERS
            //---------------------------

            init_menu: function () {

                PRIVATE.get_menu().data("menu", new ProspectDirector.Types.Core.Menu({
                    selector: PRIVATE.get_menu().selector,
                    select: $.proxy(this.menu_onSelect, this)
                }));

            },

            init_splitter: function () {

                new ProspectDirector.Types.Core.ViewportSplitter({
                    selector: PRIVATE.get_splitter().selector
                });

            },

            //---------------------------
            //--- EVENT HANDLERS
            //---------------------------

            menu_onSelect: function (e) {

                var command = $(e.item).data("command");

                switch (command) {

                    case "save":

                        PRIVATE.save();

                        break;

                }

            },

            //---------------------------
            //--- METHODS
            //---------------------------

            save: function () {

                ProspectDirector.Types.Core.Notifications.action("Saving...");

                PD.ajax({

                    type: PRIVATE.get_form().attr('method'),

                    url: PRIVATE.get_form().attr('action'),

                    data: PRIVATE.get_form().serialize(),

                    contextData: {
                        container: PRIVATE.get_form()
                    },

                    success: $.proxy(function (a, b, c) {

                        ProspectDirector.Types.Core.Notifications.success("Preferences Saved");

                    }, PRIVATE)

                });

            }

        },

        PUBLIC = {

        };

    PRIVATE.init();

    return PUBLIC;

});
