$(document).ready(function() {
	var pathname = window.location.pathname;
	//next condition is to avoid javascript error in case element do not exist.
	if($("#popup") != null)
	setPosition();
	
	if(pathname.indexOf("showcase.jsp") != -1 || pathname.indexOf("/searchsite/") != -1 || pathname.indexOf("licensed_products.jsp") != -1 || pathname.indexOf("home.jsp") != -1 || pathname == "/"){
 		//showPopup();
	}
});

function setPosition() {
	var popupW = parseInt($("#popup").css("width"));
	var popupH = parseInt($("#popup").css("height"));
	var stageH = parseInt($(document).height());
	var stageW = parseInt($(document).width());
	
	var top = (stageH - popupH) / 4;
	var left = (stageW - popupW) / 2;
	
	$("#popup").css({'top': top, 'left': left});
	$("#content-blocker").css({'height': stageH});
}

function restartPosition() {
	$("#popup").css({'top': 0, 'left': 0});
}

function showPopup(){
	$("#content-blocker").css("display","block");
	$("#popup").show(400);
	
	$(".popup-cta").click(function() {
		$("#popup").hide(400);
		$("#content-blocker").css("display","none");
	});
	
	$(".popup-close").click(function() {
		$("#popup-text-content").html("Once you’ve completed your visit to the GM Performance Parts site, please return to take the survey and share your experience. Just click the yellow icon in the navigation bar to get started. Thanks again for helping us improve our site and better meet your needs.");
		$(this).removeClass("popup-close").addClass("popup-close-survey");
		
		$(".popup-close-survey").click(function() {
			$("#popup").hide(400);
			$("#content-blocker").css("display","none");
		});
	});
}

