/*
 * Dokument:       Funkce pro zobrazeni popup okna.
 * Posledni zmena: 08.01.2010
 *
 * Vstupni data:
 */

var popupActive = ""; // prave aktivni okno

function loadPopup(id)
{
	if(popupActive == "")
  {
    popupActive = id;

		$("#popupBackground").css({
			"opacity": "0.7"
		});
		$("#popupBackground").fadeIn("slow");
		$(popupActive).fadeIn("slow");
	}
}
function disablePopup()
{
	if(popupActive != "")
  {
		$("#popupBackground").fadeOut("slow");
		$(popupActive).fadeOut("slow");
		popupActive = "";
	}
}
function centerPopup(id)
{
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(id).height();
	var popupWidth = $(id).width();
	//centering
	$(id).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#popupBackground").css({
		"height": windowHeight
	});
}

function popupHide()
{
  disablePopup();
  return false;
}
function popupShow(id)
{
  centerPopup("#" + id);
  loadPopup("#" + id);
  return false;
}

$(document).ready(function(){

	//Click out event!
	$("#popupBackground").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode == 27 && popupActive != ""){
			disablePopup();
		}
	});

});