var leavingBox = {
	data:{
		url:''
	},
	popup_leaving:function(){  
		$("#backgroundPopup").fadeIn('slow');
		$("#lightbox").fadeIn('slow');
		var posY = (($(window).height() - $("#lightbox").outerHeight()) /2) + $(window).scrollTop();
		var posX = (($(window).width() - $("#lightbox").outerWidth()) /2) + $(window).scrollLeft();
		$("#lightbox").css("top",posY+'px').css("left",posX+'px');
	}
}

$(document).ready(function(){ 
	

	    $(".interstitial_replace").click(function(event){ 


		    event.preventDefault();
		    leavingBox.data.url = $(this).attr("href");
    		
		    if(leavingBox.data.url.indexOf("urlvar") > 0)
		    {
		        leavingBox.data.url = leavingBox.data.url.slice(leavingBox.data.url.indexOf("urlvar")+7);
		    }
    		
    		
		    leavingBox.popup_leaving();
	    })
	$("#backgroundPopup, #popup-closebtn, .btn").click(function(){
		$("#backgroundPopup").hide();
		$("#lightbox").hide();
		if($(this).attr("id")=='ok-btn'){window.open(leavingBox.data.url);}
	});
});

