var ico = new GIcon();
ico.image = "icone-marcador-amarelo.png";
ico.shadow = "icone-sombra.png";
ico.iconSize = new GSize(12, 20);
ico.shadowSize = new GSize(22, 20);
ico.iconAnchor = new GPoint(6, 20);
ico.infoWindowAnchor = new GPoint(5, 1);

$('document').ready(function(){

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("mapa"));
		map.setCenter(new GLatLng(-14.782928, -52.382812), 4);
		map.setMapType(G_HYBRID_MAP);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		
		$.get('busca.php','',processaJSON)
	}

})

function processaJSON(json) {
	bounds = new GLatLngBounds();
	pontos = eval("(" + json + ")")
	
	for (i=0; i<pontos.length; i++)
		criaPonto(pontos[i])

	if (i>0) {
		map.setZoom(map.getBoundsZoomLevel(bounds));
		map.setCenter(bounds.getCenter());
	}
}

function criaPonto(ponto) {

	var MarkerOptions = new Object();
	MarkerOptions.title = ponto.titulo;
    MarkerOptions.icon = ico;
	ponto.coordenadas = new GLatLng(ponto.latitude,ponto.longitude)

	var marker = new GMarker(ponto.coordenadas, MarkerOptions);
	bounds.extend(ponto.coordenadas);

	GEvent.addListener(marker, "click", function(e) {abreBalao(marker, ponto)});
	map.addOverlay(marker);
}

function abreBalao(marker, ponto)
{
    map.panTo(marker.getLatLng());
    marker.openInfoWindowHtml(ponto.htmlBalao);
}