﻿var popupStatus = 0;
var popupID = '';
function loadPopup(pID) {
    popupID = pID;
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#" + popupID).fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#" + popupID).fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(pID) {
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#" + pID).height();
	var popupWidth = $("#" + pID).width();
	//centering
	$("#" + pID).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
$(document).ready(function () {
    $("#login").hide();
    initPopup();
});

function initPopup() {
    centerPopup('login');
     $("#loginLnk").click(function() {
	    centerPopup('login');
	    loadPopup('login');
    });
	
	$(".closePopup").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
