(function($){

$(".chzn-select").chosen({allow_single_deselect:true});

function SendQuery() {
  $('#loader').show();
  var destination = $('#search-destination').val();
  var guest = $('#guest').val();
  var toGet = 'destination=' + destination + '&guest=' + guest;
  $('input.atmosphere:checked').each(function() {
    toGet = toGet + '&' + $(this).val() + '=1';
  })
  $('input.roomfeature:checked').each(function() {
    toGet = toGet + '&' + $(this).val() + '=1';
  })
  $('input.property:checked').each(function() {
    toGet = toGet + '&' + $(this).val() + '=1';
  })
  $('input.setting:checked').each(function() {
    toGet = toGet + '&' + $(this).val() + '=1';
  })

  $.get("search",
    toGet,
    function(data){
      $('#loader').hide();
      $('.block-vignettes').hide().empty();
      $('.block-number').hide().empty();
      $('#paginator').hide().empty();
      $('.block-vignettes').append(data).fadeIn();
      $('.block-number').append($('#resultsNb').html()).fadeIn();
      $('#paginator').append($('#pagination').html()).fadeIn();
    }
  );
}

/* move the price slide */
$('#min-price').draggable({
  axis: 'x',
  containment: 'parent',
  drag: function() {
    var currentPos = $(this).position();
    $('#min-price-value').empty().append(currentPos.left);
  }
});

/* send the query */
$("#searchForm").change(
  function(){
    SendQuery()
  }
);

})(jQuery);

