$(document).ready(function() {
	$('.layer').css("height",document.body.offsetHeight+"px");

	$('#success_layer').css("height",document.body.offsetHeight+"px");
	$('#success_layer').css("display","block");
	$('#success_layer_bonus').css("height",document.body.offsetHeight+"px");
	$('#success_layer_bonus').css("display","block");
	$('#success_layer_cart').css("height",document.body.offsetHeight+"px");
	$('#success_layer_cart').css("display","block");
	$('#success_layer_voucher_cart').css("height",document.body.offsetHeight+"px");
	$('#success_layer_voucher_cart').css("display","block");

	$('#error_layer').css("height",document.body.offsetHeight+"px");
	$('#error_layer').css("display","block");
	$('#error_layer_bonus').css("height",document.body.offsetHeight+"px");
	$('#error_layer_bonus').css("display","block");

	$('#voucher_layer').css("display","none");
	$('#voucher_error_layer').css("height",document.body.offsetHeight+"px");
	$('#voucher_error_layer').css("display","block");
	$('#voucher_cart_layer').css("height",document.body.offsetHeight+"px");
	$('#voucher_cart_layer').css("display","block");		

	if ($.browser.msie){
		// Layer auf die volle Breite setzen
		$('.layer').css("width",document.body.offsetWidth+"px");

		$('#success_layer').css("width",document.body.offsetWidth+"px");
		$('#success_layer_bonus').css("width",document.body.offsetWidth+"px");
		$('#success_layer_cart').css("width",document.body.offsetWidth+"px");
		$('#success_layer_voucher_cart').css("width",document.body.offsetWidth+"px");

		$('#error_layer').css("width",document.body.offsetWidth+"px");
		$('#error_layer_bonus').css("height",document.body.offsetHeight+"px");

		$('#voucher_error_layer').css("width",document.body.offsetWidth+"px");
		$('#voucher_cart_layer').css("width",document.body.offsetWidth+"px");
	}

	// Newsletter layer
	$("form#quickNewsletterForm a.submit").click(function(e) {
		e.preventDefault();
		var href = $(this).attr("href");
		if (href.lastIndexOf("?") < 0) {
			href += "?";
		} else {
			href += "&"
		};
		href += "email=" + encodeURIComponent($(this).parents('form').find('input[name=email]').val());
		$.fancybox({
			'type'               : 'iframe',
			'centerOnScroll'     : true,
			'hideOnOverlayClick' : false,
			'showCloseButton'    : false,
			'overlayOpacity'     : 0.8,
			'overlayColor'       : '#000',
			'scrolling'          : 'no',
			'autoScale'          : false,
			'width'              : 438,
			'height'             : 517,
			'padding'            : 5,
			'href'               : href
		})
	});
});

function openLayer(layer) {
	$(layer).css("width",document.body.offsetWidth+"px");
	$(layer).css("height",document.body.offsetHeight+"px");
	$(layer).show();
	if ($(layer).children(".body").css("position") != "fixed") {
		window.scrollTo(0,0);
	}
}

function closeLayer(layer) {
	$(layer).hide();
}

function closeAllLayers() {
	$(".layer").hide();
	parent.$.fancybox.close();
}

function switchLayer(layer1, layer2) {
	closeLayer(layer1);
	openLayer(layer2);
}

function switchToLayer(layer) {
	closeAllLayers();
	openLayer(layer);
}

function adjustFancyboxSize() {
	var iframe = parent.document.getElementById("fancybox-frame");
	if (iframe != null) {
		//iframe.width = document.body.offsetWidth;
		iframe.height = document.body.offsetHeight;
	}
	parent.$.fancybox.resize();
}

