overlayStatus = 'off';
function overlaySet(cont)
{
	if (cont == '#payment') {
		var width = 500;
		var height = 600;
	} else {
		var width = 600;
		var height = 400;
	}
	var offset = (height / -2) + 4;

	// If no overlay is displayed
	if (overlayStatus == 'off' && cont != 'off') {
		$('#overlay').css('display', 'inline').animate({opacity: 0.85}, 400, 'swing');
		$('#overlay_super_container').css('display', 'inline').css('margin-top', offset + 'px');
		$('#overlay_container_shadow').animate({opacity: 1, width: width + 'px',height: height + 'px'}, 400, 'swing', function () {
			$('#overlay_container').animate({opacity: 1}, 400, 'swing');
			$('#overlay_divs').animate({opacity: 1}, 400, 'swing');
			$(cont).css('display', 'inline');
		});
		overlayStatus = 'on';

	// If we wish to hide overlay
	} else if (cont == 'off') {
		$('#overlay_divs').animate({opacity: 0}, 400, 'swing');
		$('#overlay_container').animate({opacity: 0}, 400, 'swing', function () {
			$('#overlay_container_shadow').animate({opacity: 0, width:"52px",height:"52px"}, 400, 'swing');
			$('#overlay').animate({opacity: 0}, 400, 'swing', function () {
				$('#overlay').css('display', 'none');
				$('#overlay_super_container').css('display', 'none');
				$('.o_c').css('display', 'none');
			});
		});
		overlayStatus = 'off';

	// If we want to swap overlay
	} else if (overlayStatus = 'on') {
		$('#overlay_divs').animate({opacity: 0}, 200, 'linear', function () {
			$('.o_c').css('display', 'none');
			$(cont).css('display', 'inline');
			$('#overlay_divs').animate({opacity: 1}, 200, 'linear');
		}); 
	}
}


function fade(id,alpha,endalpha)
{
	// Step av 100
	var step = 10;
	var timer = 10;
	var tt = document.getElementById(id);
	if (alpha < endalpha)
	{
		var go = 1;
	} 
	else
	{
		var go = -1;
	} 
	tt.style.display = 'inline';
	tt.timer = setInterval(function(){actualFade(go);},timer);
	
	function actualFade(d)
	{
		var a = alpha;
		if((a != endalpha && d == 1) || (a != 0 && d == -1)){
			var i = step;
			if(endalpha - a < step && d == 1){
				i = endalpha - a;
			}else if(alpha < step && d == -1){
				i = a;
			}
			alpha = a + (i * d);
			tt.style.opacity = alpha * .01;
			tt.style.filter = 'alpha(opacity=' + alpha + ')';
		}else{
			clearInterval(tt.timer);
		//	if(d == 1){startFades();}
			if(d == -1){tt.style.display = 'none';}
		}
	}
}
window.onkeyup = function (event) {
		if (event.keyCode == 27) {
			javascript:overlaySet('off');
		}
};
