$(document).ready(function(){
  $("a[rel='lightbox']").colorbox();
  $('a').filter(function() {
	  return this.hostname && this.hostname !== location.hostname;
	}).addClass("external");
	$(".js").each(function (i) {
    $(this).css({
	    'display': 'block'
    });
  })
  $(".non-js").each(function (i) {
    $(this).css({
	    'display': 'none'
    });
  })
  if ($('#form_kontrola').length != 0) {
    $('#form_kontrola').val('Praha');
  }
	$(function(){
    $.fn.formLabels();
  });
  $('#top ul li').hover(
    function () {
      $(this).find('ul').show(300);
    },
    function () {
      $(this).find('ul').stop(true, true).hide(200);
  });
  if ($('#ceny-change').length != 0) {
    var id = $("#ceny-change option:selected").attr('id');
    var tab = "#table-" + id;
    $(tab).css({
	    'display': 'block'
    });
    
    $('#ceny-change').change(function() {
      $(".ceny").css({
  	    'display': 'none'
      });
      var id = $("#ceny-change option:selected").attr('id');
      var tab = "#table-" + id;
      $(tab).css({
  	    'display': 'block'
      });
      $("#ceny-change option").not(':selected').each(function (i) {
        var id = $(this).attr('id');
        var input = ".input-" + id;
        $(input).val('');
      })
      //alert(id);
    });
  }
  if ($('.form_check').length != 0) {
    $(".form_check").validate({
      invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();
        if (errors) {
          var message = 'Vyplňte prosím povinné položky';
          $("div.error").html(message);
          $("div.error").show();
        } else {
          $("div.error").hide();
        }
      }
    })
  }
  if ($('#footer_form').length != 0) {
    $("#footer_form").validate({
      invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();
      }
    })
  }
});
