/******************************************************************************
 *
 *  Copyright 2008 David D. Emory [additional contributors append names here]
 *
 *  This file is part of Five Points. See <http://www.fpdev.org> for
 *  additional project information and documentation.
 *  
 *  Five Points is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  Five Points is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
 
/**
 * fp_map.js
 * 
 * Collection of global declarations and general-use functions supporting map
 * panel interactivity. Note that individual modules (e.g. the trip planner) may
 * provide their own collections of module-specific map definitions.
 */

// FIELD DECLARATIONS 

var fp_GMap_; // main google map object
var fp_GCoder_; // google geocoder object

// FUNCTION DEFINITIONS

/**
 * fp_initMap()
 * 
 * Initializes the map panel; called only when the page is (re)loaded. Creates
 * the actual GMap object and initializes the display options.
 */
function fp_initMap() {

  if (GBrowserIsCompatible()) {
    fp_GMap_ = new GMap2(document.getElementById("fp_map"));
    fp_GMap_.addControl(new GLargeMapControl());
    fp_GMap_.addControl(new GMapTypeControl());
    // location hard-coded for Atlanta for now:
    fp_GMap_.setCenter(new GLatLng(33.755, -84.39), 13);
    fp_GMap_.enableScrollWheelZoom();
    GEvent.addListener(fp_GMap_, "click", function(marker, point) {
      if(!marker) {
        fp_mapClick(point.x, point.y);
      //alert(point.x+" "+point.y);
      }
    });
    
    fp_GCoder_ = new GClientGeocoder();
  }
}

/**
 * fp_mapClick(x,y)
 *
 * Handles map mouse-click event.
 *
 * -- parameters --
 * x (Number): X-coord (longitude) of click location in decimal degrees
 * y (Number): Y-coord (latitude) of click location in decimal degrees
 */
function fp_mapClick(x,y) {
  fp_oTabSelected(FP_OUTPUT_LOCATIONS);
	
  var resultsDiv = fp_outputDivs_[FP_OUTPUT_LOCATIONS];
  resultsDiv.innerHTML = "Searching for nearby locations... ("+x+","+y+")";

  // currently the default map-click action:
  fp_doProximityRequest(x,y);
}