
    var map = null;
    var gmarkers = [];
    
    var geocoder = new GClientGeocoder();
    var bounds = new GLatLngBounds();
    
    // Create a base icon for all of our markers that specifies the
    // shadow, icon dimensions, etc.
    var baseIcon = new GIcon();
    baseIcon.iconSize = new GSize(22, 26);
    baseIcon.iconAnchor = new GPoint(11, 22);
    baseIcon.infoWindowAnchor = new GPoint(11, 0);

    function load() {
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            map.setCenter(new GLatLng(32.63459, -97.148269), 11);
        }
    }

function pausecomp(millis) 
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); } 
    while(curDate-date < millis);
} 

    function addMarker(lat, lon) {
        var point = new GLatLng(lat, lon);  
	map.addOverlay(new GMarker(point));
    }
  
    // Creates a marker whose info window displays the letter corresponding
    // to the given index.
    function createMarker(point, index, cText) {  
        // Create a lettered icon for this point using our icon class  
        var letter = index;
        var icon = new GIcon(baseIcon);
        if ((document.URL.toLowerCase().indexOf("viewproad") > -1) || (document.URL.toLowerCase().indexOf("proadresult.aspx") > -1) || (document.URL.toLowerCase().indexOf("/proad-") > -1))
            icon.image = "../Images/map" + letter + ".gif";
        else
            icon.image = "./Images/map" + letter + ".gif";

        var marker = new GMarker(point, icon);
        gmarkers[index] = marker;
//        marker.bindInfoWindowHtml(cText);
        GEvent.addListener(marker, "click", function() 
              {
               marker.openInfoWindowHtml(cText,{maxWidth: 300});
              });
              
        return marker;
    }
    
    function panToMarker(index, nZoom, lOpenInfo) {  
    
        var oPoint = gmarkers[index].getPoint();
        var lat = parseFloat(oPoint.lat());
        var lon = parseFloat(oPoint.lng());
        for ( var i=1, len=gmarkers.length; i<len; ++i )
        {
            if (gmarkers[i]!=null && gmarkers[i].isHidden())
                gmarkers[i].show();
                
            if (i!=index && gmarkers[i]!=null)
            {
                var oPointCheck = gmarkers[i].getPoint();
                var latCheck = parseFloat(oPointCheck.lat());
                var lonCheck = parseFloat(oPointCheck.lng());
                if (lat==latCheck && lon==lonCheck)
                    gmarkers[i].hide();
            }
        }

        if (nZoom)
            map.setZoom(nZoom);
        map.panTo(oPoint);

        if (lOpenInfo)
            {
            window.setTimeout(function(){GEvent.trigger(gmarkers[index], "click");},1000);
            }

        return;
    }
    
    /*-----------------------------------------------------------+
    | addLoadEvent: Add event handler to body when window loads |
    +-----------------------------------------------------------*/
    function addLoadEvent(func) {
        var oldonload = window.onload;
			
	if (typeof window.onload != "function") {
            window.onload = func;
        } else {
            window.onload = function () {
                oldonload();
                func();
            }
        }
    }
		
    /*------------------------------------+
    | Functions to run when window loads |
    +------------------------------------*/
    addLoadEvent(function () {
        initChecklist();
    });
		
    /*----------------------------------------------------------+
    | initChecklist: Add :hover functionality on labels for IE |
    +----------------------------------------------------------*/
    function initChecklist() {
	if (document.all && document.getElementById) {
            // Get all unordered lists
            var lists = document.getElementsByTagName("ul");
			
            for (i = 0; i < lists.length; i++) {
                var theList = lists[i];
				
		// Only work with those having the class "checklist"
		if (theList.className.indexOf("checklist") > -1) {
                    var labels = theList.getElementsByTagName("label");
						
                    // Assign event handlers to labels within
                    for (var j = 0; j < labels.length; j++) {
                        var theLabel = labels[j];
			theLabel.onmouseover = function() { this.className += " hover"; };
			theLabel.onmouseout = function() { this.className = this.className.replace(" hover", ""); };
                    }
		}
            }
	}
    }
    
    
function AddMap()
                  {
                    if (GBrowserIsCompatible())
                    {
                      map = new GMap2(document.getElementById("map"));
     				  map.addControl(new GSmallMapControl());
                      map.setCenter(new GLatLng(0, 0), 13)
            		  //map.addControl(new GMapTypeControl());
            		//AddAddress(address,1);  
                    }
                   }
function zoomfit()
{
//var bounds = new GLatLngBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var maxLon = northEast.lng();
var maxLat = northEast.lat();
var minLon = southWest.lng();
var minLat = southWest.lat();
var center = new GPoint( (maxLon+minLon)/2, (maxLat+minLat)/2 ); 
var delta = new GSize( maxLon-minLon, maxLat-minLat); 
//var minZoom = map.spec.getLowestZoomLevel(center, delta, map.viewSize); 
//map.centerAndZoom(center, minZoom);
var minZoom = map.getBoundsZoomLevel(bounds);
map.setZoom(Math.min(minZoom, 13));
map.setCenter(bounds.getCenter());
}

function AddAddress(address,index,cText)
		{
                    //var geocoder = new GClientGeocoder();
                    //window.setTimeout(function(){geocoder.getLocations(address,GetMapResponse);},1000);
                    //pausecomp(80)
                    geocoder.getLocations(address,GetMapResponse);
                    //geocoder = null;
                    function GetMapResponse(response)
                    {
                        if (response.Status.code == 200)
                        {
                        place = response.Placemark[0];
                        // if not in the DFW metroplex area, then skip it
                        if (place.Point.coordinates[0] < -98.0 || place.Point.coordinates[0] > -96.0 || place.Point.coordinates[1] < 32.0 || place.Point.coordinates[1] > 33.5)
                            return;
                        var opoint = new GLatLng(place.Point.coordinates[1],
                              place.Point.coordinates[0]);
                        //map.setCenter(opoint, 13);
                        map.addOverlay(createMarker(opoint, index, cText));
                        bounds.extend(opoint);
                        //taking zoomfit out of here and moving it to after creating all points causes script error for some reason
                        zoomfit();
                        //show image icon
                        document.getElementById("imgMap"+index).style.visibility="visible";
                        document.getElementById("imgMap"+index).width=16;

                        //Show Map
                        if (document.getElementById("map").style.visibility == "hidden")
                            ShowMap();
                            
                        var oPoint = gmarkers[index].getPoint();
                        }
                        else
                        {
                        // hide image icon in the listings results
                        document.getElementById("imgMap"+index).style.visibility="hidden";
                        document.getElementById("imgMap"+index).width="0px";
                        }
                    }
        }

function HideMap()
{
    elem = document.getElementById("map");
    if (elem)
        elem.style.height = "1px";
        elem.style.display = "none";
}

function ShowMap()
{
    // show map
    elem = document.getElementById("map");
    if (elem && gmarkers.length>1)
        elem.style.visibility = "visible";
    // show directions url on proadpage
    if ((document.URL.toLowerCase().indexOf("viewproad.aspx") > -1) || (document.URL.toLowerCase().indexOf("proadresult.aspx") > -1) || (document.URL.toLowerCase().indexOf("/proad-") > -1))
    {
        elem = document.getElementById("ctl00_ContentPlaceHolder1_urlDirections");
        if (elem && gmarkers.length>1)
            elem.style.visibility = "visible";
    }
}