﻿// We define the function first
function TypeControl() {
}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object
TypeControl.prototype = new GControl();


TypeControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.id = "GMapTypeControl";
  
  //Detect IE6
  var isIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
  
  if (isIE6)
  {
      container.style.backgroundImage = "url('../../images/GoogleMapsIcons/bg_zoom_ie6.png')";
  }
  else
  {
      container.style.backgroundImage = "url('../../images/GoogleMapsIcons/bg_zoom.png')";
  }
  
  //Street
  var streetDiv = document.createElement("div");
  var streetTxt = streetDiv.className = 'Active';
  streetDiv.appendChild(document.createTextNode("Street"));
  if (isIE6)
  {
    streetDiv.style.marginLeft = '3px';
  }
  else
  {
    streetDiv.style.marginLeft = '7px';
  }
  streetDiv.className = 'Active';
  GEvent.addDomListener(streetDiv, "click", function() {
    map.setMapType(G_NORMAL_MAP);
    hybridDiv.className = '';
    streetDiv.className = 'Active';
    satelliteDiv.className = '';
  });
  container.appendChild(streetDiv);
  
  //Satellite
  var satelliteDiv = document.createElement("div");
  satelliteDiv.appendChild(document.createTextNode("Satellite"));
  GEvent.addDomListener(satelliteDiv, "click", function() {
    map.setMapType(G_SATELLITE_MAP);
    hybridDiv.className = '';
    streetDiv.className = '';
    satelliteDiv.className = 'Active';
  });
  container.appendChild(satelliteDiv);
  
  
  //Hybrid
  var hybridDiv = document.createElement("div");
  hybridDiv.appendChild(document.createTextNode("Hybrid"));
    GEvent.addDomListener(hybridDiv, "click", function() {
    map.setMapType(G_HYBRID_MAP);
    hybridDiv.className = 'Active';
    streetDiv.className = '';
    satelliteDiv.className = '';
  });
  container.appendChild(hybridDiv);
  
  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.
TypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}
