var summaryMap;
var summaryMapBounds;
var mappedCount = 0;

function ShowSmallMapOld(divID, address, url) {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById(divID), mapOptions);
    var geocoder = new google.maps.Geocoder();
    var count = divID.replace('bb', '');
    geocoder.geocode({ 'address': address },
            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                        map.setCenter(results[0].geometry.location);
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location,
                            icon: basePath + '/markers/marker' + count + '.png'
                        });
                        var summaryMarker = new google.maps.Marker({
                            map: summaryMap,
                            position: results[0].geometry.location,
                            icon: basePath + '/markers/marker' + count + '.png'
                        });

                        summaryMapBounds.extend(results[0].geometry.location);
                        summaryMap.fitBounds(summaryMapBounds);

                        mappedCount++;

                        //if (mappedCount == maxResult) {
                        //    summaryMap.setZoom(summaryMap.getZoom() - 1);
                        // }
                    }
                }
            }
        );
}

function ShowSmallMap(divID, address, url) {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById(divID), mapOptions);
    var xmlhttp = new XMLHttpRequest();
    var count = divID.replace('bb', '');
    var url = '/_layouts/geocode.aspx?address=' + escape(address);
    xmlhttp.open('GET', url, true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.responseText.indexOf('200') == 0) {
                var lat = xmlhttp.responseText.split(',')[2];
                var lng = xmlhttp.responseText.split(',')[3];
                var ll = new google.maps.LatLng(lat, lng);
                map.setCenter(ll);
                var marker = new google.maps.Marker({
                    map: map,
                    position: ll,
                    icon: basePath + '/markers/marker' + count + '.png'
                });
                var summaryMarker = new google.maps.Marker({
                    map: summaryMap,
                    position: ll,
                    icon: basePath + '/markers/marker' + count + '.png'
                });

summaryMapBounds.extend(ll);
		if (mappedCount > 0)
{
summaryMap.fitBounds(summaryMapBounds);
}
else
{
summaryMap.setCenter(ll);
}

                mappedCount++;
            }
        }
    };
    xmlhttp.send(null);
}

        function ShowSummaryMap(divID, centerAddress) {
            summaryMapBounds = new google.maps.LatLngBounds(); 
            var mapOptions = {
                zoom: 13,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            summaryMap = new google.maps.Map(document.getElementById(divID), mapOptions);
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({ 'address': centerAddress },
            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                        //summaryMap.setCenter(results[0].geometry.location);
                    }
                }
            }
        );
        }

        function AddPointToSummaryMap(address) {
            
        }

function ShowLargeMap(divID, address) {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById(divID), mapOptions);
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': address },
            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                        map.setCenter(results[0].geometry.location);
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location
                        });
                    }
                }
            }
        );
}

function ShowRoute(tbID, address) {
    window.open('http://maps.google.com?saddr=' + document.getElementById(tbID).value + '&daddr=' + address);
}
