
// This definition is taken from the xsl/macros.xsl.m4 definition file.

//
// This file contains the JavaScript to be able to add the Map Types controls
//  onto a Google Map displayed on TripAdvisor.
//	Note: that the placement implies the existance of the Maps Saves (defined in gmapOthers.js.m4)
//
//	@author 	mhoule
//  @since     14 March 2007
//

/* ============================================================= */
/*  Hybrid Google Map Control  */
/*  Display a control allow the user to change to Hybrid view */
/* ============================================================= */
function TA_HybridControl(map)
{
}

TA_HybridControl.prototype = new GControl();

TA_HybridControl.prototype.initialize = function( map )
{
 	/*	We need a way to create this control and put in the properly
 	    Translated Strings and Images */
  var containerDiv = document.createElement("div");
  containerDiv.style.backgroundColor = "transparent";

  var Img = document.createElement("img");
  Img.id = "TA_HybridControlImg";
  Img.src = sImgHybridOff; 
  Img.alt = sSwitchToHybrid ;
  Img.style.cursor = "pointer";
  GEvent.addDomListener(Img, "click", function() {
    map.setMapType(G_HYBRID_MAP);
    setMapTypeImages(G_HYBRID_MAP);
  } );

  containerDiv.appendChild(Img);

  map.getContainer().appendChild(containerDiv);

  return containerDiv;
}

TA_HybridControl.prototype.getDefaultPosition = function()
{
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(117, 6));
}

TA_HybridControl.prototype.printable = function()
{
  return false;
}

TA_HybridControl.prototype.selectable = function()
{
  return false;
}

/* ============================================================= */
/*  Satellite Google Map Control  */
/*  Display a control allow the user to change to Satellite view */
/* ============================================================= */
function TA_SatelliteControl( )
{
}

TA_SatelliteControl.prototype = new GControl();

TA_SatelliteControl.prototype.initialize = function( map )
{
 	/*	We need a way to create this control and put in the properly
 	    Translated Strings and Images */
  var containerDiv = document.createElement("div");
  containerDiv.style.backgroundColor = "transparent";

  var Img = document.createElement("img");
  Img.id = "TA_SatelliteControlImg";
  Img.src = sImgSatOff;
  Img.alt = sSwitchToMap;
  Img.style.cursor = "pointer";
  GEvent.addDomListener(Img, "click", function() {
    map.setMapType(G_SATELLITE_MAP);
    setMapTypeImages(G_SATELLITE_MAP);
  } );

  containerDiv.appendChild(Img);

  map.getContainer().appendChild(containerDiv);

  return containerDiv;
}

TA_SatelliteControl.prototype.getDefaultPosition = function()
{
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(183, 6));
}

TA_SatelliteControl.prototype.printable = function()
{
  return false;
}

TA_SatelliteControl.prototype.selectable = function()
{
  return false;
}

/* ============================================================= */
/*  NORMAL Google Map Control  */
/*  Display a control allow the user to change to Hybrid view */
/* ============================================================= */
function TA_NormalControl( )
{
}

TA_NormalControl.prototype = new GControl();

TA_NormalControl.prototype.initialize = function( map )
{
 	/*	We need a way to create this control and put in the properly
 	    Translated Strings and Images */
  var containerDiv = document.createElement("div");
  containerDiv.style.backgroundColor = "transparent";

  var Img = document.createElement("img");
  Img.id = "TA_NormalControlImg";
  Img.src = sImgMapOn;
  Img.alt = sSwitchToSat;
  Img.style.cursor = "pointer";
  GEvent.addDomListener(Img, "click", function() {
    map.setMapType(G_NORMAL_MAP);
    setMapTypeImages(G_NORMAL_MAP);
  } );

  containerDiv.appendChild(Img);

  map.getContainer().appendChild(containerDiv);

  return containerDiv;
}

TA_NormalControl.prototype.getDefaultPosition = function()
{
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(250, 6));
}

TA_NormalControl.prototype.printable = function()
{
  return false;
}

TA_NormalControl.prototype.selectable = function()
{
  return false;
}

//	Set the Map Type Image based on the Google Map Type
function setMapTypeImages(type)
{
  var normal = document.getElementById('TA_NormalControlImg');
  var satellite = document.getElementById('TA_SatelliteControlImg');
  var hybrid = document.getElementById('TA_HybridControlImg');

  if (normal)
  {
    normal.src = (type == G_NORMAL_MAP)? sImgMapOn : sImgMapOff;
  }
  if (satellite)
  {
    satellite.src = (type == G_SATELLITE_MAP)? sImgSatOn : sImgSatOff;
  }
  if (hybrid)
  {
    hybrid.src = (type == G_HYBRID_MAP)? sImgHybridOn : sImgHybridOff;
  }
}

