$(document).ready(function(){

	$(window)
	.resize(function(e){
		CenterInterstitial();
	})
	.scroll(function(e){
		CenterInterstitial();
	})
	;

	var CenterInterstitial = function() {

		var interstitial = $("#interstitial");
		var css = {};
		css.top = $(window).scrollTop() + ($(window).height() - interstitial.height())/2;
		css.left = $(window).scrollLeft() + ($(window).width() - interstitial.width())/2;

		interstitial
		.css(css)
		;
	};

	var RemoveInterstitial = function() {
		$("#interstitial").hide(function(){
			var animate = {};
			animate.opacity = "0.0";
			$("#overlay")
			.animate(animate,500,function(){
				$("#overlay").remove();
				$("#interstitial").remove();
			});
		});
	};

	$(".exit_link")
	.click(function(e){

		e.preventDefault();

		var strHref = $(this).attr("href");

		var cssOverlay = {};
		cssOverlay.position = "fixed";
		cssOverlay.top = "0px";
		cssOverlay.left = "0px";
		cssOverlay.width = "100%";
		cssOverlay.height = "100%";
		cssOverlay.background = "#000000";
		cssOverlay.opacity = "0.0";
		cssOverlay.zIndex = "100";

		var animOverlay = {};
		animOverlay.opacity = "0.8";

		var cssInterstitial = {};
		cssInterstitial.width = "600px";
		cssInterstitial.position = "absolute";
		cssInterstitial.background = "#ffffff";
		cssInterstitial.padding = "20px";
		cssInterstitial.zIndex = "100";

		$("<div>")
		.attr("id","overlay")
		.css(cssOverlay)
		.appendTo("body")
		.animate(animOverlay,500,function(){

			var overlay = $(this);

			$("<div>")
			.hide()
			.attr("id","interstitial")
			.css(cssInterstitial)
			.load("/off-ramp.asp",function(){

				$(this)
				.find("#continue")
				.attr("href",strHref)
				.click(function(e){
					setTimeout(function(){ RemoveInterstitial(); },1);
				})
				;

				$(this)
				.find("#cancel")
				.click(function(e){
					e.preventDefault();
					RemoveInterstitial();
				})
				;

				CenterInterstitial();
				$(this).show();

			})
			.appendTo("body")
			;

		})
		.click(function(){
			RemoveInterstitial();
		})
		;

	});

});

