var popupStatus = 0;
function loadPopup(idpopup){
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery('#'+idpopup).fadeIn("slow");
		popupStatus = 1;
	}
}
function disablePopup(){
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery(".popup").fadeOut("slow");
		popupStatus = 0;
	}
}
function centerPopup(idpopup){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery('#'+idpopup).height();
	var popupWidth = jQuery('#'+idpopup).width();
	jQuery('#'+idpopup).css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

jQuery(document).ready(function(){
	jQuery('.share-popup').click(function(){
		var idpopup = (this.id).replace('a_','');
		centerPopup(idpopup);
		loadPopup(idpopup);
		jQuery(".close").click(function(){
			disablePopup();
		});
		jQuery("#backgroundPopup").click(function(){
			disablePopup();
		});
		jQuery(document).keypress(function(e){
			if(e.keyCode==27 && popupStatus==1){
				disablePopup();
			}
		});
	});
});
