var address="";
var city="New York";
var title="New York";

function InitGMap(addresss,cityy,titlee)
{
	address=addresss;
	city=cityy;
	title=titlee;
	if(geocoder==null)
	{
		initialize();
	}
	showAddress();
}

function ReloadGMap(addresss,cityy,titlee)
{
	address=addresss;
	city=cityy;
	title=titlee;

	showAddress();
}

var map = null;
var geocoder = null;

function initialize() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(40.394533, -3.647461), 6);
		map.addControl(new GSmallMapControl());
		geocoder = new GClientGeocoder();
	}
}

function showAddress() {
	if (geocoder) {
		geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				geocoder.getLatLng(
				city,
				function(point) {
					if (!point) {
						return false;
					} else {
						map.setCenter(point, 11);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						GEvent.addListener(marker, "click", function()
						{marker.openInfoWindowHtml(title);});
					}
				});
			} else {
				map.setCenter(point, 11);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				GEvent.addListener(marker, "click", function()
				{marker.openInfoWindowHtml(title);});
			}
		});
	}
}
