﻿       
        var points = '';
        var gmarkers = '';
        var to_htmls = '';
        var from_htmls = '';

        function loadMap() {
            if (GBrowserIsCompatible()) {

                for (i = 0; i < BCHData.CityViews.length; i++) {
                    
                    if (BCHData.CityViews[i].CommunityID == CommunityID) {
                        var dataSet = BCHData.CityViews[i];                        
                    }
                }
	            
	            var marker;
	            var mapScale = 9;
	            var CommunityLatitude = dataSet.Latitude;
	            var CommunityLongitude = dataSet.Longitude;
	            var CommunityLatLon = dataSet.Latitude + ", " + dataSet.Longitude;
	            
	            var map = new GMap2(document.getElementById("map"));
	            map.addControl(new GLargeMapControl());
	            map.addControl(new GMapTypeControl());
	            map.setCenter(new GLatLng(CommunityLatitude, CommunityLongitude), mapScale);
	            
                var baseIcon = new GIcon(G_DEFAULT_ICON);
                baseIcon.shadow = "http://www.billclarkhomes.com/images/icons/googlemap/" + "MapMarkerShadow.gif";
                baseIcon.iconSize = new GSize(30, 30);
                baseIcon.shadowSize = new GSize(1, 1); 
                baseIcon.iconAnchor = new GPoint(9, 34); 
                baseIcon.infoWindowAnchor = new GPoint(9, 2);

                html = "<div class='CommunityDirectionsBubble'>"
                html += "<h3>" + dataSet.CommunityName + "</h3>";
                if (dataSet.ImgURL != null) {
                    html += GetImgTag(dataSet.ImgURL, dataSet.PhotoTitle, dataSet.PhotoHeight, dataSet.PhotoWidth);
                }
                html += "<p>" + getFirstFeature(dataSet.Features) + "</p>";
                html += "<p>" + parsePriceRange(dataSet.LowPriceRange) + "</p>";
                html += "<h5><a href='javascript:tohere(0)'>Get directions to here</a></h5>";
                html += "<a href='javascript:tonearby(0)'>Search nearby</a>";
                html += "</div>"                
                
                to_htmls = '<p>Get Directions to ' + dataSet.CommunityName + '</p>' +
                           '<p>Start address:</p>' +
                           '<form action="http://maps.google.com/maps" method="get" target="_blank">' +
	                       '<p><input type="text" size="60" maxlength="60" name="saddr" id="saddr" value="" /></p>' +
	                       '<input class="Submit" value="Get Directions" type="SUBMIT">' +
	                       '<input type="hidden" name="daddr" value="' + CommunityLatLon + '"/>';

                to_htmlsNearby = '<form action="http://maps.google.com/maps" method="get" target="_blank"><p><b>Search nearby:</b> For example type: Pizza, Hotels, or Restaurants :<br><input type="text" SIZE=35 MAXLENGTH=80 name="q" id="q" value="" /></p>' +
                                 '<INPUT  class="Submit" value="Search" TYPE="SUBMIT">' +
                                 '<input type="hidden" name="near" value="' + CommunityLatLon + '"/>';
                
                marker = createMarker(new GLatLng(dataSet.Latitude, dataSet.Longitude), html, baseIcon, dataSet.CommunityID, "1");
                map.addOverlay(marker);
                gmarkers = marker;
                gmarkers.openInfoWindowHtml(html)     	        
		    }
        }

        function createMarker(point, html, baseIcon, commID, currentPosition) {
            var numberedIcon = new GIcon(baseIcon);
            numberedIcon.image = "http://www.billclarkhomes.com/images/icons/googlemap/MapMarker" + currentPosition + ".gif";
            markerOptions = { icon: numberedIcon };
            var marker = new GMarker(point, markerOptions);
            marker.html = html;
            
            GEvent.addListener(marker, "mouseover", function() {
                marker.openInfoWindowHtml(marker.html);
                marker.showMapBlowup
            });
            
            return marker;
        }

        function tohere(i) {
            gmarkers.openInfoWindowHtml(to_htmls);
            //alert("dave");
        }

        function tonearby(i) {
            gmarkers.openInfoWindowHtml(to_htmlsNearby);
        }

