var popupStatus = 0;

$(document).ready(function() {

    
    $('.hcp-link').click(function(event) {

		 event.preventDefault();
		var thislink = $(this).attr("href"); //Gets href attribute of the link that the user clicked on
		var docScrollTop = $(document).scrollTop(); //Gets Scroll position
		
        loadPopup(docScrollTop, thislink);  //Calling Loading Popup Function
       
    });

	//User stays on current page
    $("#hcp-no").click(function(event) {

        event.preventDefault();
        disablePopup();
        
    });    

});  

//loading popup
function loadPopup(docScrollTop, thislink) {

	var winH = $(window).height();  
	var winW = $(window).width();
	
	//Determine positioning based on user scrolling
	$('#popupHCP').css('top',  (winH/2-$('#popupHCP').height()/2) + docScrollTop);
	$('#popupHCP').css('left', winW/2-$('#popupHCP').width()/2);

	$(window).resize(function() {

		var newwinW = $(window).width();
		$('#popupHCP').css('left', newwinW/2-$('#popupHCP').width()/2); 

	});

	if(popupStatus==0)
	{

		$("#popupHCP").fadeIn("slow");
		popupStatus = 1;

	}

	//Allows User to Move to External Web Site
	$("#hcp-yes").click(function() { 

        $(this).attr("href", thislink);
		 disablePopup();
    }); 

}

//disables popup 
function disablePopup()
{
	if(popupStatus==1) 
	{   
		$("#popupHCP").fadeOut("slow");
		popupStatus = 0;
	}   
}


