/**
 * This is an overlay that will pop up and grey out the rest of the page on document ready (page load)
 * 
 * 
 */

$(function(){
	
	if (overlayOn) { // Only serve Overlay if cookie is not set
		
		setCookie('cc_overlay','true', 1);
		
		$('#screen').css({  "display": "block", opacity: 0.7, "width":$(document).width(),"height":$(document).height()});
		$('#pop_obj').css({"display": "block"});
		//$('#stay_here').css("display", "block");
		
		var redirect = true;
		
		//$('#stay_here').click(function(){
		$('#pop_obj').click(function(){
			$("#pop_obj").css("display", "none");
			$('#screen').css("display", "none");
			//$('#stay_here').css("display", "none");
			redirect = false;
		});
	}	
	
	// Add image to overlay div
	$('#pop_obj').attr('src', cmsOverlayGraphic);

	// Click Tracking
    $('#pop_obj').click(function() {
    	autoLinkTrackEvent('overlay_redirect_skipped', window.location.href);
    });
	
	$(window).resize(function(){
		$('#pop_obj').css("display") == 'block'?$("#screen").css("width", "100%"):"";
	});

	setTimeout(function() {
		//Redirect after cmsOverlayTimer seconds
		if (redirect) {
			autoLinkTrackEvent('overlay_redirected', cmsOverlayRedirect);
			window.location.href = cmsOverlayRedirect;
		}
	}, cmsOverlayTimer);		
});


