	var map = null;
    var geocoder = null;

    $(document).ready(function() 
	{
		if (GBrowserIsCompatible()) {
		    map = new GMap2(document.getElementById("google_maps_canvas"));
		    geocoder = new GClientGeocoder();
		    if (google_coords_1 != 0 && google_coords_2 != 0 && google_address!='') {
		    	point = new GLatLng(google_coords_1, google_coords_2);
		    	placeMarker(point, google_address);
		    } else {
		    	map.setCenter(new GLatLng(34, 0), 1);
		    }
		    map.addControl(new GSmallMapControl());
    		map.addControl(new GMapTypeControl());
    		
    		GEvent.addListener(map, 'zoomend', 
    		function() 
    		{
    			google_zoom = map.getZoom();
                $("#google_zoom").val(map.getZoom());
        	}); 
		}
	});

	function generateGoogleMap(getLocationArrayById_url, selected_location_id, address_line_1, server_path, title, logo) {
		$.post(getLocationArrayById_url, {location_id: selected_location_id}, 
		function(data) {
			var address = 'Portugal, ';
			for (i=1; i<data.locations_array.length; i++) {
				address += data.locations_array[i] + ', ';
			}
			address += address_line_1;
			
			geocoder.getLocations(address, addAddressToMap);
		}, "json");
	}

	function addAddressToMap(response) {
		map.clearOverlays();
		if (!response || response.Status.code != 200) {
			alert("Sorry, we were unable to geocode that address");
		} else {
			place = response.Placemark[0];
			point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
			$("#google_coords_1").val(place.Point.coordinates[1]);
			$("#google_coords_2").val(place.Point.coordinates[0]);
			$("#google_address").val(place.address);
			placeMarker(point, place.address);
		}
	}
	
	function placeMarker(point, address)
	{
		marker = new GMarker(point);
		map.setCenter(point, parseInt(google_zoom));
		map.addOverlay(marker);
		var windowHtml = '';
		if (global_logo != '')
			windowHtml = '<img width="70px" align="left" style="padding-right: 10px;" src="' + global_server_path + '/users_images/logos/' + global_logo + '">';
		windowHtml += address + '<br>' + '<b>' + global_title + '</b><div class="clear_float"></div>';
		marker.openInfoWindowHtml(windowHtml);
	}