// 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("178 East 9th Street, St. Paul, MN 55101");
	}
}

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 BioMedix</strong><br />';
	formTxt = formTxt + "178 East 9th Street<br />St. Paul, MN 55101";
	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;
}

