var popupStatus = 0;
var pupup_id;
function loadPopup(id){
	popup_id=id;
	centerPopup();
	if(popupStatus==0){
		jQuery("#popup_bg").css({
			"opacity": "0.7"
		});
		jQuery("#popup_bg").fadeIn();
		jQuery("#"+popup_id).fadeIn();
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		jQuery("#popup_bg").fadeOut();
		jQuery("#"+popup_id).fadeOut();
		popupStatus = 0;
	}
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#"+popup_id).height();
	var popupWidth = jQuery("#"+popup_id).width();
        //alert(windowWidth/2-popupWidth/2);
    from_top = jQuery(window).scrollTop();
	jQuery("#"+popup_id).css({
		"position": "absolute",
		"top": from_top + windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	jQuery("#popup_bg").css({
		"height": windowHeight
	});
}

jQuery(document).ready(function(){
	jQuery(".popup_close").click(function(){
		disablePopup();
	});
	jQuery("#popup_bg").click(function(){
		disablePopup();
	});
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});
    //jQuery(window).scroll(function () {
	   // from_top = jQuery(window).scrollTop();
       // var windowHeight = document.documentElement.clientHeight;
	   // var popupHeight = jQuery("#popup_preview").height();
        //jQuery("#popup_preview").css("top", from_top + (windowHeight/2-popupHeight/2) + "px");
    //});
