// This javascript file adds a google map to a div in the DOM
	
	var gContainer = "postContentDiv";
	var gMap;
	var gGeocoder;
	var gPoint;
	var gPointCenter;
	var gIcon;
	
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon();
	baseIcon.shadow = "/img/mapiconshadow.png";
	baseIcon.iconSize = new GSize(38, 37);
	baseIcon.shadowSize = new GSize(53, 40);
	baseIcon.iconAnchor = new GPoint(17, 37);
	baseIcon.shadowAnchor = new GPoint(15, 38);
	baseIcon.infoWindowAnchor = new GPoint(15, 2);
	baseIcon.infoShadowAnchor = new GPoint(30, 26);
	
	// addAddressToMap() is called when the geocoder returns an
	// answer.  It adds a marker to the map with an open info window
	// showing the nicely formatted version of the address and the country code.
	function addAddressToMap(response) {
		gMap.clearOverlays();
		if (!response || response.Status.code != 200) {
			alert("Sorry, we were unable to geocode that address");
		} else {
			gPoint = new GLatLng(33.701950,-117.861800);
			gPointCenter = new GLatLng(33.703903,-117.861242);
			
			gMap.setCenter(gPointCenter, 15);
			
			gIcon = new GIcon(baseIcon);
			gIcon.image = "/img/mapicon_fa.png";
			markerOptions = { icon:gIcon };
			var marker = new GMarker(gPoint, markerOptions);
			gMap.addOverlay(marker);
			
			var infoHTML = "<strong>The First American Corporation</strong><br />"+
				"1 First American Way<br />"+
				"Santa Ana, California 92707<br />"+
				"Get directions: <a href='http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=&daddr=First+American+Way+S+%4033.701922,+-117.862245&sll=33.702981,-117.86219&sspn=0.011585,0.020084&ie=UTF8&z=16' target='_blank'>To here</a>"+
				" - <a href='http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=First+American+Way+S+%4033.701922,+-117.862245&daddr=&sll=33.702981,-117.86219&sspn=0.185366,0.32135&ie=UTF8&z=16' target='_blank'>From here</a><br />"+
				"<a href='http://maps.google.com/maps?f=l&hl=en&geocode=&q=&near=First+American+Way+S+%4033.701922,+-117.862245&sll=33.702981,-117.86219&sspn=0.046342,0.080338&ie=UTF8&z=16&iwloc=addr' target='_blank'>Search nearby</a>";
			
			marker.openInfoWindowHtml(infoHTML);
			
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(infoHTML);
			});
		}
	}
	
	function MakeMap(){
		gMap = new GMap2(document.getElementById(gContainer));
		gMap.addControl(new GLargeMapControl());
		gMap.addControl(new GMapTypeControl());
		gGeocoder = new GClientGeocoder();
		gGeocoder.getLocations("1 First American Way, Santa Ana, California 92707", addAddressToMap);
	}
			
	addEvent(window, "load", MakeMap);
	addEvent(window, "unload", GUnload);