$(document).ready(function(){
	
   /**
	* Initial hide the sportcard an insurance number field.
	* On form submit, ask whether the email adress is correct.
	*/
	if($("#signupForm").length > 0) {		
		
		if($("#insurance-1:checked").length == 0) {
			$("#insuranceNr, label[for='insuranceNr']").parent().hide();
		}
		if($("#sportcard-1:checked").length == 0) {
			$("#sportcardNr, label[for='sportcardNr']").parent().hide();
		}

		$("#insurance-1").click(function () {
			$("#insuranceNr, label[for='insuranceNr']").parent().slideDown("slow");
		});
		$("#sportcard-1").click(function () {
			$("#sportcardNr, label[for='sportcardNr']").parent().slideDown("slow");
		});
		$("#insurance-0").click(function () {
			$("#insuranceNr, label[for='insuranceNr']").parent().slideUp("slow");
		});
		$("#sportcard-0").click(function () {
			$("#sportcardNr, label[for='sportcardNr']").parent().slideUp("slow");
		});
		
		$("#signupForm").submit(function () {
			if($("#email").val() != '') {
				msg = "Weet jke zeker dat je het juiste mailadres (" + $("#email").val() + ") hebt opgegeven?";
				return confirm(msg);
			} else {
				return true;
			}
		});
		
	}
	
   /**
	* Image fade in effect.
	*/
	$("#banner").hoverIntent(function () {
		$(this).animate( { opacity: 0 }, 1000);
	}, function () {
		$(this).animate( { opacity: 1 }, 1000);
	}).click(function () { window.location = 'http://www.spacsport.nl/'; });
	
   /**
	* Menu anmimations.
	*/
	$("#menu li").css("opacity", "0.75");
	
	$("#menu li:not(.submenu)").hover(
		function () {
			$(this).animate( { opacity: 1, textColor: '#42B0FF' }, 300 );
			$(this).children("a").pulse({
			    textColors: ['#42B0FF', '#fff'],
				speed: 800,
				runLength: 1
			});
		},
		function () {
			$(this).children("a").recover();
			$(this).animate( { opacity: 0.75 }, 500 );
		}
	);
	
	var config = {    
	     sensitivity: 1,  
	     interval: 10,
	     over: makeTall,
	     timeout: 500,
	     out: makeShort
	};
	
	$("#menu .submenu").hoverIntent(config);
	
	function makeTall() {
		$(this).css("opacity", "0.75");
		$(this).animate( { opacity: 0.97 } , 1000 );
		$(this).children("ul").slideDown(300);
		$(this).children("ul").children("li").animate( { opacity: 0.75 }, 300 );
	};
	
	function makeShort() {
		$(this).animate( { opacity: 0.75 } , 700 );
		$(this).children("ul").slideUp(500);
	};
	
	$('#admin h3').next().hide();
	$('#admin h3').css('cursor', 'pointer');
	$('#admin h3').click(function() {
		$(this).next().slideToggle();
	});
	
	jQuery(function($){
		$.datepicker.regional.nl = {
			closeText: 'Sluiten',
			prevText: '←',
			nextText: '→',
			currentText: 'Vandaag',
			monthNames: ['januari', 'februari', 'maart', 'april', 'mei', 'juni',
			'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
			monthNamesShort: ['jan', 'feb', 'maa', 'apr', 'mei', 'jun',
			'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
			dayNames: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
			dayNamesShort: ['zon', 'maa', 'din', 'woe', 'don', 'vri', 'zat'],
			dayNamesMin: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
			dateFormat: 'yy-mm-dd', firstDay: 1,
			isRTL: false};
		$.datepicker.setDefaults($.datepicker.regional.nl);
		
	});
	
});

