﻿/*

    Map legend object with standard panel functionality.
    
*/

function Legend(legendID){

    // Handle to self's DOM object.
    var _legend = null;
    
    _init();

    // Constructor
    function _init(){
        _legend = document.createElement('div');
        _legend.id = legendID;
        
        _legend.className = "ve_legend transparent";
        document.body.appendChild(_legend);
        
        _legend.innerHTML = _getContent();
    }
    
    // Getter for DOM object.
    function _getElement(){
        return _legend;
    }
    
    // Internal function to create legend content.
    function _getContent(){
        var content = "<table style='width:100%;'>" +
                            "<tr><th colspan='2'>Legend:</th></tr>" +
                            "<tr><td><img src='" + pinWireless + "'/></td><td>Wireless</td></tr>" + 
                            "<tr><td><img src='" + pinBroadcast + "'/></td><td>Broadcast</td></tr>" + 
                            "<tr><td><img src='" + pinInBuilding + "'/></td><td>In-Building</td></tr>" + 
                            "<tr><td><img src='" + pinRooftop + "'/></td><td>Rooftop</td></tr>" +
                        "</table>";
                        
        content += "<div id='legendContent'></div>";
                    
        return content;
    }

    // Repositions the legend as per given offsets.
    function _reposition(top, left){
        _legend.style.top = top + "px";
        _legend.style.left = left + "px";
    }
    
    // Shows the legend
    function _show(){
        _legend.style.display = "block";
    }
    
    // Hides the legend.
    function _hide(){
        _legend.style.display = "none";
    }
    
    // Sets the legend's content data.
    function _setContent(content){
        document.getElementById('legendContent').innerHTML = content;
    }
    
    /* Public accessors for the mentioned functions */
    
    this.GetElement = _getElement;
    this.Reposition = _reposition;
    this.Show = _show;
    this.Hide = _hide;
    this.SetContent = _setContent;
}