if (GBrowserIsCompatible()) {
	// Create a map object
	var map = new GMap2(document.getElementById('google-map'));
	var directions = new GDirections(map, document.getElementById('directions'));
	map.setCenter(new GLatLng(29.7268184, -95.3874972), 15);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.enableScrollWheelZoom();
	
	var point = new GLatLng(29.7268184, -95.3874972);
	// console.log(point);
	var marker = new GMarker(point);
	var html = '<strong>Venue Museum District</strong><br />5353 Fannin<br />Houston, TX 77004<br />';
	var default_html = html + 'Directions: <a href="javascript: directionsTo();">To</a> - <a href="javascript: directionsFrom();">From</a><br /><br />';
	var to_html = html +
		'Directions: <strong>To</strong> - <a href="javascript: directionsFrom();">From</a><br />' +
		'Start address: ' +
		'<input type="text" id="start_address" name="start_address" value="" style="width: 125px;" /> ' +
		'<input type="button" value="Go" onclick="setDirections(Ext.get(\'start_address\').getValue(), Ext.get(\'end_address\').getValue());"> ' +
		'<input type="hidden" id="end_address" name="end_address" value="' + point.lat() + ',' + point.lng() + '"/>';
	var from_html = html +
		'Directions: <a href="javascript: directionsTo();">To</a> - <strong>From</strong><br />' +
		'End address: ' +
		'<input type="text" id="end_address" name="end_address" value="" style="width: 125px;" /> ' +
		'<input type="button" value="Go" onclick="setDirections(Ext.get(\'start_address\').getValue(), Ext.get(\'end_address\').getValue());"> ' +
		'<input type="hidden" id="start_address" name="start_address" value="' + point.lat() + ',' + point.lng() + '"/>';

	GEvent.addListener(directions, 'addoverlay', function() {
		if (directions.getStatus().code == 200) {
			Shadowbox.open({
				content: '<div style="margin: 10px; margin-top: 0px;">' + document.getElementById('directions').innerHTML + '</div>',
				player: 'html',
				height: 450,
				width: 650
			});
		}
	});
	
	GEvent.addListener(directions, 'error', function() {
		if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
			alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);
		else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
			alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);
		else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
			alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);
		else if (directions.getStatus().code == G_GEO_BAD_KEY)
			alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);
		else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
			alert("A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);
		else alert("An unknown error occurred.");
	});

	GEvent.addListener(marker, 'click', function() {
		map.openInfoWindowHtml(point, default_html);
	});
	map.addOverlay(marker);
	marker.openInfoWindowHtml(default_html);

	function directionsTo() {
		map.openInfoWindowHtml(point, to_html);
	}
	
	function directionsFrom() {
		map.openInfoWindowHtml(point, from_html);
	}
	
	function setDirections(fromAddress, toAddress) {
		directions.load("from: " + fromAddress + " to: " + toAddress);
	}
}