
function showPopup(popupId) {
	// add background div if not found
	if ($("#backgroundPopup").length == 0) {
        var backgroundPopup = document.createElement('div');
        backgroundPopup.setAttribute("id", "backgroundPopup");
        backgroundPopup.id = "backgroundPopup";
        document.body.appendChild(backgroundPopup);
	}
	
	$("#backgroundPopup").unbind('click')
	$("#backgroundPopup").click(function() {
		hidePopup(popupId);
	});
    
	centerPopup(popupId);
	$("#backgroundPopup").css({
		"opacity": "0.7"
	});
	$("#backgroundPopup").fadeIn(350);
	
	$("#"+popupId).css({
		"z-index": "10"
	});
	$("#"+popupId).fadeIn(350);
}

function showSwf() {
	jQuery('body').find('embed').each(
		function(index) {
			$(this).css('visibility','visible');
		}
	);
	jQuery('body').find('object').each(
		function(index) {
			$(this).css('visibility','visible');
		}
	);
}

function hideSwf() {
	jQuery('body').find('embed').each(
		function(index) {
			$(this).css('visibility','hidden');
		}
	);
	jQuery('body').find('object').each(
		function(index) {
			$(this).css('visibility','hidden');
		}
	);
}

function hidePopup(popupId) {
	$("#backgroundPopup").fadeOut(350);
	$("#"+popupId).fadeOut(350);
	// TODO: implement workaround to avoid hiding swf showSwf();
}

function centerPopup(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
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}