// A PanoramiControl is a GControl that displays photos from Panoramio in the map

// We define the function first
function PanoramioControl() {
}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object
PanoramioControl.prototype = new GControl();

// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
PanoramioControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var panoramio_visible = false;
  var panoramio_layer = new GLayer("com.panoramio.all");
  var PanoramioDiv = document.createElement("div");
  PanoramioDiv.setAttribute('id', 'pano_label');
  this.setButtonStyle_(PanoramioDiv);
  container.appendChild(PanoramioDiv);
  PanoramioDiv.appendChild(document.createTextNode('Ver fotos de ésta zona'));
  GEvent.addDomListener(PanoramioDiv, "click", function() {
    if (!panoramio_visible) {
      map.addOverlay(panoramio_layer);
      panoramio_visible = true;
      $('pano_label').update("Ocultar fotos");
    } else {
      map.removeOverlay(panoramio_layer);
      panoramio_visible = false;
      $('pano_label').update("Ver fotos de ésta zona");
    }
  });

  map.getContainer().appendChild(container);
  return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
PanoramioControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(40, 25));
}

// Sets the proper CSS for the given button element.
PanoramioControl.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "none";
  button.style.color = "black";
  button.style.fontWeight = "bold";
  button.style.backgroundColor = "white";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "11em";
  button.style.cursor = "pointer";
}
