/* $Id: googlemap.js 10831 2011-03-30 14:33:27Z mmawdsley $ */

function Google_Map ()
{
  /*
   * Used for internal referencing
   */
  var that = this;
  /*
   * Map options
   */
  that.map_options = {googleBarOptions : {style : "new"}};
  /*
   * Map object
   */
  that.map = null;
  /*
   * Zoom input
   */
  that.zoom_input = null;
  /*
   * Previous marker
   */
  that.previous_marker = null;
  
  /*
   * Sets up the map
   * @param float latitude initial latitude
   * @param float longitude initial longitude
   * @param string map_id ID of the map container
   * @param string map_type initial map type
   * @param integer zoom initial zoom level
   * @param boolean initial_mark whether to place a marker on the map
   */
  that.setup = function (latitude, longitude, map_id, map_type, zoom, initial_marker)
    {
      var container = null;     // Map container

      /*
       * Validate the container
       */
      
      container = document.getElementById (map_id);

      if (!container)
        return false;

      /*
       * Set up the map
       */
      
      that.map = new GMap2 (container, that.map_options);
      that.map.setCenter (new GLatLng (latitude, longitude));
      that.map.setZoom (zoom);
      that.map.setUIToDefault ();
      that.set_map_type (map_type);
      
      /*
       * Set the first point
       */
      
      if (initial_marker)
        that.place_marker (latitude, longitude);
      
    }

  /*
   * Places a marker on the map
   * @param float latitude
   * @param float longitude
   * @param char letter letter to use as the icon
   */
  that.place_marker = function (latitude, longitude, letter)
    {
      var url = null;           // URL of the map
      var marker = null;        // GMarker object
      var point = null;         // GLatLng object
      var options = null;
      
      point = new GLatLng (latitude, longitude);

      if (letter)
        {
          var baseIcon = new GIcon (G_DEFAULT_ICON);
          var letteredIcon = new GIcon (baseIcon);
          
          letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

          options = { icon: letteredIcon, title: "Title" }
          
        }
      else
        {
          options = { title: "Title" }

        }
      
      marker = new GMarker (point, options);
      
      that.map.addOverlay (marker);
      that.previous_marker = marker;

    }

  /*
   * Sets the initial map type
   * @param string map_type_id ID of the map type
   */
  that.set_map_type = function (map_type_id)
    {
      if (map_type_id == "m")
        that.map.setMapType (G_NORMAL_MAP);
      
      if (map_type_id == "k")
        that.map.setMapType (G_SATELLITE_MAP);
      
      if (map_type_id == "h")
        that.map.setMapType (G_HYBRID_MAP);
      
      if (map_type_id == "p")
        that.map.setMapType (G_PHYSICAL_MAP);
      
    }
  
}
