

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

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.650"
		});
		$("#backgroundPopup").fadeIn("fast", fadeIn_timeout('#popupWindow', 400, "fast"));
		//$("#backgroundPopup").fadeIn("slow");
		//$("#popupWindow").fadeIn("slow");
		popupStatus = 1;
		
	}
}
var isSex = false;
function loadPopupSex(){
	//loads popup only if it is disabled
	
	var isSex = true
	
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.95"
		});
		$("#popupWindowClose").css({
			"visibility": "hidden"
		});
		
		$("#backgroundPopup").fadeIn("fast", fadeIn_timeout('#popupWindow', 400, "fast"));
		//$("#backgroundPopup").fadeIn();
		//$("#popupWindow").fadeIn();
		popupStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupWindow").fadeOut("fast", fadeOut_timeout('#backgroundPopup', 400, "fast"));
		//$("#backgroundPopup").fadeOut("slow");
		//$("#popupWindow").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	
	var scrollDim = getScrollXY();
	var widthPlus =scrollDim[0];
	var heightPlus =scrollDim[1];
	//alert (scrollDim);	
	
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupWindow").height();
	var popupWidth = $("#popupWindow").width();
	

	//centering
	$("#popupWindow").css({
		"position": "absolute",
		"_position": "relative",
		"top": (windowHeight/2-popupHeight/2) + heightPlus,
		"left": (windowWidth/2-popupWidth/2) + widthPlus
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


function popupWin(Pop_w, Pop_h, popTitle, PopSource) {
	
	$(document).ready(function(){
		
		$("#popupWindow").css({'width' : Pop_w});
		$("#popupWindow").css({'height' : Pop_h});
		
		$("#popupWindow .nadpis").html(popTitle);
		$("#popupWindow #popupArea").html(PopSource);

	});
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".popup").click(function(){
									 
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	if(isSex=false){
		//CLOSING POPUP
		//Click the x event!
		$("#popupWindowClose").click(function(){
			disablePopup();
		});
		//Click out event!
		$("#backgroundPopup").click(function(){
			disablePopup();
		});
		//Press Escape event!
		$(document).keypress(function(e){
			if(e.keyCode==27 && popupStatus==1){
				disablePopup();
			}
		});
	}

});	


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


