/// class ProspectDirector.Types.Core.FeaturedObject

ProspectDirector.Types.Core.FeaturedObject = Class.extend({

    init: function (options) {

        this.options = $.extend({
            featureData: null,
            features: []
        }, options);

        this.init_features();

    },

    get_features: function () {
        return this.options.features;
    },

    init_features: function () {

        var featuresData = this.options.featureData,
            featureData = null,
            index = 0;

        for (index; index < featuresData.length; index++) {

            featureData = featuresData[index];
            featureData.selector = this.options.container + " " + featureData.selector;

            if (featureData.type !== undefined) {
                this.options.features[this.options.features.length] = new featureData.type(featureData);
            }
            else {
                this.options.features[this.options.features.length] = new ProspectDirector.Types.Core.Feature(featureData);
            }

        }

        if (this.options.features.length > 0) {
            this.options.features[0].select($(featuresData[0].selector));
        }

    },

    selectFeature: function (container) {

        var index = 0,
            feature = null,
            featureCount = this.get_features().length;

        for (index = 0; index < featureCount; index++) {

            feature = this.get_features()[index];

            if (feature.get_container().is(container)) {
                feature.select();
            }

        }

    },

    saveFeatures: function () {

        var index = 0,
            feature = null,
            features = this.get_features();

        for (index = 0; index < features.length; index++) {
            feature = features[index];
            feature.save();
        }

    },

    updateFeatures: function (dataSet) {

        var index = 0,
            data = null,
            feature = null,
            features = this.get_features();

        for (index; index < features.length; index++) {

            feature = features[index];

            data = dataSet[feature.get_id()];

            if (data !== undefined) {
                feature.update(data);
            }

        }

    },

    destroyFeatures: function () {

        var index = 0,
            feature = null,
            features = this.get_features();

        for (index = 0; index < features.length; index++) {
            feature = features[index];
            feature.destroy();
        }

    }

});

ProspectDirector.Types.Core.FeaturedObject.Dialog = function (id, title, url, height, width) {

    var result = null,
        config = {
            resizable: true
        };

        if (height !== undefined) {
            config.height = height ? height : 450;
        }

        if (width !== undefined) {
            config.width = width ? width : 550
        }

        result = new (ProspectDirector.Types.Core.Dialog.extend({

            init: function () {

                this._super(id, title, ProspectDirector.RUNTIME.resolveUrl(url), {
                    config: config
                });

            }

        }));

    return result;

}