/* Copyright 2009 WeatherBill Inc.

 a WB pricing location is an object of the following form:

 {
   name: ...,
   latLng: ...,
   pricingId: ...
 }
 For example, SFO's Location object would be:

{
 name: "SFO",
 latLng: new GLatLng(37.271832, -119.270203),
 pricingId: "840023234",
 city: "San Francisco",
 state: "California"
}

*/
if (!wb) throw new Error("required module wb not loaded!");
wb.locations = wb.locations || {};
(function($){
   function legacy_location_to_location(l){
     return {
       name: l[0],
       latLng: new GLatLng(l[4], l[5]),
       pricingId: l[1],
       city: l[2],
       state: l[3]
     };
   }

   /**
    * Get locations function that works with legacy loctions api.
    * Memoize locations once converted from legacy format
    * to our format, since it gets fired every time the map moves.
    */
   var legacyLocations;
   function legacy_get_locations_function(center, getLocationsCallback){
     legacyLocations = legacyLocations || $.map(STATIONS, wb.locations.legacyLocationToLocation);
     getLocationsCallback(legacyLocations);
   }

   wb.locations.legacyLocationToLocation = legacy_location_to_location;
   wb.locations.legacyGetLocationsFunction = legacy_get_locations_function;
})(jQuery);
