// A GLabel is a simple overlay that outlines a lat/lng bounds on the
// map. It has a border of the given weight and color and can optionally
// have a semi-transparent background color.
function GLabel(bounds, html) {
  this.bounds_ = bounds;
  this.weight_ = 1;
  this.color_ = "red";
  this.bgcolor_ = "#FFFFFF";
  this.html_ = html;
  this.div_ = document.createElement("div");
}
GLabel.prototype = new GOverlay();

// Creates the DIV representing this GLabel.
GLabel.prototype.initialize = function(map) {
  // Create the DIV representing our GLabel
  var div = this.div_ ;
  div.style.border = this.weight_ + "px solid " + this.color_;
  div.style.backgroundColor = this.bgcolor_;
  div.style.position = "absolute";
  div.style.textAlign = "center";
  div.innerHTML = this.html_;

  // Our GLabel is flat against the map, so we add our selves to the
  // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
  // below the marker shadows)
  map.getPane(G_MAP_MAP_PANE).appendChild(div);

  this.map_ = map;
  this.div_ = div;
}

// Remove the main DIV from the map pane
GLabel.prototype.remove = function() {
  this.div_.parentNode.removeChild(this.div_);
}

// Copy our data to a new GLabel
GLabel.prototype.copy = function() {
  return new GLabel(this.bounds_, this.html_);
}

// Redraw the GLabel based on the current projection and zoom level
GLabel.prototype.redraw = function(force) {
  // We only need to redraw if the coordinate system has changed
  if (!force) return;

  // Calculate the DIV coordinates of two opposite corners of our bounds to
  // get the size and position of our GLabel
  var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
  var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());

  // Now position our DIV based on the DIV coordinates of our bounds
  this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
  this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
  this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px";
  this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px";
}
