// Google Maps API

//<![CDATA[
if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(41.179173, -77.317657), 6);
	    map.addControl(new GLargeMapControl());


		// arrays to hold copies of the markers and html used by the side_bar
		var side_bar = "";
		var gmarkers = [];
		var i = 0;
		
		// Create our Corp marker icon
		var icon_Corp = new GIcon();
		icon_Corp.image = "images/Corp.png";
		icon_Corp.iconSize = new GSize(42, 30);
		icon_Corp.iconAnchor = new GPoint(6, 20);
		icon_Corp.infoWindowAnchor = new GPoint(20, 20);
		
		// Create our Office marker icon
		var icon_Office = new GIcon();
		icon_Office.image = "images/Office.png";
		icon_Office.iconSize = new GSize(25, 25);
		icon_Office.iconAnchor = new GPoint(6, 20);
		icon_Office.infoWindowAnchor = new GPoint(20, 20);

		// Create our Nursing/Office share marker icon
		var icon_Nursing = new GIcon();
		icon_Nursing.image = "images/Nurse.png";
		icon_Nursing.iconSize = new GSize(25, 25);
		icon_Nursing.iconAnchor = new GPoint(6, 20);
		icon_Nursing.infoWindowAnchor = new GPoint(20, 20);
		
		// Create our Nursing marker icon
		var icon_NO = new GIcon();
		icon_NO.image = "images/NurseOffice.png";
		icon_NO.iconSize = new GSize(45, 28);
		icon_NO.iconAnchor = new GPoint(6, 20);
		icon_NO.infoWindowAnchor = new GPoint(20, 20);
						
		// Creates a marker at the given point with the given number label
		function createMarker(point, description, icon_type, location) {
			if (icon_type == "Nursing")
				var marker = new GMarker(point, icon_Nursing);
			else if (icon_type == "Office")
				var marker = new GMarker(point, icon_Office);
			else if (icon_type == "Corp")
				var marker = new GMarker(point, icon_NO);
			else  // (icon_type == "Corp")
				var marker = new GMarker(point, icon_Corp);
		
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(description + '<br/>' + '<a href="' + location + '" target="_blank">' + location + '</a>');
			});
			
			// save the info we need to use later for the side_bar
			gmarkers[i] = marker;
			// add a line to the side_bar html
			side_bar += '<a href="javascript:PopMsgClr();" onClick="myclick(' + i + ')" style="padding: 2px 0px 2px 10px">' + description + '</a><br/>';
			i++;

			return marker;
		}
		
		// This function picks up the click and opens the corresponding info window
		function myclick(i) {
			GEvent.trigger(gmarkers[i], "click");
		}
		function PopMsgClr() {
			window.status='';
		}
		
		// Download the data in data.xml and load it on the map.
		GDownloadUrl("map.xml", function(data, responseCode) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			var labels = xml.documentElement.getElementsByTagName("label");  // There must a a label for every marker
			var types = xml.documentElement.getElementsByTagName("type");
			var links = xml.documentElement.getElementsByTagName("hyperlink");
			var menu = document.getElementById("nav");
			
			for (var i = 0; i < markers.length; i++) {
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); 
				var description = labels[i].getAttribute("lab");
				var icon_type = types[i].getAttribute("typ");
				var location = links[i].getAttribute("url");
				map.addOverlay(createMarker(point, description, icon_type, location));
			}

		});
	} // end if
//]]>