var startZoom 		= 15;
var description		= '<div><b>Santa Barbara KUMC</b></div>';
var iconImage		= '../images/umc_icon.jpg'

var map;
var mapPanel;
var directions;
var directionsPanel;

function addMarker(latitude, longitude, description) {
	var icon = new GIcon();
	icon.image = iconImage;
	icon.iconSize = new GSize(20,36);
	icon.iconAnchor = new GPoint(10,36);
	icon.infoWindowAnchor = new GPoint(10,10);
	
	var marker = new GMarker(new GLatLng(latitude, longitude), icon);
	
	GEvent.addListener(marker, 'click',
		function() {
			marker.showMapBlowup();
		}
	)
	
	map.addOverlay(marker);
}

function init() {
	mapPanel = document.getElementById("map");
	directionsPanel = document.getElementById("route");
	if (GBrowserIsCompatible() && mapPanel && directionsPanel) {
		map = new GMap2(mapPanel);
		var location = new GLatLng(marker.latitude, marker.longitude);
		map.setCenter(location, startZoom);
		
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		
		addMarker(marker.latitude, marker.longitude, description);
		
		directions = new GDirections(map, directionsPanel);
	}
}

window.onload 	= init;
window.onunload = GUnload;

function mapDirections() {
	if (GBrowserIsCompatible() && mapPanel && directionsPanel) {
		source = document.getElementById("source").value
		
		// Clear any previously displayed directions and load up the directions
		// for the current request.
		directions.clear();
		directions.load("from: " + source + " to: " + destination);
	}
}
