$(document).ready(function() {
	
	// fading images on home-page
	$('#slideshow').cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 4000
	});
	
	// photo gallery pop-ups
	$('.gallery a').fancybox({
		centerOnScroll: true,
		overlayColor: '#ffffff',
		transitionIn: 'elastic',
		transitionOut: 'elastic'
	});
	
	// calendar form
	$('#calendarForm').submit(function() {
		event.preventDefault();
		// verify that all fields have been filled
		var emptyFields = $('#calendarForm input[type="text"]').filter(function() { return $(this).val() === ''; });
		if (emptyFields.length !== 0) {
			alert('Alle Felder sind erforderlich.');
			return false;
		}
		// submit the form to an email notification handler before forwarding to the donation page
		$this = $(this);
		$.ajax({
			data: $this.serialize(),
			dataType: 'html',
			type: $this.attr('method'),
			url: 'calendar-submission.php',
			success: function(response) {
				if (response === '1') {
					// redirect to donation page
					$this.unbind('submit').submit();
				}
				else {
					alert('Es gab ein Problem Absenden des Formulars.');
				}
			}
		});
	});
	
});
