$(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = $("#signupform").validate({
		rules: {
			fullname: "required",
			password: {
				required: true,
				minlength: 5
			},
			password_confirm: {
				required: true,
				minlength: 5,
				equalTo: "#password"
			},
			email: {
				required: true,
				email: true,
				//remote: "emails.php"
			},
			gender:"required",
			kategorie:"required",
			terms:"required",
			captcha:"required",

		},
		messages: {
			fullname: "Zadejte prosím své celé jméno",
			captcha: "Napište číslo, kolik je na obrázku nástrojů.",
			password: {
				required: "Zadejte prosím heslo",
			},
			password_confirm: {
				required: "Zadejte prosím heslo",
				equalTo: "Hesla se neshodují"
			},
			email: {
				remote: jQuery.format("{0} is already in use")
			},
			dateformat: "Choose your preferred dateformat",
			terms: "Musíte souhlasit s pravidly a podmínkami."
		},
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
	});

});


$(document).ready(function(){

	// accordion functions
	var accordion = $("#stepForm").accordion();
	var current = 0;

	$.validator.addMethod("pageRequired", function(value, element) {
		var $element = $(element)
		function match(index) {
			return current == index && $(element).parents("#sf" + (index + 1)).length;
		}
		if (match(0) || match(1) || match(2)) {
			return !this.optional(element);
		}
		return "dependency-mismatch";
	}, $.validator.messages.required)

	var v = $("#cmaForm").validate({
		errorClass: "warning",
		onkeyup: false,
		onblur: false,
	});

	// back buttons do not need to run validation
	$("#sf2 .prevbutton").click(function(){
		accordion.accordion("activate", 0);
		current = 0;
	});
	$("#sf3 .prevbutton").click(function(){
		accordion.accordion("activate", 1);
		current = 1;
	});
	// these buttons all run the validation, overridden by specific targets above
	$(".open2").click(function() {
	  if (v.form()) {
	    accordion.accordion("activate", 2);
	    current = 2;
	  }
	});
	$(".open1").click(function() {
	  if (v.form()) {
	    accordion.accordion("activate", 1);
	    current = 1;
	  }
	});
	$(".open0").click(function() {
	  if (v.form()) {
	    accordion.accordion("activate", 0);
	    current = 0;
	  }
	});
});

$(document).ready(function(){
   $('#selectCategory').hoverAccordion({
      keepHeight: true,
      activateItem: 3,
      speed: 'fast'
   });
});

$(document).ready(function(){
	$('a#gotop').click(function() 
	{
		$('body').animate({scrollTop : 0},500);
		return false;
	});
});

$(document).ready(function(){
	$('.invisibleButton').css('visibility','visible');
	$('#selectCategory').css('height','100px');
});


$(document).ready(function() 
{
    $('.lightbox a').lightBox();
	$('a.lightbox').lightBox();
});


  window.___gcfg = {lang: 'cs'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();

