function showFancyBox( Contents ) {
$.fancybox('<div id="#popup">'+Contents+'</div>', {
				'autoDimensions' : false,
				'width' : 500,
				'height' : 'auto',
				'transitionIn' : 'fade',
				'transitionOut' : 'fade',
				'titleShow' : 'false',
				'enableEscapeButton' : 'true'
			});
			assignEvents();
}


function assignEvents() {
	// Remove all previous bindings
	$("a[href*='bestelform']").unbind();
	$("a[href*='besteldomein']").unbind();
	$("form#popupNewOrder").unbind();
	$("form.whoIsForm").unbind();

	// Intercept Bestel Popup links
	$("a[href*='bestelform']").click(function(event) {
		event.preventDefault();
		$.post("am-temp/bestelformulier.php", "link=" + $(this).attr("href"), function(data) {
			showFancyBox(data);
		});
		return false;
	});
	
	// Intercept WhoIs popup links
	$("a[href*='besteldomein']").click(function(event) {
		event.preventDefault();
		$.post("/am-temp/whoisformulier.php", "link=" + $(this).attr("href"), function(data) {
			showFancyBox(data);
		});
		return false;
	});
	
	// Intercept form
	$("form#popupNewOrder").submit(function(event) {
		event.preventDefault();
		var data = $(this).serialize();
		data += "&formName=" + $(this).attr("id");

		$(this).find('.notifications').slideUp( {
			duration : 'normal',
			easing : 'easeOutExpo',
			step : function() {
				$.fancybox.resize();
			},
			complete : function() {
				$(this).html('<!-- # -->');
				currentMe = this;
				$.post('/am-temp/orderhandler.php', data, function() {
					$(currentMe).slideDown( {
						duration : 'slow',
						easing : 'easeOutExpo',
						step : function() {
							$.fancybox.resize();
						}
					});
				}, 'script');
			}
		});
		return false;
	});
	
	// Intercept Whois Form
	$("form.whoIsForm").submit(function(event) {
		event.preventDefault();
		var formData = $(this).serialize();
		$.post("am-temp/whois.php", formData, function(data) {
			showFancyBox(data);
		});
		return false;
	});

}

$(document).ready(function() {
	assignEvents();
});
