﻿var popupcommStatus = 0;

function loadpopupcomm(){
	if(popupcommStatus==0){
		$("#backgroundpopupcomm").css({
			"opacity": "0.7"
		});
		$("#backgroundpopupcomm").fadeIn("slow");
		$("#popupcommCart").fadeIn("slow");
		popupcommStatus = 1;
	}
}

function disablepopupcomm(){
	if(popupcommStatus==1){
		$("#backgroundpopupcomm").fadeOut("slow");
		$("#popupcommCart").fadeOut("slow");
		popupcommStatus = 0;
	}
}

function centerpopupcomm(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupcommHeight = $("#popupcommCart").height();
	var popupcommWidth = $("#popupcommCart").width();
	$("#popupcommCart").css({
		"position": "absolute",
		"top": windowHeight/2-popupcommHeight/2,
		"left": windowWidth/2-popupcommWidth/2
	});
	
	$("#backgroundpopupcomm").css({
		"height": windowHeight
	});
	
}

$(document).ready(function(){
	
	$("#buttoncomm").click(function(){
		centerpopupcomm();
		loadpopupcomm();
	});
	
	$("#popupcommCartClose").click(function(){
		disablepopupcomm();
	});
	$("#backgroundpopupcomm").click(function(){
		disablepopupcomm();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupcommStatus==1){
			disablepopupcomm();
		}
	});

});
