var popupStatus = 0;
var popupid;

function loadPopup(){
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#"+popupid).fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#"+popupid).fadeOut("slow");
		popupStatus = 0;
	}
}

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

jQuery(document).ready(function(){
	jQuery("#popup_close").click(function(){
		disablePopup();
	});
	jQuery("#backgroundPopup").click(function(){
		disablePopup();
	});
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	jQuery("#popup_close2").click(function(){
		disablePopup2();
	});
	jQuery("#backgroundPopup2").click(function(){
		disablePopup2();
	});
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup2();
		}
	});
	
});

function loadPopup2(){
	if(popupStatus==0){
		jQuery("#backgroundPopup2").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup2").fadeIn("slow");
		jQuery("#"+popupid).fadeIn("slow");
		popupStatus = 1;
	}
}

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

function disablePopup2(){
	if(popupStatus==1){
		jQuery("#backgroundPopup2").fadeOut("slow");
		jQuery("#"+popupid).fadeOut("slow");
		popupStatus = 0;
	}
}


    //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");
    //});
