﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;

ModalPopup = {
	
	popupStatus: 0,
	currentPopupId: null,
	
	show: function(popupId) {
		ModalPopup.centerPopup(popupId);
		ModalPopup.loadPopup(popupId);
	},
	
	
	hide: function() {
		//disables popup only if it is enabled
		if(ModalPopup.currentPopupId){
			$("#modalpopup_Background").fadeOut("medium");
			$("#" + ModalPopup.currentPopupId).fadeOut("medium");
			ModalPopupcurrentPopupId = null;
		}
	},

	//centering popup
	centerPopup: function(popupId){
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#" + popupId).height();
		var popupWidth = $("#" + popupId).width();
		
		//centering
		$("#" + popupId).css({
			//"position": "fixed",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		
		$("#modalpopup_Background").css({
			"height": windowHeight
		});
	},
	
	loadPopup: function(popupId){
		//loads popup only if it is disabled
		if(ModalPopup.popupStatus==0){
			$("#modalpopup_Background").css({
				"opacity": "0.7"
			});
			$("#modalpopup_Background").fadeIn("medium");
			$("#modalpopup_Background").click(function(){ ModalPopup.hide(); });
			$("#" + popupId).fadeIn("medium");
			ModalPopup.currentPopupId = popupId;
		}
	}
}

$('body').append('<div id="modalpopup_Background"></div>');
