/**
 * @requires OpenLayers/OpenLayers.js
 */

/**
 * Class: GMES.Layer 
 * Inherits from:
 *  - <OpenLayers.Layer.WMS>
 */
GMES.Layer = OpenLayers.Class(OpenLayers.Layer.WMS, {
		
	 /**
     * APIProperty: region
     * {String}
     */
	region: null,
	
	 /**
     * APIProperty: product
     * {String}
     */
	product: null,
	
    /**
     * Constructor: GMES.Layer
     * Create a new GMES layer object
     *
     * Example:
     * (code)
     * var gmesLayer = new GMES.Layer("GMES Layer","Campania","Italian Land Use Map",
     *                                    "http://wms.geoway.de/gmes/mapserver", 
     *                                    {layers: "campania,italia"});
     * (end)
     *
     * Parameters:
     * name - {String} A name for the layer
     * region - {String} The name of the region
     * product - {String} The name of the product
     * url - {String} Base url for the WMS
     *                (e.g. http://wms.jpl.nasa.gov/wms.cgi)
     * params - {Object} An object with key/value pairs representing the
     *                   GetMap query string parameters and parameter values.
     * options - {Ojbect} Hashtable of extra options to tag onto the layer
     */
    initialize: function(name,region,product, url, params, options) {
    	this.region = region;
    	this.product = product;    	
    	params.transparent = true;
    	if(options == null){
    		options = {'reproject': true};
    	}else{
    		options.reproject = true
    	}
        var newArguments = [];        
        params = OpenLayers.Util.upperCaseObject(params);
        newArguments.push(name, url, params, options);
        OpenLayers.Layer.WMS.prototype.initialize.apply(this, newArguments);     
    },    

    /**
     * Method: destroy
     * Destroy this layer
     */
    destroy: function() {        
        OpenLayers.Layer.WMS.prototype.destroy.apply(this, arguments);  
    },

    
    /**
     * Method: clone
     * Create a clone of this layer
     *
     * Returns:
     * {<GMES.Layer>} An exact clone of this layer
     */
    clone: function (obj) {
        
        if (obj == null) {
            obj = new GMES.Layer(this.name,
                                           this.url,
                                           this.region,
                                           this.product,
                                           this.params,
                                           this.options);
        }        
        obj = OpenLayers.Layer.WMS.prototype.clone.apply(this, [obj]);        
        return obj;
    },
    
    toJSON: function(){
    	return Object.toJSON({
    		name: this.name,
    		region: this.region,
    		product: this.product,
    		url: this.url,
    		params: this.params,
    		options: this.options,
    		visibility: this.visibility,
    		opacity: this.opacity
    	});
    },           
    
    CLASS_NAME: "GMES.Layer"
});

