/**
 * En este JS vamos a definir todos los atributos y metodos comunes para todas
 * las pantallas de landings.
 *
 * Author: cesc
 */
 $(document).ready(function(){
    $('#buscador_rapido_elementos').keyup(filtra_elementos);
    $('#item_menu_cabecera_4086').addClass('selected'); // HOTELES
    $('#buscador_rapido_elementos').focus();
    $("#landing_content_inner .landing_minificha:even").addClass("impar");
 });
 
 /**
  * Atributos globales
  */
var enlaces_mostrados = new Array();
var listado_hoteles = new Array();
var mapa_hoteles;

 /**
  * Filtra los elementos de la lista
  * seg�n lo introducido.
  */
 function filtra_elementos(event) {
    if (event.keyCode == 13) {
      if (enlaces_mostrados.length > 0) {
        document.location.href = enlaces_mostrados[0];
      }
    } else {
        enlaces_mostrados = new Array();
        var valor_filtro = $(this).val().toLowerCase();
    
        $('#busqueda_local_elemento a h3').each(function(indice, elemento) {
            if (valor_filtro != '') {
                var contenido_elemento = $(elemento).html().toLowerCase();
            
                if (contenido_elemento.match(new RegExp(valor_filtro))) {
                    // Mostramos
                    $(this).fadeIn();
                    enlaces_mostrados[enlaces_mostrados.length] = $(this).parent().attr('href');
                } else {
                    // Ocultamos
                    $(this).fadeOut();
                }
            } else {
                // Mostramos
                $(this).fadeIn();
                enlaces_mostrados[enlaces_mostrados.length] = $(this).parent().attr('href');
            }
        });
    }
 }
 
 /**
  * Dibujamos google maps
 */
function dibuja_mapa_hoteles(capa) 
{
   
   var myoptions = {
      zoom:13,
      navigationControl: true,
      navigationControlOptions: {
        style: google.maps.NavigationControlStyle.SMALL
      },
      scaleControl: false,
      mapTypeControl:true,
      center: new google.maps.LatLng( 41.390876 , 2.166262),
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      streetViewControl: true
   };

   mapa_hoteles = new google.maps.Map(document.getElementById(capa), myoptions);
 }
 
 /**
  * Metodo para a�adir hoteles en el array
  * que los dibuaj� en al mapa
 */
function agrega_hotel_mapa(codigo, nombre, estrellas, direccion, pais, ciudad, foto_principal, longitud, latitud, link) 
{
   listado_hoteles[listado_hoteles.length] = {
      codigo: codigo, 
      nombre:nombre, 
      estrellas: estrellas, 
      direccion: direccion, 
      pais: pais, 
      ciudad: ciudad, 
      foto_principal: foto_principal, 
      longitud:longitud, 
      latitud:latitud, 
      link:link
   };
 }
 
 /**
  * Dibujamos cada hotel en el google maps
 */
function coloca_hoteles_mapa() 
{
  var puntos_agregados = new Array();
  
  $(listado_hoteles).each(function(indice, elemento) 
  {
    if ((elemento.longitud != '') && (elemento.latitud != '')) 
    {
      var punto =  new google.maps.LatLng(elemento.latitud , elemento.longitud);
      puntos_agregados[puntos_agregados.length] = punto;

	  var hotel = new google.maps.Marker({
        position: punto,
        map: mapa_hoteles,
        icon: '/CLIENTES/www.eurostarshotels.com/imagenes_plantillas/marker.png'
      });

      var html = '<div id="listener" class="doce">';
      html += '<div id="listener_nombre"><a href="'+ elemento.link +'">'+ elemento.nombre+'</a></div> ';
      html += '<div id="listener_foto"><img src="'+elemento.foto_principal+'" ></div>';
	  html += '<div id="listener_direccion">'+elemento.direccion+'<br /> <strong>'+elemento.ciudad+' </strong> </div>';
      html += '<div style="clear:both;"></div><br />';
      html += '&nbsp;</div>';

      var infoWindow = new google.maps.InfoWindow({
        content: html,
		maxWidth: 300,
        size: new google.maps.Size(80,50)
      });

      google.maps.event.addListener(hotel, 'click', function() {
        infoWindow.open(mapa_hoteles, hotel);
      });
    }
  });

  // Encuadramos mapa con el mximo zoom posible mostrando todos
  // los puntos existentes.
  var bounds = new google.maps.LatLngBounds();
  for (var i = 0; i < puntos_agregados.length; i++) {
      bounds.extend(puntos_agregados[i]);
  }
  mapa_hoteles.fitBounds(bounds);


}

/**
 * colocación de hoteles en el mapa, pero para la
 * api v2 de google.
 */ 
function oloca_hoteles_mapa_v2() 
{
  var puntos_agregados = new Array();
  
  $(listado_hoteles).each(function(indice, elemento) 
  {
    
  });
}

