
$(function(){

  // zainicjowanie lightboxa
  $('a[@rel*=lightbox]').lightBox();

  // znikanie wartości z pól input
  $("input[name=query]").focus(function() {
    var value = $(this).val();
    if (value == "Szukasz czegoś?") { $(this).val(""); }
  });
  $("input[name=query]").blur(function() {
    var value = $(this).val();
    if ($(this).val() == "") { $(this).val("Szukasz czegoś?"); }
  });

  $("input[name=email]").focus(function() {
    var value = $(this).val();
    if (value == "E-mail") { $(this).val(""); }
  });
  $("input[name=email]").blur(function() {
    var value = $(this).val();
    if ($(this).val() == "") { $(this).val("E-mail"); }
  });

  $("textarea[name=content]").focus(function() {
    var value = $(this).val();
    if (value == "Treść") { $(this).val(""); }
  });
  $("textarea[name=content]").blur(function() {
    var value = $(this).val();
    if ($(this).val() == "") { $(this).val("Treść"); }
  });

  $("input[name=login]").focus(function() {
    var value = $(this).val();
    if (value == "Login...") { $(this).val(""); }
  });
  $("input[name=login]").blur(function() {
    var value = $(this).val();
    if ($(this).val() == "") { $(this).val("Login..."); }
  });

  $("input[name=pass]").focus(function() {
    var value = $(this).val();
    if (value == "Hasło...") { $(this).val(""); }
  });
  $("input[name=pass]").blur(function() {
    var value = $(this).val();
    if ($(this).val() == "") { $(this).val("Hasło..."); }
  });
  
  // wyświetlenie 10 newsów w aktualnościach
  if ($("div#content div.news").length > 10) {
    var height = 20;
    $("div#content div.news").each(function(i){
      if (i < 10) {
        height += $(this).height() + $(this).css("margin-bottom");
        return true;
      }
      $(this).hide();
    });
    
    $("div#content").height(height);
    $("div#content div.news:visible:last").after('<p style="text-align: right;"><a href="#" id="showAllNews">Zobacz wszystkie</a></p>');
    $("div#content a#showAllNews").click(function(){
      $("div#content").height(height);
      $("div#content div.news:hidden").show();
      $(this).hide();
      return false;
    });
  }

  // Formularz rejestracji uczestników tabliczki
  $("form#mtable input[value=Imię]").focus(function(){
    if ($(this).val() == "Imię") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Imię");
    });
  });

  $("form#mtable input[value=Nazwisko]").focus(function(){
    if ($(this).val() == "Nazwisko") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Nazwisko");
    });
  });

  $("form#mtable input[value=Pełna nazwa szkoły]").focus(function(){
    if ($(this).val() == "Pełna nazwa szkoły") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Pełna nazwa szkoły");
    });
  });

  $("form#mtable input[value=Adres szkoły]").focus(function(){
    if ($(this).val() == "Adres szkoły") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Adres szkoły");
    });
  });

  $("form#mtable input[value=Telefon]").focus(function(){
    if ($(this).val() == "Telefon") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Telefon");
    });
  });

  $("form#mtable input[value=Adres e-mail]").focus(function(){
    if ($(this).val() == "Adres e-mail") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Adres e-mail");
    });
  });

  $("form#mtable input[value=Ilość kompletów kart]").focus(function(){
    if ($(this).val() == "Ilość kompletów kart") $(this).val("");
    $(this).blur(function(){
      if ($(this).val() == "") $(this).val("Ilość kompletów kart");
    });
  });
  
  $("form#mtable").submit(function(){
    $("input[type=submit]", this).attr("disabled","disabled");
  });

});

