/*
 * Copyright 2008 Institut Geographique National France, released under the
 * BSD license.
 */
/**
 * Class: Geoportal.Control
 * The Geoportal framework controlers base class.
 */
Geoportal.Control= OpenLayers.Class( OpenLayers.Control, {

    /**
     * Constructor: Geoportal.Control
     * Create a Geoportal Control.  The options passed as a parameter
     * directly extend the control.  For example passing the following:
     *
     * > var control = new Geoportal.Control({div: myDiv});
     *
     * Overrides the default div attribute value of null.
     *
     * Parameters:
     * options - {Object}
     */
    initialize:function(options) {
        // We do this before the extend so that instances can override className in options.
        this.displayClass= this.CLASS_NAME.replace("Geoportal.","gp").replace(/\./g,"");

        OpenLayers.Util.extend(this,options);
        this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
        if(this.eventListeners instanceof Object) {
            this.events.on(this.eventListeners);
        }
        if (this.id==null) {
            this.id= OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_");
        }
    },

    /**
     * APIMethod: changeLang
     * Assign the current language.
     *      Should be overridden by sub-classes.
     *
     * Parameters:
     * evt - {Event} event fired.
     *      evt.lang holds the new language
     */
    changeLang: function(evt) {
    },

    /**
     * Constant: CLASS_NAME
     * {String} *"Geoportal.Control"*
     */
    CLASS_NAME:"Geoportal.Control"
});

/**
 * APIFunction: selectFeature
 * Default Geoportal behavior function when selecting feature : a popup is
 * created.
 *
 * Parameters:
 * feature - {<OpenLayers.Feature.Vector>} the selected feature.
 */
Geoportal.Control.selectFeature= function(feature) {
    if (feature) {
        if (!feature.popup) {
            feature.createPopup();
        }
        if (feature.layer && feature.layer.map && feature.popup) {
            feature.layer.map.addPopup(feature.popup);
        }
    }
};

/**
 * APIFunction: unselectFeature
 * Default Geoportal behavior function when unselecting feature : the popup is
 * removed and destroyed.
 *
 * Parameters:
 * feature - {<OpenLayers.Feature.Vector>} the feature that got unselected.
 */
Geoportal.Control.unselectFeature= function(feature) {
    if (feature) {
        if (feature.popup) {
            feature.popup.destroy();
            feature.popup= null;
        }
    }
};

