	/* Contantes de las posiciones de la información dentro del array de hoteles */
	var HOTEL_CODIGO    = 0;
	var HOTEL_NOMBRE    = 1;
	var HOTEL_CATEGORIA = 2;
	var HOTEL_PAIS      = 3;
	var HOTEL_CIUDAD    = 4;
	var HOTEL_DIRECCION = 5;
	var HOTEL_LATITUD   = 6;
	var HOTEL_LONGITUD  = 7;
	var HOTEL_MARCA     = 8;

	/* Valores para el mapa */
	var existenGeocodes       = false;   // False si no existe ningun hotel con geocodes en la busqueda
	var centroLatitud         = 39.57;   // Por defecto. Palma de Mallorca. Si aparece ha habido un error.
	var centroLongitud        = 2.65;    // Por defecto. Palma de Mallorca. Si aparece ha habido un error.
	var mapaProfundidad       = 14;      // Profundidad por defecto.
	var mapaAltura            = 0.54;    // Amplitud de altura permitido para la profundidad por defecto
	var mapaAnchura           = 0.30;    // Amplitud de altura permitido para la profundidad por defecto
	var mapaUmbral            = 0.01;    // Umbral minimo para la amplitud de la altura o anchura
	var mapaProfundidadMaxima = 14;      // Profundidad maxima permitida
	var mapaProfundidadMinima = 5;
	
	/* Devuelve el texto que se mostrara dentro de la ventana de información de cada marcador */
	function formatearContenido(indice) {
		var texto = new String();
		texto     = "<span class='v_333333_10n'>";
		texto    += "<b>"+contenedorHoteles[indice][HOTEL_NOMBRE]+"</b>";
		texto    += " "+contenedorHoteles[indice][HOTEL_CATEGORIA];
		texto    += "<br>"+contenedorHoteles[indice][HOTEL_DIRECCION];
		texto    += "<br>"+contenedorHoteles[indice][HOTEL_CIUDAD];
		texto    += "<br>"+contenedorHoteles[indice][HOTEL_PAIS];
		texto    += "</span>";
		return texto;
	}
	
	/* 
	Crea un marcador para un hotel.
	La imagen depende de la marca del hotel
	Se añaden los eventos relaciones con el marcador.
	*/
	function crearMarcador(map, geocode, indice, icono) {
		
		/* Icono */
    icono.image  =pathIconos+"sm_icono_"+contenedorHoteles[indice][HOTEL_MARCA]+".png";
		var marcador = new GMarker(geocode, icono);
		
		/* Eventos */
		GEvent.addListener(marcador, "mouseover", function() {
			marcador.openInfoWindowHtml(formatearContenido(indice));
		});
		GEvent.addListener(marcador, "mouseout", function() {
			map.closeInfoWindow();
		});
		
		return marcador;
	}
			
	/* Carga el mapa si el navegador es compatible */
		/* Carga el mapa si el navegador es compatible */
	var map;
	google.load("maps", "2.119a");
	function load(tipo) {
		if (GBrowserIsCompatible()) {
		
			/* Inicializacion del mapa */
			var map = new google.maps.Map2(document.getElementById("map"));
			map.setCenter(new google.maps.LatLng(39.57, 2.65), 15);			
			// Obtenemos el tipo de mapa que queremos mostrar
			if (tipo == "NORMAL") map.setMapType(G_NORMAL_MAP);
			if (tipo == "SATELITE") map.setMapType(G_SATELLITE_MAP);
			if (tipo == "HIBRIDO") map.setMapType(G_HYBRID_MAP);			
		 
		 /* Icono base para las imagenes de los marcadores */
		        var icono              = new google.maps.Icon();
		        icono.iconSize         = new google.maps.Size(24, 24);
		        icono.shadowSize       = new google.maps.Size(0, 0);
		        icono.iconAnchor       = new google.maps.Point(12, 12);
		        icono.infoWindowAnchor = new google.maps.Point(18, -10);			
			
			/* Carga de los marcadores e infos de los hoteles */
		for (var i=0; i<contenedorHoteles.length; i++) {
				if (contenedorHoteles[i][HOTEL_LATITUD]!="" && contenedorHoteles[i][HOTEL_LONGITUD]!="") {
					var geocode  = new GLatLng(contenedorHoteles[i][HOTEL_LATITUD],contenedorHoteles[i][HOTEL_LONGITUD]);
					map.addOverlay(crearMarcador(map, geocode, i, icono));
				}
			}
			
			/* Variables que controlan la mayor amplitud entre los hoteles */
			var mayorLatitud  = new Number();
			var mayorLongitud = new Number();
			var menorLatitud  = new Number();
			var menorLongitud = new Number();
			
			/* Busqueda de la mayor amplitud en alto y ancho en todos los hoteles */	
			for (var i=0; i<contenedorHoteles.length; i++) {
			
				/* Si el hotel hotel tiene geocode */
				if (contenedorHoteles[i][HOTEL_LATITUD]!="" && contenedorHoteles[i][HOTEL_LONGITUD]!="") {
					
					/* Si es el primer hotel con geocode */
					if (existenGeocodes==false) {
						existenGeocodes = true;
						mayorLatitud    = contenedorHoteles[i][HOTEL_LATITUD];
						menorLatitud    = contenedorHoteles[i][HOTEL_LATITUD];
						mayorLongitud   = contenedorHoteles[i][HOTEL_LONGITUD];
						menorLongitud   = contenedorHoteles[i][HOTEL_LONGITUD];
					} else {
						if (contenedorHoteles[i][HOTEL_LATITUD]>mayorLatitud)   {mayorLatitud=contenedorHoteles[i][HOTEL_LATITUD];}
						if (contenedorHoteles[i][HOTEL_LATITUD]<menorLatitud)   {menorLatitud=contenedorHoteles[i][HOTEL_LATITUD];}
						if (contenedorHoteles[i][HOTEL_LONGITUD]>mayorLongitud) {mayorLongitud=contenedorHoteles[i][HOTEL_LONGITUD];}
						if (contenedorHoteles[i][HOTEL_LONGITUD]<menorLongitud) {menorLongitud=contenedorHoteles[i][HOTEL_LONGITUD];}
					}
					
				}
			}
			//alert("("+mayorLatitud+","+menorLatitud+","+mayorLongitud+","+menorLongitud+")");
			
			/* Calculo del geocode central del mapa */
			centroLatitud  = (new Number(mayorLatitud) + new Number(menorLatitud)) / 2;
			centroLongitud = (new Number(mayorLongitud) + new Number(menorLongitud)) / 2; 
			
			/* Punto central del mapa. Si no hay geocodes se elimina el mapa */
			if (existenGeocodes) {
			
				var ok = false;
				while (!ok && mapaProfundidad>mapaProfundidadMinima) {
					map.setCenter(new google.maps.LatLng(centroLatitud, centroLongitud), mapaProfundidad);
					var tmpBounds = map.getBounds();
					var indice = 0;
					var algunoFuera = false;
					while (indice<contenedorHoteles.length && !algunoFuera) {
						if (contenedorHoteles[indice][HOTEL_LATITUD]!="" && contenedorHoteles[indice][HOTEL_LONGITUD]!="") {
							var geocode = new GLatLng(contenedorHoteles[indice][HOTEL_LATITUD],contenedorHoteles[indice][HOTEL_LONGITUD]);;
							if (!tmpBounds.contains(geocode)) {
								algunoFuera = true;
							}
						}
						indice++;
					}
					if (algunoFuera) {
						mapaProfundidad--;
					} else {
						ok = true;
					}
				}
				
				map.setCenter(new google.maps.LatLng(centroLatitud, centroLongitud), mapaProfundidad);
			} else {
				GUnload();
				document.getElementById("cont_map").style.visibility = "hidden";
				document.getElementById("map").style.visibility = "hidden";
				document.getElementById("map").style.height     = 0;
				document.getElementById("map").style.width      = 0;
				document.getElementById("estadoVisualizacionMapa").style.visibility = "hidden";
				document.getElementById("estadoVisualizacionMapa").style.height     = 0;
				document.getElementById("estadoVisualizacionMapa").style.width      = 0;
			}
			
			/* Añadimos los controles al mapa */
			map.addControl(new GCentrarHotelControl(centrar_mapa,new GLatLng(centroLatitud, centroLongitud), mapaProfundidad));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());			
		}
	}
	
	/* VISUALIZACION DEL MAPA */
	
	/* Estado de visualizacion del mapa */
	var visualizacionMapa = false;
	
	/* Controla el estado de visualizacion del mapa */
	function estadoVisualizacionMapa() {
		if (visualizacionMapa) {
			mostrarMapa();
		} else {
			ocultarMapa();
		}
		visualizacionMapa = !visualizacionMapa;
	}
	
	/* Oculta el mapa en el navegador */
	function ocultarMapa() {
		document.getElementById("cont_map").style.visibility = "hidden";		
		document.getElementById("cont_map").style.height     = 0;
		document.getElementById("cont_map").style.width      = 0;
		document.getElementById("cont_map").style.padding      = 0;
		document.getElementById("map").style.visibility = "hidden";
		document.getElementById("map").style.height     = 0;
		document.getElementById("map").style.width      = 0;
		// mostrar_mapa declarado fuera
		document.getElementById("estadoVisualizacionMapa").innerHTML = mostrar_mapa;
	}
	
	/* Muestra el mapa (oculto) en el navegador */
	function mostrarMapa() {
		document.getElementById("cont_map").style.visibility = "visible";				
		document.getElementById("cont_map").style.height     = "290px";
		document.getElementById("cont_map").style.width      = "550px";
		document.getElementById("cont_map").style.padding      = "4px";
		document.getElementById("map").style.visibility = "visible";
		document.getElementById("map").style.height     = "290px";
		document.getElementById("map").style.width      = "550px";
		// ocultar_mapa declarado fuera
		document.getElementById("estadoVisualizacionMapa").innerHTML = ocultar_mapa;
	}
	
	/* AL CAMBIAR O CERRAR LA PAGINA */	
	document.onunload=window.onunload = function() {
		GUnload();
	}