(function(){
	$('#submitThank').bind('click', function(){
		$(this).prop('disabled', true);
		$('#thKrutilka').show();
		$.ajax({
		      url: $('#thankForm').attr('action'),
		      type: 'post',
		      data : $('#thankForm').serialize(),
		      async: false, 
		      success: function(data){
		    	  $('#thKrutilka').hide();
		    	  if (data.success) {
		    		  $.when(
	      				$("#success").animate({ opacity: 1 }, 1000).promise()
	  		    	  ).done(function(){
	      				$('#thankModal').modal('hide');
	      				$("#success").css('opacity', 0);
	      				$('#submitThank').prop('disabled', false);
	  		    	  });
		    	  }
		    	  else {
		    		  $.when(
	      				$("#fail").animate({ opacity: 1 }, 1000).promise()
	  		    	  ).done(function(){
	      				$('#thankModal').modal('hide');
	      				$("#fail").css('opacity', 0);
	      				$('#submitThank').prop('disabled', false);
	  		    	  });
		    	  }
		      },
		}, 'json');
	});
})();