
	var puntos_latlng = new Array();
	var map;

	/**
	 * Creamos y cargamos el mapa
	 * El string coords debe contener:
	 *  0. Latitud
	 *  1. Longitud
	 *  2. Titulo
	 *  3. Foto
	 *  4. Estrellas
	 *  5. Direccion
	 *  6. Poblacion
	 *  7. Telefono
	 *  8. Estrellas
	 *  9. Orden
	 */
	function load(coords){

	    if (GBrowserIsCompatible()) {
	        map = new GMap2(document.getElementById("map")); // ligamos el mapa a la capa predefinida
	        map.addControl(new GSmallMapControl()); // incluimos control de mapa pequeño (flechas)

            map.addMapType(G_PHYSICAL_MAP); // indicamos al control de tipo de mapa, que incluya el fisico
	        map.addControl(new GMapTypeControl()); // incluimos interfaz de control de usuario para cambiar tipo de mapa
	        map.addControl(new GScaleControl()); // incluimos la escala del mapa
	        map.setMapType(G_PHYSICAL_MAP); // definimos por defecto la vista a mapa fisico

			// determinamos las diferentes posiciones de los hoteles
			for(i=0; i < coords.length; i++)
			{
				var coord = coords[i].split("@"); // las coordenadas nos vienen separadas por ,

		        // Creamos el "marcador" para indicar el punto del hotel
				icon = createIcon(coord[9]); // creamos el icono
				point = createPoint(coord); // creamos el punto

				marker = createMarker(point, icon, coord); // montamos el marcador
			    map.addOverlay(marker);

			    puntos_latlng[puntos_latlng.length] = new GLatLng(coord[0], coord[1]);
	        }
			encuadra_mapa();
	    }
	}

	/**
	 * Creamos el marcador con todos los detalles
 	 * El array coords debe contener:
	 *  0. Latitud
	 *  1. Longitud
	 *  2. Titulo
	 *  3. Foto
	 *  4. Estrellas
	 *  5. Direccion
	 *  6. Poblacion
	 *  7. Telefono
	 *  8. Estrellas
	 *  9. Orden
	 */
	function createMarker(point, icon, coord)
	{
		var marker = new GMarker(point, icon);

		GEvent.addListener(marker, "click", function() {
			infoHtml = createHtml(coord); //
			marker.openInfoWindowHtml(infoHtml);
		});
		return marker;
	}

	/**
	 * Creacion del formulario buscador por hotel (por defecto)
	 */
	function createHtml(coord)
	{
		// farem cerca per hotel
		var infoHtml = '<div align="left" class="texto2 ocre">' + coord[2] + ' <img src="' + coord[8] + '"/></div>'
				+ '<br /><div align="left" class="texto"><img src="' + coord[3] + '" align="left" style="margin-right:10px;margin-bottom:10px;width:120px;height:80px;" />'
				+ coord[5]
				+ '<br />' + coord[6]
				+ '<br />' + coord[7]
				+ '<br />' + $('#habitaciones_desde').text()
				+ '<br /><br /><button onClick="submitForm(\'' + coord[10] + '\',\'' + coord[1] + '\',\'' + coord[0] + '\',\'' + coord[2] + '\',\'' + coord[6] + '\');" >Reservar</button>'
				+ '</div>';

		return infoHtml;
	}

	/**
	 * Creamos el punto con la coordenada
	 */
	function createPoint(coord)
	{
		return new GLatLng(coord[0], coord[1]);
	}

	/**
     *	Creamos un icono para el marcador
     */
	function createIcon(orden)
	{
		var rutaOrden = parseInt(orden);
		rutaOrden += 1;

		var icon = new GIcon(G_DEFAULT_ICON, $('#url_imagen').val() + '/images/icono_gm_' + rutaOrden + '.png');
	    icon.iconSize = GSize(27,25);

        return icon;
	}

	/**
	 * Encuadra el mapa con todos los puntos
	 */
	function encuadra_mapa()
	{
	    var latlngbounds = new GLatLngBounds();
	    for(var i = 0; i < puntos_latlng.length; i++)
	    {
	        latlngbounds.extend(puntos_latlng[i]);
	    }
	    map.setCenter(latlngbounds.getCenter(), map.getBoundsZoomLevel(latlngbounds)-1);
	}

	/**
	 * Montamos la fecha para la búsqueda
	 */
	function getDates(num)
	{
	 	// Fecha actual
		var today = new Date();

		var day = today.getDate();

		if (day < 10)
		{
			day = "0" + day;
		}

		var month = today.getMonth() + 1; // pq los meses van de 0 a 11

		if (month < 10)
		{
			month = "0" + month;
		}

		var year  = today.getFullYear();

		// Añadimos dias
		fecha = month + "/" + day + "/" + year;

		hoy = new Date(fecha);

		hoy.setTime(hoy.getTime() + num*24*60*60*1000);

		mes = hoy.getMonth() + 1;

		if(mes < 9)
			mes = "0" + mes;

		fechaIni = day + "/" + month + "/" + year;
		if (hoy.getDate() < 10)
		{
			dia = "0" + hoy.getDate();
		}
		else
		{
			dia = hoy.getDate();
		}
		fechaFin = dia + "/" + mes + "/" + hoy.getFullYear();

		var dates = new Array();
		dates[0] = fechaIni;
		dates[1] = fechaFin;

		return dates;
	}

	/**
	 * Seteamos el action del formulario y ponemos las fechas en la plantilla rutas_elemento.html
	 */
	function submitForm(id_hotel, longitud, latitud, nombre_hotel, nombre_provincia)
	{	    
		$('#longitud').val(longitud);
		$('#latitud').val(latitud);
		$('#tipo_busqueda').val('X_LOQUESEA');
		$('#nombre_ciudad').val(nombre_hotel);		
		$('#id_hotel').val(id_hotel);
		$('#descripcion_provincia').val(nombre_provincia);
		$('#formulario_buscador').submit();
	}

