var map = null;

function loadMap()
{
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(45.50141, 9.192646), 15);
}		


function centerMap(comune)
{
	var geocoder = new GClientGeocoder();

	//map.setCenter(new GLatLng(45.472267, 9.19669, true), 10);
	
	geocoder.getLatLng(
		comune,
		function(point) {
			if (point)
			{
				map.setCenter(point, 11);
			}
		}
	)
}		

	
function addPointer(address, nomepalestra, index)
{
	try
	{
		var geocoder = new GClientGeocoder();	
		
		//map.addOverlay(getMarker(new GLatLng(44.472267, 9.19669, true), nomepalestra, index));
			
		geocoder.getLatLng(
			address,
			function(point) {			
				if (point)
				{
					map.addOverlay(getMarker(point, nomepalestra, index));							
				}	
			}
		)	
	}
	catch(error)
	{}
}	


//Private-----------------------------------------------------------------------------------------------------------------------------------------------------------
function getMarker(point, nomepalestra, index) 
{
	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var icon = new GIcon(getIcon());
	//icon.image = "logomappa.jpg";
	icon.image = "http://www.google.com/mapfiles/marker.png";
	var marker = new GMarker(point, icon);

	GEvent.addListener(
		marker, 
		"click", 
		function() {
			marker.openInfoWindowHtml(nomepalestra);
		}
	);
	return marker;
}	


function getIcon()
{
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
	
	return baseIcon;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------