/**
 * @name FIA Roster Map Init
 * @version 1.0
 * @author Mike Stecker
 * @fileoverview Creates a map pulling data from a simple RSS feed and
 * displays points on the map using a control with buttons to pan in four directions,
 * and zoom in and zoom out, and a zoom slider. The UI is based on the 
 * LargeMapControl from Google Maps (circa December 2008), but it does not
 * have any integration with Street View.
 */
 
 	var map;
	var extLargeMapControl;

	function load() {
      
		map = new GMap2(document.getElementById("roster_map"));
		extLargeMapControl = new ExtLargeMapControl();
   		
		if (GBrowserIsCompatible()) {
      
			// create the map
			map.setCenter(new GLatLng(42.0625,-105.677068000000006), 3);
			map.addControl(new GMapTypeControl());
			map.addControl(extLargeMapControl);


			// read the data from the XML feed
			GDownloadUrl("/roster/gmapsfeed2/", function(data) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
											parseFloat(markers[i].getAttribute("lng")));
					var name = markers[i].getAttribute("name");
					var date = markers[i].getAttribute("date");
					var time = markers[i].getAttribute("time");
					var address = markers[i].getAttribute("address");
					var city = markers[i].getAttribute("city");
					var state = markers[i].getAttribute("state");
					var zipcode = markers[i].getAttribute("zipcode");
					var contactphone = markers[i].getAttribute("contactphone");
					var contacturl = markers[i].getAttribute("contacturl");
					var contacteml = markers[i].getAttribute("contacteml");
					var marker = createMarker(point, name, date, time, address, city, state, zipcode, contactphone, contacturl, contacteml);
					map.addOverlay(marker);
					}

				// create the marker
				function createMarker(point, name, date, time, address, city, state, zipcode, contactphone, contacturl, contacteml) {

					var marker = new GMarker(point);
			
					var html = "<div class=\"eventinfo\"><p><span class=\"name\">" + name + "</span><br/>" + address + "<br/>" + city + ", " + state + " " + zipcode + "</p><p>Date: " + date + "<br/>Time: " + time +  "</p><hr><p>" + contactphone + "<br/><a href=\"mailto:" + contacteml + "\">" + contacteml + "</a><br/><a href=\"" + contacturl + "\">" + contacturl + "</a></p><p><a href=\"http://maps.google.com/maps?saddr=&daddr=" + address + ", " + city + ", " + state + ", " + zipcode + "\" target=\"_blank\">Get Directions</a> (opens new window)</div>";
					GEvent.addListener(marker, 'click', function() {
						marker.openInfoWindowHtml(html);
						});
					return marker;
					}
				});
			}
    
		else {
      		alert("Sorry, the Google Maps API is not compatible with this browser");
    		}
    	}
