function addMapByLatLng(mapName, lattitude, longitude, streetAddress, zoomLevel) {

	document.getElementById(mapName).innerHTML="Loading...";

	var dAddress = escape(streetAddress);
	this.moveTimer = null;
	var cursor = new GLatLng(lattitude,longitude);
	var marker = new GMarker(cursor);

	buildMap(mapName, cursor, marker, dAddress, zoomLevel);
}

function addMapByAddress(mapName, streetAddress, zoomLevel) {
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(streetAddress, 
		function(cursor){
			var dAddress = escape(streetAddress);
			this.moveTimer = null;
			var marker = new GMarker(cursor);

			buildMap(mapName, cursor, marker, dAddress, zoomLevel);
		}
	);
}

function buildMap(mapName, cursor, marker, dAddress, zoomLevel){

	// create and display map
	var map = new GMap2(document.getElementById(mapName));
	
	// add map controls, center on location, and add location marker
	map.addControl(new GSmallZoomControl());
	map.addControl(new GMapTypeControl(1));
	map.setCenter(cursor, zoomLevel);
	map.addOverlay(marker);
	
	// add driving directions link
	GEvent.addListener(marker, "click", 
		function() {
			sAddress = escape(window.prompt("Enter Start address for driving directions:",""));
			if (sAddress&&sAddress!="null"){
				q = "?saddr=" + sAddress + "&daddr=" + dAddress;
				window.open("http://maps.google.com"+q,"directions","width=800,height=600,resizable, scrollbars");
			}
		}
	);
	
	// on pan, recenter map after 10 seconds idle
	GEvent.addListener(map, "moveend", 
		function(){
			window.clearTimeout(this.moveTimer);
			this.moveTimer = window.setTimeout(function(){map.panTo(cursor)}, 10000);
		}
	);
}