﻿var popupStatus = 0;
var currentDiv = "#gallery";

function loadPopup(mydiv){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.5"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#close").fadeIn("slow");
		$(mydiv).fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#close").fadeOut("slow");
		$("#backgroundPopup").fadeOut("slow");
		$(currentDiv).fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(myDiv){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(myDiv).height();
	var popupWidth = $(myDiv).width();
	$(myDiv).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}

$(document).ready(function(){
$("#galleryTrigger").click(function(){
	loadPopup(currentDiv);
});
$("#galleryTrigger2").click(function(){
	loadPopup(currentDiv);
});
$("#backgroundPopup").click(function(){
	disablePopup();
});
$("#close").click(function(){
	disablePopup();
});
$(document).keypress(function(e){
	if(e.keyCode==27 && popupStatus==1){
	disablePopup();
	}
});
						   });