var opt = {
	messages : {
		email : {
			required: 'Pole wymagane'
		},
		question : {
			required: 'Pole wymagane'
		}
	}
};

function initializeValidator() {
	var opt = {
		beforeSubmit	: beforeSubmit,
		success			: done,
		clearForm		: true
	};
	
	if ($.validator != undefined) {
		$.validator.setDefaults({
			submitHandler: function(form) {
				$(form).ajaxSubmit(opt);
			},
			errorPlacement: function(error, element) {
				error.appendTo(element.prev());
			}
		});
	}
}

$(function(){
	$("a").focus(function(){ $(this).blur()});
	initializeValidator();
	$("#question").validate(opt);
	$("ul.gallery li a").lightBox();
});

function beforeSubmit(submitJson) {
	$("#question").find('button').before('<img class="loader" src="images/ajax-loader.gif" width="16" height="11" alt=""/>').remove();
}

function done() {
	$("#question")
		.before('<p class="msg">Zapytanie zostało wysłane!</p>')
		.remove();
	$("p.msg")
		.css('backgroundColor', '#f02857')
		.animate({
			backgroundColor: '#292a2e'
		}, 1000);
}
