var map;
var geocoder;

function loadMap() 
{ 
	if (GBrowserIsCompatible()) 
	{ 
		map = new GMap2(document.getElementById("map")); 
		geocoder = new GClientGeocoder();
	
		//map.addControl(new GLargeMapControl());
		//map.setMapType(G_HYBRID_MAP);
		//map.setCenter(new GLatLng(37.4419, -122.1419), 10); 
		centerBy("Украина");    
	
		for (var i in dealers) 
		{            
			markCity(dealers[i]);  
			//alert('key is: ' + i + ', value is: ' + myArray[i]);
		}
	} 
}     
        

function centerBy(city)
{
	geocoder.getLatLng(city,
	    function(point) 
		{
	    	if (!point) 
			{
	        	alert("Место '" + city + "' не найдено");
	      	}
	 		else 
			{
		        map.setCenter(point, 5);
	        }
	   }); 
}


function markCity(city) 
{
	geocoder.getLatLng(city['address'],
	    function(point) 
		{
	    	if (!point) 
			{
	        	alert("Место '" + city['city'] + "' не найдено");
	      	}
	 		else 
			{
 	           //map.setCenter(point, 13);
		        var marker = new GMarker(point);   
	
	       	    GEvent.addListener(marker, "click", function() 
				{    
					var html = "<strong>" + city['title'] + "</strong><br><address>" + city['address'] + "</addresss><br><em>тел: " + city['phone']  +  "</em>"
				    map.openInfoWindowHtml(point, html);
					$('#dealer_id').attr('value', city['id']);
					$('#message_title').attr('value', "Отправка сообщения для '" + city['title'] + "'");
			    });
	
		        map.addOverlay(marker);  
	        }
	   }); 
}

