// GOOGLE MAPS STUFF
var startZoom = 13;

var map;

// Creates a marker at the given point
// Clicking the marker will hide it
function createMarker(latlng, infoHtml) {
	var marker = new GMarker(latlng);
	
	var addInfoWinFunc = function() {
	  var myHtml = infoHtml;
	  map.openInfoWindowHtml(latlng, myHtml);
	};
	
	GEvent.addListener(marker,"click", addInfoWinFunc);
	addInfoWinFunc();
	return marker;
}

function initMap(name, address, lat, lng) 
{
	if (GBrowserIsCompatible()) {
       	map = new GMap2(document.getElementById("cavamap"));
       	var location = new GLatLng(lat, lng);
       	map.setCenter(location, startZoom);
				var mapInfoTxt = "<b>"+name+"</b><br/>"+address;
				map.addOverlay(createMarker(location, mapInfoTxt));
	}
}

// Get directions function
var directions;

function doDir(fromaddress, toaddress) {
	var dirPanel = document.getElementById("directions");
	// dirPanel.innerHtml = ""; //clear the div before filling it with the directions
	if (typeof directions == "undefined") {	directions = new GDirections(map, dirPanel);}
	//alert('from: ' + fromaddress + ' to: ' + toaddress);
	directions.load('from: ' + fromaddress + ' to: ' + toaddress);
	return false;
}

addEvent(window, 'unload', GUnload);
