$(document).ready(function() {
  //$('#yachtDescription').hide();
  $("#marina_region").autocomplete("/marinas;region");
  $("#marina_water").autocomplete("/marinas;water");
  $("#marina_island").autocomplete("/marinas;island");
  //$('#userGalleryImages img').Tooltip({ showURL: false });
  $('.date-pick').datePicker({clickInput:true,createButton:false});
  $(function() {
        $('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
      });
});



function gmaps_loaded() {
  return (typeof(window['GMap2']) != "undefined");
}

function bigZoom()  {
  map.setCenter(position, 15);
  $('#setZoom').toggle("slow");
  $('#unsetZoom').toggle("slow");
}

function smallZoom()  {
  map.setCenter(position, 8);
  $('#setZoom').toggle("slow");
  $('#unsetZoom').toggle("slow");
}


//$("td.length_field input").each(function(i){alert($(this).val() + "1")})

function  addNew3Files()  {
  photos = parseInt($('#fieldsCount').val());
  for(i = photos + 1;i <= photos + 3;i++) {
    html = '<div class=\"left box\"><input id=\"file' + i + '\" type=\"file\" name=\"new_image[file_' + i + ']\" /><br />Opis zdjęcia: <br /><input id=\"description' + i + '\" type=\"text\" name=\"new_image_description[file_' + i + ']\" size=\"31\" /></div>';
    $('#newPhotos').append(html);
   }  
   fields = parseInt($('#fieldsCount').val()) + 3;
   $('#fieldsCount').val(fields);
}

function displayDescription(id) {
  $('#photo' + id).removeClass('box');
  $('#photo' + id).addClass('darkBox');
  $('#photosDescription').empty();
  $('#photosDescription').append($('#' + id).html());
}

function hideDescription(id) {
  $('#photo' + id).removeClass('darkBox');
  $('#photo' + id).addClass('box');  
  $('#photosDescription').empty();
  info = 'Po najechaniu myszką na zdjęcie, zobaczysz jego opis. Kliknięcia powiększa zdjęcie.';
  $('#photosDescription').append(info);
}

function  showAddnationalInfo() {
  $('#addnationalInfo').toggle();
}
function removePhoto(confirmation,info,id) {
  if (confirm(confirmation)) {
    $.ajax({
    type: "POST",
    url: "/yachts/remove_photo/" + id,
    date: '',
    dataType: 'html',
    beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/html");},
    success: function(data) {
      $('#' + id).remove();
      $('#photoInfo').empty();
      $('#photoInfo').append(info);
      }
    });
  }
}

function renderUpdatedGallery(id) {
  $.ajax({
    type: "POST",
    url: "/galleries/render_gallery/" + id,
    dataType: 'html',
    beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/html");},
    success: function(data) {
        $("#galleryImages").empty();
        $("#galleryImages").append(data);
        }
  });
}

function checkName(field)  {
  if ($('#' + field).val() != "") {    
  }
  else
  {
    alert("Podaj proszę nazwę!");
    return false;
  }     
}

function setMarinaAsVisited(user_id,marina_id)  {
  function renderUpdatedGallery(id) {
  $.ajax({
    type: "POST",
    url: "/marinas;visited",
    dataType: 'html',
    data:"user_id=" + user_id + "marina_id" + marina_id, 
    beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/html");},
    success: function(data) {
      $("#visitMarina").empty();
      $("#visitMarina").append(data);
      }
    });
  }
}




