﻿//Function to call all markers
   	// Creates a marker at the given point with the given number label
function createGameMarker(point, gameNumber) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("Marker #<b>" + gameNumber + "</b>");
	});
	return marker;
}

function loadMap(coordlat,coordlng,mapID) { //coordlat and coordlng are passed from main document
	if (GBrowserIsCompatible()) {	//checks to see if Browser is compatible
		//create variable map equal to div with ID map
		var map = new GMap2(document.getElementById(mapID));

		//Add controls
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		//Center map using coordlat and coordlng passed from main document; zoom level 13
		map.setCenter(new GLatLng(coordlat,coordlng), 4);
		//display the original coordlat and coordlng in <p> with id coord below map
		/* commented out because of new version of map inside div instead of iframe
		document.getElementById("coord").innerHTML = coordlat+", "+coordlng.toString();
		*/
		//Add listener for getCenter function
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			//Display Lat and Long in <p> with id coord below map
			document.getElementById("coord").innerHTML = center.toString();
		})
		// to add a pre-defined marker
		//var point = new GLatLng(coordlat,coordlng);
  		//map.addOverlay(new GMarker(point));
  		
  		// To add a marker with a click event
  		//GEvent.addListener(map, "click", function(marker, point) {
  		//	if (marker) {
  		//		map.removeOverlay(marker);
  		//	} else {
  		//		map.addOverlay(new GMarker(point));
  		//	}
  		//});
		
		//To add a Info Window
		//map.openInfoWindow(map.getCenter(),
                   //document.createTextNode("Hello, world"));
		
		
		/*commented out until I can figure out how to make the markers
		for (var i = 0; i < 2; i++) {
			var gameCoord = new Array(2);
				gameCoord[0] = "27.9111,-82.8451";
				gameCoord[1] = "44.284537,-69.604225";
				
			var point = GLatLng(gameCoord[i]);
			map.addOverlay(createGameMarker(point, i + 1));
			}*/
		
	}
	else {	//if browser is not compatible
		document.write("<p>This browser is not compatible with Google maps</p>");
	}
}