//<![CDATA[

    var locations = {};
    var map
    var zoom 
    function load() {
      GDownloadUrl("markers.xml", function(data) {
        var xml = GXml.parse(data);
        var settings = xml.documentElement.getElementsByTagName("settings");
        var centlat = settings[0].getAttribute("centlat")
        var centlng = settings[0].getAttribute("centlng")
        zoom = settings[0].getAttribute("zoom")
        var strURL = window.location.href
        if (strURL.indexOf('.html?LL=') > 0) {
        	var wrk = strURL.split('.html?LL=')
        	var wrk = wrk[1]
        	var wrk2 = wrk.split("_")
        	centlat = wrk2[0]
        	centlng = wrk2[1]
        	zoom = wrk2[2]
        }
        
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(centlat, centlng), parseFloat (zoom));
        var mapControl = new GLargeMapControl(); 
				var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10)); 
				var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10)); 
				map.addControl(mapControl, topRight); 	
        map.savePosition();
        
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var prop = markers[i].getAttribute("prop");
          var id = markers[i].getAttribute("id");
          var sleeps = markers[i].getAttribute("sleeps");
          var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                  parseFloat(markers[i].getAttribute("lng")));
          var store = {id: id, latlng: latlng, prop: prop, sleeps: sleeps};
          var latlngHash = (latlng.lat().toFixed(6) + "" + latlng.lng().toFixed(6));
          latlngHash = latlngHash.replace(".","").replace(".", "").replace("-","");
          if (locations[latlngHash] == null) {
            locations[latlngHash] = []
          }
          locations[latlngHash].push(store);
        }
        for (var latlngHash in locations) {
          var stores = locations[latlngHash];
          if (stores.length > 1) {
            map.addOverlay(createClusteredMarker(stores));
          } else {
            map.addOverlay(createMarker(stores));
          }
         }
      });
    }
function propZoom(lat,lng){
	map.setCenter(new GLatLng(lat, lng),14);
}
function resetMap() {
	map.closeInfoWindow();
	map.returnToSavedPosition()
}
    function createMarker(stores) {
      var store = stores[0];
      var newIcon = MapIconMaker.createMarkerIcon({width: 12, height: 12, primaryColor: "#ff0000"});
      var marker = new GMarker(store.latlng, {icon: newIcon,title: store.prop});
      var html = '<table><tr><td><a href="property' +store.id + '.html"><img class="imgLeft" width="100" height="67" src="images/Thumbnails/prop' + store.id + '.jpg" /></a></td><td><div class="Mapmenu"><a href="property' +store.id + '.html">' + store.prop + '</a></div><div class="Mapmenu">Sleeps ' + store.sleeps + '</div><div class="Mapmenu"><a href="#" onclick="propZoom(' + store.latlng.lat() + ',' + store.latlng.lng() + ')">Zoom in to Property</a></div></td></tr></table>';
      GEvent.addListener(marker, 'mouseover', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

    function createClusteredMarker(stores) {
      var newIcon = MapIconMaker.createMarkerIcon({width: 16, height: 16, primaryColor: "#00ff00"});
      
      var html = "<table>";
      var title = "";
      for (var i = 0; i < stores.length; i++) {
        html += '<tr><td><a href="property' +stores[i].id + '.html"><img class="imgLeft" width="100" height="67" src="images/Thumbnails/prop' + stores[i].id + '.jpg" /></a></td><td><div class="Mapmenu"><a href="property' +stores[i].id + '.html">' + stores[i].prop + '</a></div><div class="Mapmenu">Sleeps ' + stores[i].sleeps + '</div><div class="Mapmenu"><a href="#" onclick="propZoom(' + stores[i].latlng.lat() + ',' + stores[i].latlng.lng() + ')">Zoom in to Property</a></div></td></tr>';
        title += stores[i].prop + '/'
      }
      html += "</table>"
      var marker = new GMarker(stores[0].latlng, {icon: newIcon,title: title});
      GEvent.addListener(marker, 'mouseover', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
    //]]>
