// JavaScript Document
//<![CDATA[

    var iconBlue = new GIcon(); 
    iconBlue.image = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_blue.png';
    iconBlue.shadow = 'http://www.terrynagel.com/phpcms/images/icons/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);

    var iconRed = new GIcon(); 
    iconRed.image = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_red.png';
    iconRed.shadow = 'http://www.terrynagel.com/phpcms/images/icons/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);
	
	var iconYellow = new GIcon(); 
    iconYellow.image = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_yellow.png';
    iconYellow.shadow = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_shadow.png';
    iconYellow.iconSize = new GSize(12, 20);
    iconYellow.shadowSize = new GSize(22, 20);
    iconYellow.iconAnchor = new GPoint(6, 20);
    iconYellow.infoWindowAnchor = new GPoint(5, 1);
	
	var iconGreen = new GIcon(); 
    iconGreen.image = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_green.png';
    iconGreen.shadow = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_shadow.png';
    iconGreen.iconSize = new GSize(12, 20);
    iconGreen.shadowSize = new GSize(22, 20);
    iconGreen.iconAnchor = new GPoint(6, 20);
    iconGreen.infoWindowAnchor = new GPoint(5, 1);
	
	var iconGray = new GIcon(); 
    iconGray.image = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_gray.png';
    iconGray.shadow = 'http://www.terrynagel.com/phpcms/images/icons/mm_20_shadow.png';
    iconGray.iconSize = new GSize(12, 20);
    iconGray.shadowSize = new GSize(22, 20);
    iconGray.iconAnchor = new GPoint(6, 20);
    iconGray.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons[2005] = iconBlue;    
	customIcons[2006] = iconRed;
	customIcons[2007] = iconYellow;
	customIcons[2008] = iconGreen;
	customIcons[2009] = iconGray;
	
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.5810, -122.365), 14);
        map.addControl(new GSmallMapControl());
          GDownloadUrl("phpcms/includes/phpcms_neighborhood_map.php", function(data) {
          var xml = GXml.parse(data);
		  var markers = xml.documentElement.getElementsByTagName("neighbor");
          for (var i = 0; i < markers.length; i++) {
            var name = markers[i].getAttribute("name");
			var address = markers[i].getAttribute("address");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
          var marker = createMarker(point,name,address);
		  map.addOverlay(marker);

          }
        });
      }
	}
    function createMarker(point,name,address) {
	var marker = new GMarker(point,customIcons[2008]);
	var html = "<b>" + address + "</b><br />"+name;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });

      return marker;
    }
    //]]>
