﻿var map = null;
var geocoder = null;

function PageLoad(address)
{
    initialize();
    showAddress(address);
}
function initialize() 
{
  if (GBrowserIsCompatible()) 
  {
    map = new GMap2(document.getElementById("map_canvas"));

    map.setCenter(new GLatLng(37.4419, -122.1419), 15);
    map.addControl(new GScaleControl());
    var boxStyleOpts = {opacity: .2, border: "2px solid yellow" };
    var otherOpts = { buttonStartingStyle: {width: '17px', height: '17px', display:'none'},overlayRemoveTime: 0 };

    map.addControl(new DragZoomControl(boxStyleOpts, otherOpts, {}),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(27,7)));
    map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,32)));

    geocoder = new GClientGeocoder();
  }
}
function showAddress(address, i)
{
    if (geocoder && address!='' && address.replace(",","").trim()!='') 
    {
        geocoder.getLatLng(address,
            function(point) 
            {
                if (!point) 
                {
                  alert(address + " not found");
                } 
                else 
                {
                    map.setCenter(point, 9);
                    if(i)
                    {
                        var baseIcon = new GIcon(G_DEFAULT_ICON);
                        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);
                    
                        //var letter = String.fromCharCode("A".charCodeAt(0) + i);
                        var letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i);
                        var letteredIcon = new GIcon(baseIcon);
                        
                        letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
                        // Set up our GMarkerOptions object
                        markerOptions = { icon:letteredIcon };
                        marker = new GMarker(point, markerOptions);
                    }
                    map.addOverlay(marker);
                    GEvent.addListener(marker,"click", function() {map.openInfoWindowHtml(point, address);});
                    marker.openInfoWindowHtml(address);
                }
            }
        );
    }
}
function Show(address, i)
{
    initialize();
    showAddress(address, i);
}
function ZoomIn()
{
    if(map!=null)
        map.zoomIn()
}
function ZoomOut()
{
    if(map!=null)
        map.zoomOut()
}