/**
 * GMap javascript file
 *
 * TODO add a loader while the map is loading ?
 *
 * @author Benjamin Grandfond <benjaming@theodo.fr>
 * @since  2009-12-15
 */

(function ()
{
  /**
   * Set the default center with the IP address of the client
   *
   * @author Benjamin Grandfond <benjaming@theodo.fr>
   * @since  2009-12-15
   */
  google.maps.Map.prototype.setDefaultCenter = function()
  {
    // Geolocalise le client
    var location = google.loader.ClientLocation;
    var zoom = 10;

    // Si le client a été géolocalisé
    if (location)
    {
      center_lat = location.latitude;
      center_lng = location.longitude;

      this.setCenter(new google.maps.LatLng(center_lat, center_lng), zoom);
    }
  }

  /**
   * Array of markers of the map
   */
  google.maps.Map.prototype.markers = new Array();

  /**
   * Add a marker to the array
   */
  google.maps.Map.prototype.addMarker = function(marker)
  {
    this.markers[this.markers.length] = marker;
  };

  /**
   * Return every markers
   */
  google.maps.Map.prototype.getMarkers = function()
  {

    return this.markers;
  };

  /**
   * Set all markers of the map
   */
  google.maps.Map.prototype.setMarkers = function(markers)
  {
    this.markers = markers;
  };

  /**
   * Remove every markers
   */
  google.maps.Map.prototype.clearMarkers = function()
  {
    for (var i = 0; i < this.markers.length; i++)
    {
      this.markers[i] .setMap(null);
    }

    this.markers = new Array();
  };

  /**
   * The opened info window
   */
  google.maps.Map.prototype.openedWindow = null;

  google.maps.Map.prototype.getOpenedWindow = function()
  {

    return this.openedWindow;
  }

  google.maps.Map.prototype.setOpenedWindow = function(infoWindow)
  {

    this.openedWindow = infoWindow;
  }

})();
