/*
 * traffic.js
 *
 * Copyright (c) 2006-2009 by Goose Networks, Inc.
 * Copyright (c) 2007, Google.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Derived from ExtMapTypeControl v1.3.
 */

function TrafficLegendControl() {};

TrafficLegendControl.prototype = new GControl();

/**
 * Method called by GMap2's addOverlay method.
 */ 
TrafficLegendControl.prototype.initialize = function(map) {
    var container;
    var legendDiv;
    var legendInfo;

    container = document.createElement("div");
    legendDiv = document.createElement("div");
    legendDiv.style.clear = "both";
    legendDiv.style.padding = "2px";
    legendDiv.style.border = "1px solid black";
    DOM.setStyle(legendDiv, 'background-color', '#ffffff');
    DOM.setStyle(legendDiv, 'font-family', 'Arial');
    DOM.setStyle(legendDiv, 'font-size', '12px');
    DOM.setStyle(legendDiv, 'font-weight', 'normal');
    DOM.setStyle(legendDiv, 'line-height', 'normal');
    legendInfo = [{"color": "#30ac3e", "text": "&gt; 50 MPH"},
                  {"color": "#ffcf00", "text": "25-50 MPH"},
                  {"color": "#ff0000", "text": "&lt; 25 MPH"},
                  {"color": "#c0c0c0", "text": "No data"}];
    for (var i = 0; i < legendInfo.length; i++) {
        legendDiv.innerHTML +=
            "<div style='text-align: left'><span style='background-color: " +
            legendInfo[i].color + "'>&nbsp;&nbsp</span>" +
            "<span style='color: " + legendInfo[i].color + "'> " +
            legendInfo[i].text + " </span>" + "</div>";
    }

    container.appendChild(legendDiv);
    map.getContainer().appendChild(container);

    return container;
};

/*
 * Method required by GMaps API for controls.
 */
TrafficLegendControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
};
