// These are locations that we'll typically create maps for.
var aldersgateLoc = new GLatLng(43.6222, -84.201);
var aldersgateLabel = "<p><b>Aldersgate United Methodist Church</b><br/>2206 Airfield Ln.<br/>Midland, MI</p>";

var mmiLoc = new GLatLng(43.6259, -84.251);
var mmiLabel = "<p><b>Michigan Molecular Institute</b><br/>1910 W. St. Andrews Rd.<br/>Midland, MI</p>";

var wheelerLoc = new GLatLng(43.6417, -84.2129);
var wheelerLabel = "<p><b>Wheeler Street Church of Christ</b><br/>1123 E. Wheeler St.<br/>Midland, MI</p>";

var messiahLoc = new GLatLng(43.5682, -84.24895);
var messiahLabel = "<p><b>Messiah Lutheran Church</b><br/>1550 S. Poseyville Rd.<br/>Midland, MI</p>";

var libraryLoc = new GLatLng(43.625378, -84.249076);
var libraryLabel = "<p><b>Grace A. Dow Memorial Library</b><br/>1710 W. St. Andrews Rd.<br/>Midland, MI</p>";

var firestation1Loc = new GLatLng(43.451394, -84.037648);
var firestation1Label = "<p><b>Firestation #1</b><br/>6171 Shattuck Rd.<br/>Saginaw Township, MI</p>";

// This function will return the most common map...centered around a single location with a label.
function createGoogleMap(latitude, longitude, zoom, mapElement, label) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(mapElement));
		var mapLocation = new GLatLng(latitude, longitude);
		map.setCenter(mapLocation, zoom);
		map.addControl(new GSmallZoomControl());
		
		var marker = new GMarker(mapLocation);
		map.addOverlay(marker);			
		marker.bindInfoWindowHtml(label);
		
		return map;
	}
}

// Call this function to get a blank map.  Must call setCenter before adding any markers.
function createBlankGoogleMap(mapElement) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(mapElement));
		map.addControl(new GSmallZoomControl());
		
		return map;
	}
}

// The following functions allow us to add any number of markers to a given map.
function addGLocMarkerToMap(map, gLoc, label) {
	if (GBrowserIsCompatible()) {
		var marker = new GMarker(gLoc);
		map.addOverlay(marker);
		marker.bindInfoWindowHtml(label);
	}
}

function addMarkerToMap(map, latitude, longitude, label) {
	if (GBrowserIsCompatible()) {
		var marker = new GMarker(new GLatLng(latitude, longitude));
		map.addOverlay(marker);			
		marker.bindInfoWindowHtml(label);
	}
}

// These functions are shortcuts to our most-used maps.
function aldersgateMap(mapElement)   { return createGoogleMap(  aldersgateLoc.lat(),   aldersgateLoc.lng(), 13, mapElement,   aldersgateLabel); }
function mmiMap(mapElement)          { return createGoogleMap(         mmiLoc.lat(),          mmiLoc.lng(), 13, mapElement,          mmiLabel); }
function wheelerMap(mapElement)      { return createGoogleMap(     wheelerLoc.lat(),      wheelerLoc.lng(), 13, mapElement,      wheelerLabel); }
function messiahMap(mapElement)      { return createGoogleMap(     messiahLoc.lat(),      messiahLoc.lng(), 13, mapElement,      messiahLabel); }
function libraryMap(mapElement)      { return createGoogleMap(     libraryLoc.lat(),      libraryLoc.lng(), 13, mapElement,      libraryLabel); }
function firestation1Map(mapElement) { return createGoogleMap(firestation1Loc.lat(), firestation1Loc.lng(), 13, mapElement, firestation1Label); }

// These functions are for adding labels for often-used locations.
function addAldersgateToMap(map, optionalPreLabel) { addGLocMarkerToMap(map, aldersgateLoc, optionalPreLabel + aldersgateLabel); }
function addMMIToMap(map, optionalPreLabel)        { addGLocMarkerToMap(map, mmiLoc,        optionalPreLabel + mmiLabel); }
function addWheelerToMap(map, optionalPreLabel)    { addGLocMarkerToMap(map, wheelerLoc,    optionalPreLabel + wheelerLabel); }
function addMessiahToMap(map, optionalPreLabel)    { addGLocMarkerToMap(map, messiahLoc,    optionalPreLabel + messiahLabel); }
function addLibraryToMap(map, optionalPreLabel)    { addGLocMarkerToMap(map, libraryLoc,    optionalPreLabel + libraryLabel); }

// These functions are for centering on often-used locations.
function centerMapOnAldersgate(map) { map.setCenter(aldersgateLoc, 13); }
function centerMapOnMMI(map)        { map.setCenter(mmiLoc, 13); }
function centerMapOnWheeler(map)    { map.setCenter(wheelerLoc, 13); }
function centerMapOnMessiah(map)    { map.setCenter(messiahLoc, 13); }
function centerMapOnLibrary(map)    { map.setCenter(libraryLoc, 13); }

// These functions will show/hide a map.  Right now, only toggleMap is used.
function showMap(mapID, showHideLinkID) {
	document.getElementById(mapID).display = "block";
	document.getElementById(showHideLinkID).innerHTML = "<a onclick=\"hideMap(document.getElementById('" + mapID + "'), document.getElementById('" + showHideLinkID + "'))\">Hide Map</a>";
}

function hideMap(mapID, showHideLinkID) {
	document.getElementById(mapID).display = "none";
	document.getElementById(showHideLinkID).innerHTML = "<a onclick=\"showMap(document.getElementById('" + mapID + "'), document.getElementById('" + showHideLinkID + "'))\">Show Map</a>";
}

function toggleMap(mapID, showHideLinkID) {
	if (document.getElementById(mapID).style.display == "none") {
		document.getElementById(mapID).style.display = "block";
		document.getElementById(showHideLinkID).innerHTML = "Hide Map";
	}
	else {
		document.getElementById(mapID).style.display = "none";
		document.getElementById(showHideLinkID).innerHTML = "Show Map";
	}
}
