var customControl;

var tooltip = document.createElement("div");
tooltip.setAttribute("id","div_marker_tooltip");
tooltip.style.border="1px #666 solid";
tooltip.style.backgroundColor="#ffffff";
tooltip.style.fontWeight="bold";
tooltip.style.overflow="hidden";
          
function addCustomControl (innerHTML) {
    
    var innerHTML = innerHTML;
    
    removeCustomControl();
    
    function CustomControl() {
    }

    CustomControl.prototype = new GControl();

    CustomControl.prototype.initialize = function (map) {
      var container = document.createElement("div");
      this.setButtonStyle_(container);
      container.appendChild(document.createTextNode(''));
      map.getContainer().appendChild(container);
      return container;
    }

    CustomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(300, 250));
    }

    CustomControl.prototype.setButtonStyle_ = function(button) {
      button.innerHTML  = innerHTML;
      button.style.textDecoration = "underline";
      button.style.color = "#0000cc";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";
      button.style.padding = "20px";
      button.style.marginBottom = "3px";
      button.style.textAlign = "center";
      button.style.width = "150px";
      button.style.cursor = "pointer";
    }
    
    customControl = new CustomControl();
    
    map.addControl(customControl);
    map.disableDragging();
   
}

function removeCustomControl() {
    map.removeControl(customControl);
    map.enableDragging();
}

function showTooltip(marker) {
    tooltip.innerHTML = marker.tooltip;
    var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(), map.getZoom());
    var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(), map.getZoom());
    var anchor = marker.getIcon().iconAnchor;
    var width = marker.getIcon().iconSize.width;
    var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
    pos.apply(tooltip);
    tooltip.style.visibility="visible";
}