// Function for toggling the placement address
function togglePlacementAddress(animationDuration) {
	var $e = $('#container-placementAddressField');
	if($('#plaatsingField-Nee').attr('checked')) {
		$e.slideDown(animationDuration);
	} else {
		$e.slideUp(animationDuration);
	}
}

$(document).ready(function() {
	$('a.fancy').fancybox({
		'titlePosition'	: 'inside'
	});

	$('#cycle').cycle({
		fx: 'fade',
		speed: 500,
		timeout: 5000
	});

	// Fix the hiding and showing of the placement address
	togglePlacementAddress(0);
	$('#plaatsingField input').click(function() {
		togglePlacementAddress(250);
	});

	// First, hide all boxes
	$('#container-fax, #container-email, #container-date').hide(0);

	// Fix the hiding and showing of the proper shipping form box
	var $shippingFields = $('#shipping-mail, #shipping-fax, #shipping-self');

	$shippingFields.each(function(){
		if ($(this).attr('checked')) toggleShipping($(this));
	});

	$shippingFields.click(function(){
		toggleShipping($(this));
	});

	function toggleShipping($element){
		var $id = $element.attr('id');
		if($id == 'shipping-mail') {
			$('#container-email:hidden').show();
			$('#container-fax:visible, #container-date:visible').hide();
		}
		if($id == 'shipping-fax') {
			$('#container-fax:hidden').show();
			$('#container-email:visible, #container-date:visible').hide();
		}
		if($id == 'shipping-self') {
			$('#container-date:hidden').show();
			$('#container-fax:visible, #container-email:visible').hide();
		}
	}
});
