
var map, cluster;

var iconT = new GIcon();
iconT.image = "images/icoT.png";
iconT.shadow = "images/icoS2.png";
iconT.iconSize = new GSize(28, 30);
iconT.shadowSize = new GSize(28, 30);
iconT.iconAnchor = new GPoint(6, 20);
iconT.infoWindowAnchor = new GPoint(15,1);	

var iconR = new GIcon();
iconR.image = "images/icoR.png";
iconR.shadow = "images/icoS2.png";
iconR.iconSize = new GSize(28, 30);
iconR.shadowSize = new GSize(28, 30);
iconR.iconAnchor = new GPoint(6, 20);
iconR.infoWindowAnchor = new GPoint(15,1);	

var iconA = new GIcon();
iconA.image = "images/icoA.png";
iconA.shadow = "images/icoS.png";
iconA.iconSize = new GSize(28, 30);
iconA.shadowSize = new GSize(28,30);
iconA.iconAnchor = new GPoint(6, 20);
iconA.infoWindowAnchor = new GPoint(15,1);	

function myOnLoad() {
	if (GBrowserIsCompatible()) {
		map=new GMap2(document.getElementById('map'));
		var icon = new GIcon();
		var marker, markersArray=[];
		for (var i=0; i<json.length; i++) {
			if(json[i].ico=='A') icon=iconA;
			if(json[i].ico=='R') icon=iconR;
			if(json[i].ico=='T') icon=iconT;
			marker=newMarker(new GLatLng(json[i].lat, json[i].lng), json[i].id, json[i].titulo, json[i].textos,icon);
			markersArray.push(marker);
		}
		
		cluster=new ClusterMarker(map, { markers:markersArray } );
		cluster.fitMapToMarkers();
		
		map.savePosition();	//	enables the large map control centre button to return the map to initial view
		map.setCenter(new GLatLng(39.42686525870761,-4.4625091552734375), zoom, G_NORMAL_MAP);
    map.setUIToDefault();

	}
}

function newMarker(markerLocation, markerId, titulo, textoHtml,icono) {
	var marker=new GMarker(markerLocation, {icon:icono, title:titulo});
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(textoHtml);
	});
	return marker;
}

function toggleClustering() {
	cluster.clusteringEnabled=!cluster.clusteringEnabled;
	cluster.refresh(true);	//	true required to force a full update of the markers - otherwise the update would occur next time that the map is zoomed or the active markers change
}
