/**
 *
 * Functions dealing with the google maps addition to the page
 *
 */

// This function creates the map
function loadLatLang(map, lat, lng) {
	// Create new map object
	map = new GMap2(document.getElementById("map"));
	
	// Add the zoom control to the map
	map.addControl(new GSmallMapControl());

	// Center map and add markers
	addLatLangToMap(map, lat, lng);
}

function loadAddress(map, address) {
	// Create new map object
	map = new GMap2(document.getElementById("map"));
	
	// Add the zoom control to the map
	map.addControl(new GSmallMapControl());

	// Center map and add markers
	addAddressToMap(map, address);
}

// This function adds the point to the map
function addLatLangToMap(map, lat, lng) {
	// Retrieve the latitude and longitude
	point = new GLatLng(lat, lng);
	
	// Center the map on this point
	map.setCenter(point, 13);

	// Create a marker
	marker = new GMarker(point);

	// Add the marker to map
	map.addOverlay(marker);
}

// This function adds the point to the map
function addAddressToMap(map, address) {
	// Retrieve the latitude and longitude
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(address, function(point){
		if (point) {
			// Center the map on this point
			map.setCenter(point, 13);
		
			// Create a marker
			marker = new GMarker(point);
		
			// Add the marker to map
	map.addOverlay(marker);
		} else {
			alert('no');
		}
    }); 
}

