$(document).ready(function() {
  var default_search_value = $("form#search input").val();
  // otevre odkaz v novem okne
  $("a.external").click(function() {
    open($(this).attr("href"));
    return false;
  });
  
  
  if ($("#section_text img[src*='projects']").length > 0 || $("#section_text img[src*='partners']").length > 0){
      $("#section_text").addClass("section_text_white");  
    }
  


  $("form#search input").focus(function() {
    $(this).val("");
    $(this).removeClass("text-right").addClass("text-left");
  });
  $("form#search input").blur(function() {
    $(this).val(default_search_value);
    $(this).removeClass("text-left").addClass("text-right");
  });

  // pop-up menu
//  $("div#menu_3").hover(function() {
//    $("div#popup_3").css("display", "block");
//    }, function() {
//      $("div#popup_3").css("display", "none");
//  });
//  $("div#menu_4").hover(function() {
//      $("div#popup_4").css("display", "block");
//    }, function() {
//      $("div#popup_4").css("display", "none");
//  });
  $("div.menu_item").hover(function() {
      $("div.popup", this).css("display", "block");
    }, function() {
      $("div.popup", this).css("display", "none");
  });
  $("div.popup_item a").hover(function() {
      $(this).addClass("popup_hover");
    },
    function() {
      $(this).removeClass("popup_hover");
  });

  // kontrola kontaktniho formulare pri odesilani
  $("form#form_kontakty").submit(function() {
    var errors = "";
    if ($("input#name", $(this)).val() == "") {
      errors += translations["kontakty_form_jmeno_prijmeni"]+"\n";
    }
    if ($("input#email", $(this)).val() == "") {
        errors += translations["kontakty_form_email"]+"\n";
    }
    if ($("input#phone", $(this)).val() == "") {
        errors += translations["kontakty_form_telefon"]+"\n";
    }
    if ($("input#subject", $(this)).val() == "") {
        errors += translations["kontakty_form_predmet"]+"\n";
    }
    if ($("textarea#text", $(this)).val() == "") {
        errors += translations["kontakty_form_zprava"]+"\n";
    }
    if ($("input#code", $(this)).val() == "") {
        errors += translations["kontakty_form_kod"]+"\n";
    }
    
//    if ($("input#code", $(this)).val() == "") {
//        errors += "Kontrolní kód\n";
//    }

    if (errors != "") {
      alert(translations["kontakty_povinne"]+"\n\n"+errors);
      return false;
    } else {
      return true;
    }
  });

  $("a.del_file").click(function() {
    return confirm(translations["dokumenty_opravdu_smazat_soubor"]);
  });

  $("button#btn_delete_contact").click(function () {
    return confirm(translations["kontakty_opravdu_smazat"]);
  });
});
