// Google map code
var map = null;
var geocoder = null;

$(function() {
	initialize();
});

function initialize() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallZoomControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		
		geocoder = new GClientGeocoder();
		showAddress("6545 France Ave S, Edina, MN 55435");
	}
}

function showAddress(streetAddress) {
	var address = streetAddress;
	if (geocoder) {
		geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert(address + " not found");
			} else {
				map.setCenter(point, 9);
				var marker = new GMarker(point);
				map.addOverlay(marker);
	
				marker.openInfoWindowHtml(getDirections(address));
				GInfoWindowTab("title",  "content")
			}
		});
	}
}

function getDirections(destination){
	var formTxt = '<strong>Directions to:</strong><br />';
	formTxt = formTxt + "6545 France Ave S<br />Edina, MN 55435";
	formTxt = formTxt + '<br /><form method="get" action="http://maps.google.com/maps">';
	formTxt = formTxt + '<input type="hidden" name="daddr" value="'+destination+'" /> ';
	formTxt = formTxt + ' <input type="text" name="saddr" /><input type="submit" value="get directions" /></form>';
	return formTxt;
}

