/**

 * @namespace WPGMZA

 * @module Geocoder

 * @requires WPGMZA

 */

(function($) {

	

	WPGMZA.Geocoder = function()

	{

		WPGMZA.assertInstanceOf(this, "Geocoder");

	}

	

	WPGMZA.Geocoder.SUCCESS			= "success";

	WPGMZA.Geocoder.ZERO_RESULTS	= "zero-results";

	WPGMZA.Geocoder.FAIL			= "fail";

	

	WPGMZA.Geocoder.getConstructor = function()

	{

		switch(WPGMZA.settings.engine)

		{

			case "open-layers":

				return WPGMZA.OLGeocoder;

				break;

				

			default:

				return WPGMZA.GoogleGeocoder;

				break;

		}

	}

	

	WPGMZA.Geocoder.createInstance = function()

	{

		var constructor = WPGMZA.Geocoder.getConstructor();

		return new constructor();

	}

	

	WPGMZA.Geocoder.prototype.getLatLngFromAddress = function(options, callback)

	{

		if(WPGMZA.isLatLngString(options.address))

		{

			var parts = options.address.split(/,\s*/);

			var latLng = new WPGMZA.LatLng({

				lat: parseFloat(parts[0]),

				lng: parseFloat(parts[1])

			});

			callback([latLng], WPGMZA.Geocoder.SUCCESS);

		}

	}

	

	WPGMZA.Geocoder.prototype.getAddressFromLatLng = function(options, callback)

	{

		var latLng = new WPGMZA.LatLng(options.latLng);

		callback([latLng.toString()], WPGMZA.Geocoder.SUCCESS);

	}

	

	WPGMZA.Geocoder.prototype.geocode = function(options, callback)

	{

		if("address" in options)

			return this.getLatLngFromAddress(options, callback);

		else if("latLng" in options)

			return this.getAddressFromLatLng(options, callback);

		

		throw new Error("You must supply either a latLng or address");

	}

	

})(jQuery);