
kff.widgets.GoogleMap = function(options)
{
	this.options = $.extend({
		element: null,
		zoom: 8
	}, options);
};

kff.widgets.GoogleMap.prototype.init = function()
{
	this.$element = $(this.options.element);
	this.geocoder = new google.maps.Geocoder();
	this.googlemap = new google.maps.Map(this.$element.get(0), {
		zoom: this.options.zoom,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
};

kff.widgets.GoogleMap.prototype.zoomTo = function(address)
{
	this.geocoder.geocode(
		{
			address: address
		}, 
		$.proxy(function(results, status)
		{
			if(status == google.maps.GeocoderStatus.OK) 
			{
				this.googlemap.setCenter(results[0].geometry.location);
			}
		}, this));
};

kff.widgets.GoogleMap.prototype.showAddress = function(address, zoom)
{
	if(!zoom) zoom = 15;
	this.geocoder.geocode(
		{
			address: address
		}, 
		$.proxy(function(results, status)
		{
			if(status == google.maps.GeocoderStatus.OK) 
			{
				this.googlemap.setCenter(results[0].geometry.location);
				this.googlemap.setZoom(zoom);
				new google.maps.Marker({
					map: this.googlemap, 
					position: results[0].geometry.location
				});
			}
		}, this));
};

