//Custom control for google map api
//use GControl interface

//Declaration du la class pour le controle de zoom
function TiviproZoomControl () {
}
TiviproZoomControl.prototype = new GControl();

//Creation des div pour chaque bouttons
TiviproZoomControl.prototype.initialize = function(map) {

  var container = document.createElement("div");
  //CSS de la boite de controle
  container.style.backgroundColor = "white";
  container.width = "22px";
  container.padding = "2px 2px 2px 4px";

  //Zoom In
  var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv);
  container.appendChild(zoomInDiv);
  zoomInDiv.innerHTML = '<img src="images/GoogleMap/plus.gif" alt="Zoom In" title="Zoomer"/>';
  GEvent.addDomListener(zoomInDiv, "click", function() {
    map.zoomIn();
  });

  //Zoom Out
  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.innerHTML = '<img src="images/GoogleMap/moins.gif" alt="Zoom Out" title="Dezoomer"/>';
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    map.zoomOut();
  });
  
  map.getContainer().appendChild(container);
  return container;

}

//Positionnement par defaut
TiviproZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 5));
}

//CSS appliqué au controle
TiviproZoomControl.prototype.setButtonStyle_ = function(button) {
  button.style.backgroundColor = "#F6F6F6";
  button.style.padding = "2px 0px 2px 2px";
  button.style.width = "23px";
  button.style.cursor = "pointer";
}

//Declaration du la class pour le controle du type de carte
function TiviproMapTypeControl() {
}
TiviproMapTypeControl.prototype = new GControl();

//Creation des div pour chaque bouttons
TiviproMapTypeControl.prototype.initialize = function(map) {

  var container = document.createElement("div");

  //Plan
  var PlanDiv = document.createElement("div");
  this.setButtonStyle_(PlanDiv);
  PlanDiv.style.background='url("images/GoogleMap/bt_orange1.gif") no-repeat left top';
  container.appendChild(PlanDiv);
  PlanDiv.appendChild(document.createTextNode("Plan"));
  PlanDiv.style.color = "white";

  //Satellite
  var SatDiv = document.createElement("div");
  this.setButtonStyle_(SatDiv);
  container.appendChild(SatDiv);
  SatDiv.appendChild(document.createTextNode("Satellite"));

  //Hybrid
  var MixDiv = document.createElement("div");
  this.setButtonStyle_(MixDiv);
  container.appendChild(MixDiv);
  MixDiv.appendChild(document.createTextNode("Mixte"));

  //Evenement sur le controle
  GEvent.addDomListener(PlanDiv, "click", function() {
    map.setMapType(G_NORMAL_MAP);
    PlanDiv.style.background='url("images/GoogleMap/bt_orange1.gif") no-repeat left top';
    SatDiv.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
    MixDiv.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
    PlanDiv.style.color = "white";
    SatDiv.style.color = "gray";
    MixDiv.style.color = "gray";
  });
  GEvent.addDomListener(PlanDiv, "mouseover", function() {
    PlanDiv.style.textDecoration = "underline";
  });
  GEvent.addDomListener(PlanDiv, "mouseout", function() {
    PlanDiv.style.textDecoration = "none";
  });

  GEvent.addDomListener(SatDiv, "click", function() {
    map.setMapType(G_SATELLITE_MAP);
    PlanDiv.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
    SatDiv.style.background='url("images/GoogleMap/bt_orange1.gif") no-repeat left top';
    MixDiv.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
    PlanDiv.style.color = "gray";
    SatDiv.style.color = "white";
    MixDiv.style.color = "gray";
  });
  GEvent.addDomListener(SatDiv, "mouseover", function() {
    SatDiv.style.textDecoration = "underline";
  });
  GEvent.addDomListener(SatDiv, "mouseout", function() {
    SatDiv.style.textDecoration = "none";
  });

  GEvent.addDomListener(MixDiv, "click", function() {
    map.setMapType(G_HYBRID_MAP);
    PlanDiv.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
    SatDiv.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
    MixDiv.style.background='url("images/GoogleMap/bt_orange1.gif") no-repeat left top';
    PlanDiv.style.color = "gray";
    SatDiv.style.color = "gray";
    MixDiv.style.color = "white";
  });
  GEvent.addDomListener(MixDiv, "mouseover", function() {
    MixDiv.style.textDecoration = "underline";
  });
  GEvent.addDomListener(MixDiv, "mouseout", function() {
    MixDiv.style.textDecoration = "none";
  });


  map.getContainer().appendChild(container);
  return container;

}

//Positionnement par defaut
TiviproMapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5));
}

//CSS appliqué au controle
TiviproMapTypeControl.prototype.setButtonStyle_ = function(button) {
  //button.style.backgroundColor = "#F6F6F6";
  button.style.background='url("images/GoogleMap/bt_gris1.gif") no-repeat left top';
  button.style.color = "gray";
  button.style.padding = "4px 10px";
  button.style.marginBottom = "3px";
  button.style.width = "22px";
  button.style.cursor = "pointer";
  button.style.display = "inline";
  button.style.fontWeight = "bold";
  //button.style.border = "1px outset red";

}
