
/* obsluzny js pro mapu hotelu na trips listu */


/* dotazeni ceskych hotelu dle parametru */
function loadMapHotels(id, params, displayed) 
{ 
  function IsNumeric(input) {
      return (input - 0) == input && input.length > 0;
  }  
  params = params.replace(/&amp;/g, "&") 
  counter = 0;         

  $.getJSON(documentPath + "?" + params, {getMapHotels: 1, ajax: 1, displayed: displayed}, function(j) {  
    if (j != null) {  
      mapHotels = j; 
      //alert(mapHotels);
      for (var i = 0; i < j.length; i++) {
        (function () {  
          var parts = j[i].gps.split(',');
          var hotel = j[i];
          if((parts.length >= 2) && IsNumeric(parts[0]) && IsNumeric(parts[1])) { 
            //addMarker(new google.maps.LatLng(parts[0], parts[1]),  j[i].name + " - od " + j[i].minPrice, j[i].name + " - od " + j[i].minPrice, id, "hotel" );   
            markers.push(addMarker(new google.maps.LatLng(parts[0], parts[1]), 
               function() { showHotelDescription('Hotel', hotel.id, {'hideOffersButton': 0, 'documentUrl': hotel.url, 'minPrice': hotel.minPrice, 'minDays' : 7 }); }, 
               hotel.name + " - od " + hotel.minPrice, id, "hotel", { "price": hotel.minPriceOriginal } )); 
            counter++;
          } 
        })();
      }
      
      loadMapSlider(id);  
    }
    else {  
        
    }
    
    $("#"+id+"_status").hide();
    
  }); 
}


/* ziskani destinaci */
function loadMapDestinations(id, params) 
{ 
  function IsNumeric(input) {
      return (input - 0) == input && input.length > 0;
  }    

  params = params.replace(/&amp;/g, "&") 
  $.getJSON(documentPath + "?" + params, {getMapDestinations: 1, ajax: 1}, function(j) { 
    if (j != null) {       
      for (var i = 0; i < j.dst.length; i++) {
        (function () {  
          var dest = j.dst[i];             
          var parts = dest.gps.split(',');
          if((parts.length >= 2) && IsNumeric(parts[0]) && IsNumeric(parts[1])) {   
            addMarker(new google.maps.LatLng(parts[0], parts[1]), function() { location.href = dest.url; }, "Přejít na destinaci "+dest.name+" - nabídky od "+dest.minPrice, id, "dest"); 
          } 
          else {
             var geocoder = new google.maps.Geocoder();
             geocoder.geocode( { 'address': dest.name}, function(results, status) {
               if (status == google.maps.GeocoderStatus.OK) 
                 addMarker(results[0].geometry.location, function() { location.href = dest.url; }, "Přejít na destinaci "+dest.name+" - nabídky od "+dest.minPrice, id, "dest"); 
             });
          }  
        })();
      } 
    }     
  });  
} 


/* nastaveni rozsahu slideru na cenu podle hotelu v mape */
function loadMapSlider(id) 
{ 
  var max = 0, min = 0;          
  var range_max = 0;        
  var range_min = parseInt(markers[0].get("price"));
  
  for (var i = 0; i < markers.length; i++) {
    var price = parseInt(markers[i].get("price"));
    if(price > range_max)
      range_max = price;
    if(price < range_min)
      range_min = price;
  }  
                                
  min = Math.floor(range_min/10000)*10000; 
  max = Math.ceil (range_max/10000)*10000;      
  range_min = Math.floor(range_min/1000)*1000; 
  range_max = Math.ceil (range_max/1000)*1000; 
      
  $("#map_slider_price").slider("option", "min", min);
  $("#map_slider_price").slider("option", "max", max);
  $("#map_slider_price").slider("option", "values", [range_min, range_max]); 
  $("#price_interval").text(range_min + " Kč - " + range_max + " Kč" );
}
