$(document).ready(function()
  {
    // lightbox
    $(".plakat").lightBox();
    $("#fotogalerie .img-in a").lightBox();
    $("#download-box a.img").lightBox();

    // fotogalerie
    $("#ostatni-fotky").hide();
    $("p.vsechny-fotky a").click(function () {
      if ($(this).hasClass("hide")) {
        $("#ostatni-fotky").hide();
        $(this).removeClass("hide");
        $(this).text("Zobrazit všechny fotografie");
      }
      else
      {
        $("#ostatni-fotky").show();
        $(this).addClass("hide");
        $(this).text("Skrýt ostatní fotografie");
      }
    })

    // vyhledani
    var $textik = "Vyhledání..."
  
    $("#sb-text").attr("value", $textik);

    $("#sb-text").blur(function () {
      if (!$(this).attr("value")) {
        $(this).attr("value", $textik);
      }
    })
    $("#sb-text").focus(function () {
      if ($(this).attr("value") == $textik) {
        $(this).attr("value", "");
      }
    })

    $("#sb-submit").click(function () {
      if ($("#sb-text").attr("value").length < 2 || $("#sb-text").attr("value") == $textik) {
        alert("Minimální délka hledaného výrazu je 2 znaky!");
        return false;
      }
    })

    //externi odkazy a popup
    $("a").filter(function() {
      return this.hostname && this.hostname !== location.hostname;
    }).addClass("external");

    $("a.external, a.popup").click(function() {
      window.open(this.href);
      return false;
    });

    // BANNER
    // 
    // Define margin for center alignment (vertical + horizontal)
    var popMargTop = 50;//($(document).height() - $('#banner').height()) / 2;
    var popMargLeft = ($(document).width() - $('#banner').width() - 40) / 2;

    //Apply Margin to Popup
    $('#banner').css({
      'margin-top' : popMargTop,
      'margin-left' : popMargLeft
    });

    //Close Popups and Fade Layer
    $('a.close, #fade').click(function () { //When clicking on the close or fade layer...
      $('#fade , #banner').fadeOut(function() {
        $('#fade, a.close').remove();
      }); //fade them both out

      return false;
    });


  
  });

