// JavaScript Document



    //<![CDATA[

	//This sets up the blue icon
	var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);


	//This sets up the red icon
    var iconRed = new GIcon(); 
    iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRed.iconSize = new GSize(12, 20);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

	//This assigns the custom icons to a particular type
    var customIcons = [];
    customIcons["restaurant"] = iconBlue;
    customIcons["bar"] = iconRed;

    function load() {
      if (GBrowserIsCompatible()) {														//If the browser is compatible...javascript...
        var map = new GMap2(document.getElementById("gmap"));							//Set up a new map
        map.addControl(new GSmallMapControl());											//Set up a control for zooming on the google map
        map.addControl(new GMapTypeControl());											//Set up a control to change the type of map
        map.setCenter(new GLatLng(35.728677,-79.760742), 7);									//Set the map up for a center around Holly Springs, NC and zoom level 13

        GDownloadUrl("phpsqlajax_genxml.php", function(data) {							
          var xml = GXml.parse(data);
          var railfan = xml.documentElement.getElementsByTagName("railfandata");
          for (var i = 0; i < 5; i++) {
            var name = railfan[i].getAttribute("name");
            var address = railfan[i].getAttribute("address");
            var type = railfan[i].getAttribute("type");
			var comments = railfan[i].getAttribute("comments");
            var point = new GLatLng(parseFloat(railfan[i].getAttribute("lat")),
                                    parseFloat(railfan[i].getAttribute("lng")));
			var marker = createMarker(point, name, address, type, comments);
            map.addOverlay(marker);
			var sidePanelInit = document.getElementById('gmaptext');
			sidePanelInit.innerHTML = "Search above.";
          }
        });
      }
    }


   function searchLocations() {
     var address = document.getElementById('addressInput').value;
     geocoder.getLatLng(address, function(latlng) {
       if (!latlng) {
         alert(address + ' not found');
       } else {
         searchLocationsNear(latlng);
       }
     });
   }


    function createMarker(point, name, address, type, comments) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + comments;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
    //]]>
