﻿
    var baseIcon = new GIcon();
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    
    var map = null;
    var geocoder = null;  

    function createMarker(point,name,html) {	    
	    var icon = new GIcon(baseIcon);
        icon.image = "http://www.google.com/mapfiles/marker"+name+".png";
         
        var marker = new GMarker(point, icon);
        
        /* //no click event
        GEvent.addListener(marker, "click", function() {            
            marker.openInfoWindowHtml(html);
        });   */     
        return marker;
    }
        
    function initialize() {
    //debugger;        
      if (GBrowserIsCompatible()) {      
        geocoder = new GClientGeocoder();        
        //xml will contain ids of maps
        var xmlDoc = GXml.parse(xml);
        var maps = xmlDoc.documentElement.getElementsByTagName("location");              
        for(var i = 0; i < maps.length; i++){                             
            showAddress(maps[i].getAttribute("address"), maps[i].getAttribute("name"), maps[i].getAttribute("address"), maps[i].getAttribute("mapId"));
        }      
      }
    }
    
    function showAddress(address, name, html, mapId) {        
        //address = Addr1, City, STATE
        var map = new GMap2(document.getElementById(mapId));
        if (geocoder) {
            geocoder.getLatLng(
              address,
              function(point) {
               if (!point) {
                //if no geocode for given address, what to do?
                alert(address + " not found");                
               } else {
                map.setCenter(point, 13);
                var marker = createMarker(point, name, html);
                map.addOverlay(marker);                
              }
            }
          );
      }
    }
