/**********************************************************************/
/* Original code from Adrian "yEnS" Mato Gondelle, www.yensdesign.com */
/* Modified by megaphone internet www.megaphone.ch                    */
/**********************************************************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

// load the popup
function loadPopup()
{
	//loads popup only if it is disabled
	if(popupStatus==0)
	{
		// background opacity
		$j("#popupBackground").css({"opacity": "0.9"});
		// no fading for background
		$j("#popupBackground").show();
		// slow fading for the pop up
		$j("#popupContent").fadeIn("slow");
		// the popup is open
		popupStatus = 1;
	}
}

//disabling popup 
function disablePopup()
{
	//disables popup only if it is enabled
	if(popupStatus==1)
	{
		// slow fading for the popup
		$j("#popupContent").hide();
		// no fading for the background
		$j("#popupBackground").fadeOut("slow");
		// the popup is close
		popupStatus = 0;
	}
}

// Vertical scrolling position
// http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}


//centering popup
function centerPopup()
{
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupWidth = $j("#popupContent").width();
	var popupHeight = $j("#popupContent").height();
	//centering
	$j("#popupContent").css({
		"position": "absolute",
		"top": f_scrollTop()+windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$j("#popupBackground").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$j(document).ready(function()
{
	//CLOSING POPUP
	//Click the x event!
	$j("#popupContentClose").click(function(){
		disablePopup();
        return false;
	});
	//Click out event!
	$j("#popupBackground").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$j(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

