﻿

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var popupFTStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#mailRequestDiv").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#mailRequestDiv").fadeOut("slow");
		popupStatus = 0;
	}
}
//loading popup with jQuery magic!
function loadFTPopup(){
	//loads popup only if it is disabled
	if(popupFTStatus==0){
		$("#backgroundFTPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundFTPopup").fadeIn("slow");
		$("#firstTimeDiv").fadeIn("slow");
		popupFTStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disableFTPopup(){
	//disables popup only if it is enabled
	if(popupFTStatus==1){
		$("#backgroundFTPopup").fadeOut("slow");
		$("#firstTimeDiv").fadeOut("slow");
		popupFTStatus = 0;
	}
}

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 ];
}

//centering popup
function centerPopup(){
	//alert(getScrollXY());
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#mailRequestDiv").height();
	var popupWidth = $("#mailRequestDiv").width();
	//centering
	$("#mailRequestDiv").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+getScrollXY()[1] ,
		"left": windowWidth/2-popupWidth/2+getScrollXY()[0]
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": '2000px'
	});
	
}

function centerFTPopup(){
	//alert(getScrollXY());
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#firstTimeDiv").height();
	var popupWidth = $("#firstTimeDiv").width();
	var top = windowHeight/2-popupHeight/2+getScrollXY()[1];
	if (top < 0) {
		top = 0;
	}
	//centering
	$("#firstTimeDiv").css({
		"position": "absolute",
		"top": top ,
		"left": windowWidth/2-popupWidth/2+getScrollXY()[0]
	});
	//only need force for IE6
	
	$("#backgroundFTPopup").css({
		"height": '2000px'
	});
	
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupFirstTimeClose").click(function(){
		disableFTPopup();
	});
	
	//Click out event!
	//$("#backgroundPopup").click(function(){
	//	disablePopup();
	//});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disableFTPopup();
		}
	});

});
