
		                        
var map = null;
var geocoder = null;
var markers = [];

function createMarker(point,html,icon) {
	var marker = new GMarker(point, {icon:icon});
	GEvent.addListener(marker, "click", function() {
      			marker.openInfoWindowHtml(html);
      		});
      		return marker;
}




function home_initialize(xml_url) { 
	if (GBrowserIsCompatible()) {
	      
		geocoder = new GClientGeocoder();
		
		map = new GMap2(document.getElementById("map_canvas"));
		//map = new GMap(document.getElementById("map_canvas"));
	    
		//map.addControl(new GSmallMapControl());
	    //map.addControl(new GMapTypeControl());
	    
	    map.setUIToDefault();
	    var mc = new MarkerClusterer(map);
	    
	    getMarkers(xml_url);
	      //map.setCenter(new GLatLng(55.7557860,37.6176330), 4); // Moscow
	      // map.setCenter(new GLatLng(61.5240100,105.3187560), 4); // Russia
	      //map.setCenter(new GLatLng(59.6362497,56.7667885), 5); // Solikamsk
	      map.setCenter(new GLatLng(57.7807389,40.9366913), 5); // Kostroma
	    
	      //map.setMapType(G_PHYSICAL_MAP);
	
	    GEvent.addListener(map, "click", function(overlay, point) {
		      if (overlay){	// marker clicked
			      overlay.openInfoWindowHtml(overlay.infowindow);	// open InfoWindow
		      } else if (point) {	// background clicked
			      
		      }
	    });  
	    
	    GEvent.addListener(mc, "clusterclick", function (cluster) {
	    	  var markers = cluster.getMarkers();
	    	  var bounds  = new GLatLngBounds();
	    	  $.each(markers, function(i, marker){
	    	    bounds.extend(marker.marker.getLatLng()); 
	    	  });
	    	  map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
	    });
	      
	};
	
	
	
	function getMarkers(xml_url){
	    var urlstr=xml_url;
	    var request = GXmlHttp.create();
	    request.open('GET', urlstr , true);	// request XML from PHP with AJAX call
	    request.onreadystatechange = function () {
			if (request.readyState == 4) {
				var xmlDoc = request.responseXML;
				locations = xmlDoc.documentElement.getElementsByTagName("marker");
				var icon = new GIcon(G_DEFAULT_ICON);
		          icon.image = "http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png";
		          markers = [];
				
		         if (locations.length){
					for (var i = 0; i < locations.length; i++) { // cycle thru locations
						
						
						
						var latlng = new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng"));
			            var marker = new GMarker(latlng, {icon: icon});
			            markers.push(marker);
			            

						
					}
					var mcOptions = { gridSize: 20, maxZoom: 10, zoomOnClick: false};
					var markerCluster = new MarkerClusterer(map, markers, mcOptions);

				}
			}
		}
		request.send(null);
	}
	
	
};




function map_initialize(address) { 
	if (GBrowserIsCompatible()) {
	      map = new GMap2(document.getElementById("map_canvas"));
	      
	      geocoder = new GClientGeocoder();
	      
	      find(address);
	      // map.setCenter(new GLatLng(48.8566667,2.3509871), 12); 
	      map.setMapType(G_PHYSICAL_MAP);
	
	      map.setUIToDefault();  
	       
	      
	};
};

function find(address) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          //alert("\"" + address + "\" not found");
        } else {
            map.setCenter(point, 6);
        }
      }
    );
}




