﻿/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */


/**
* @requires OpenLayers/Control.js
*/

/**
* Class: OpenLayers.Control.Information
*
* Inherits from:
*  - <OpenLayers.Control>
*/
OpenLayers.Control.Information = OpenLayers.Class(OpenLayers.Control, {


    /** 
    * Property: element
    * {DOMElement} 
    */
    element: null,

    message: '',

    setMessage: function(messageToShow) {
        this.message = messageToShow;
    },
    /**
    * Constructor: OpenLayers.Control.MousePosition
    * 
    * Parameters:
    * options - {DOMElement} Options for control.
    */
    initialize: function(options) {
        OpenLayers.Control.prototype.initialize.apply(this, arguments);
    },

    /**
    * Method: destroy
    */
    destroy: function() {
        if (this.map) {
            this.map.events.unregister('mousemove', this, this.redraw);
        }
        OpenLayers.Control.prototype.destroy.apply(this, arguments);
    },

    /**
    * Method: draw
    * {DOMElement}
    */
    draw: function() {
        OpenLayers.Control.prototype.draw.apply(this, arguments);

        if (!this.element) {
            this.div.left = "";
            this.div.top = "";
            this.element = this.div;
            this.element.style.display = "none";
        }

        this.redraw();
        return this.div;
    },

    /**
    * Method: redraw  
    */
    redraw: function(evt) {
        if (this.message != '' && this.message != null) {
            this.element.style.display = "block";
            this.element.style.width = "100%";
            this.element.style.filter = "alpha(opacity=70)";
            this.element.style.opacity = "0.7";
            this.element.style.fontSize = "11";
            this.element.style.background = "black";
            this.element.style.color = "white";
            this.element.innerHTML = this.message;
        }
        else {
            this.element.style.display = "none";
        }
    },


    /** 
    * Method: setMap
    */
    setMap: function() {
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
        this.map.events.register('mousemove', this, this.redraw);
    },

    CLASS_NAME: "OpenLayers.Control.Information"
});

