// A IrishGridControl is a GControl that displays switches
// on/off the grid layout.
function IrishGridControl() {
}
IrishGridControl.prototype = new GControl();

// Creates a one DIV for the button and places it 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.
IrishGridControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.style.border = "1px solid";

  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  container.appendChild(buttonDiv);
  buttonDiv.appendChild(document.createTextNode("Irish Grid"));
  buttonDiv.id = "IrishGrid";
  GEvent.addDomListener(buttonDiv, "click", function() {

    if(grat) {
      map.removeOverlay(grat);
      grat = null;
      var el = document.getElementById("BritishGrid");
      if(el && el.style.fontWeight != "normal" && el.style.fontWeight != 400){
        el.style.border = "1px outset";
        el.style.fontWeight = "normal";
        grat = new OGraticule(2);
        buttonDiv.style.border = "1px inset";
        buttonDiv.style.fontWeight = "bold";
        map.addOverlay(grat);
      } else {
        buttonDiv.style.border = "1px outset";
        buttonDiv.style.fontWeight = "normal";
      }

    } else {
      grat = new OGraticule(2);
      this.graticule = grat;
      buttonDiv.style.border = "1px inset";
      buttonDiv.style.fontWeight = "bold";
      map.addOverlay(grat);
    }
  });

  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.
IrishGridControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 28));
}

// Sets the proper CSS for the given button element.
IrishGridControl.prototype.setButtonStyle_ = function(button) {

  button.style.backgroundColor = "white";
  button.style.border = "1px outset";
  button.style.fontWeight = "normal";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}


// A GBGridControl is a GControl that displays switches
// on/off the grid layout.
function GBGridControl() {
}
GBGridControl.prototype = new GControl();

// Creates a one DIV for the button and places it 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.
GBGridControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.style.border = "1px solid";

  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  container.appendChild(buttonDiv);
  buttonDiv.appendChild(document.createTextNode("British Grid"));
  buttonDiv.id = "BritishGrid";
  GEvent.addDomListener(buttonDiv, "click", function() {
    if(grat) {
      map.removeOverlay(grat);
      grat = null;
      var el = document.getElementById("IrishGrid");
      if(el && el.style.fontWeight != "normal" && el.style.fontWeight != 400){
        el.style.border = "1px outset";
        el.style.fontWeight = "normal";
        grat = new OGraticule(1);
        buttonDiv.style.border = "1px inset";
        buttonDiv.style.fontWeight = "bold";
        map.addOverlay(grat);
      } else {
        buttonDiv.style.border = "1px outset";
        buttonDiv.style.fontWeight = "normal";
      }

    }
    else {
      grat = new OGraticule(1);
      buttonDiv.style.border = "1px inset";
      buttonDiv.style.fontWeight = "bold";
      map.addOverlay(grat);
    }
  });

  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.
GBGridControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(87, 28));
}

// Sets the proper CSS for the given button element.
GBGridControl.prototype.setButtonStyle_ = function(button) {

  button.style.backgroundColor = "white";
  button.style.border = "1px outset";
  button.style.fontWeight = "normal";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}

