var marker;

function unLoad() {
	GUnload();
}

//Ajusta el Zoom y el Centro del Mapa en función de las posiciones de los marcadores
function ajustarZoom(map, bounds) {
	if (!bounds.isEmpty()) {
		var swLL = bounds.getSouthWest();
		var neLL = bounds.getNorthEast();
		var centro = bounds.getCenter();
		
		//	Margen en el interior del mapa
		var marginRatio = 0.1;
		   
		var minLat = Math.min(2*centro.lat() - neLL.lat(), swLL.lat());                
		var maxLat = Math.max(2*centro.lat() - swLL.lat(),  neLL.lat());        
		var minLng = Math.min(2*centro.lng() - neLL.lng(), swLL.lng());               
		var maxLng = Math.max(2*centro.lng() - swLL.lng(), neLL.lng());
		  
		var minLatLng = new GLatLng(minLat-marginRatio, minLng-marginRatio);
		var maxLatLng = new GLatLng(maxLat+marginRatio, maxLng+marginRatio);
		
		bounds.extend(maxLatLng);
		bounds.extend(minLatLng);      
	
		map.setCenter(centro);
		map.setZoom(map.getBoundsZoomLevel(bounds));
	}
}

function cargarMapa(capa, lat, lng, zoom) {
	if (GBrowserIsCompatible()) {
		var centro = new GLatLng(lat, lng);
	    var map = new GMap2(document.getElementById(capa));
	    map.setCenter(centro, zoom);
	    /*map.addControl(new GMapTypeControl());*/
		map.addControl(new GLargeMapControl());
		map.enableScrollWheelZoom();	
		return map;
	}
}

function cargarMapaFicha(capa, lat, lng, zoom) {
	if (GBrowserIsCompatible()) {
		var centro = new GLatLng(lat, lng);
	    var map = new GMap2(document.getElementById(capa));
	    map.setCenter(centro, zoom);
	    //map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();	
		return map;
	}
}

function crearMarcador(lat, lng, enlace, markerData) {
	var marker = new GMarker(new GLatLng(lat, lng), markerData);
	if (enlace != null && enlace != "") {
		GEvent.addListener(marker, "click", function() {
			document.location.href = enlace;
		});
	}
	return marker;	
}

function crearMarcadorRed(lat, lng, enlace) {
	icon = new GIcon(G_DEFAULT_ICON);
	icon.image = "pages/img/es/aplicaciones/marcadorRedes.gif";
	icon.iconSize = new GSize(29, 45); 
	icon.iconAnchor = new GPoint(15,45);	
	icon.shadow = "";
	var markerData = {};
	markerData.icon = icon;
	return crearMarcador(lat, lng, enlace, markerData);	
}

function crearMarcadorGrupo(lat, lng, enlace) {
	icon = new GIcon(G_DEFAULT_ICON);
	icon.image = "pages/img/es/aplicaciones/marcadorGrupos.gif";
	icon.iconSize = new GSize(26, 45);
	icon.iconAnchor = new GPoint(13,45);
	icon.shadow = "";
	var markerData = {};
	markerData.icon = icon;
	return crearMarcador(lat, lng, enlace, markerData);	
}

function crearMarcadorProyecto(lat, lng, enlace) {
	icon = new GIcon(G_DEFAULT_ICON);
	icon.image = 'pages/img/es/aplicaciones/marcadorProyectos.gif';
	icon.iconSize = new GSize(28, 50);
	icon.iconAnchor = new GPoint(14,50);
	icon.shadow = "";
	var markerData = {};
	markerData.icon = icon;
	return crearMarcador(lat, lng, enlace, markerData);	
}
