﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var popupDiv;
var currentPopup;

//loading popup
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(popupDiv).fadeIn("slow");
		popupStatus = 1;
		currentPopup = popupDiv;
	}
}

//disabling popup
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(popupDiv).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(popupDiv){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(popupDiv).height();
	var popupWidth = $(popupDiv).width();
	//centering
	$(popupDiv).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//****** Start Repeat Section ******//
	//LOADING POPUP
    $("#TermsPop").click(function() {       //<----Trigger event
		//Setting popupDiv name
		popupDiv = "#popupTerms";       //<----Popup Section Div Name
		//centering with css
		centerPopup(popupDiv);
		//load popup
		loadPopup(popupDiv);
	});
	//CLOSING POPUP
	$("#popupTermsClose").click(function(){       //<----Click the x event!
		disablePopup(currentPopup);
	});
	//CLICK OUT EVENT
	$("#backgroundPopup").click(function(){
		disablePopup(currentPopup);
	});
	//****** End Repeat Section ******//
	//****** Start Repeat Section ******//
	//LOADING POPUP
	$("#PrivacyPop").click(function() {       //<----Trigger event
		//Setting popupDiv name
		popupDiv = "#popupPrivacy";       //<----Popup Section Div Name
		//centering with css
		centerPopup(popupDiv);
		//load popup
		loadPopup(popupDiv);
	});
	//CLOSING POPUP
	$("#popupPrivacyClose").click(function(){       //<----Click the x event!
		disablePopup(currentPopup);
	});
	//CLICK OUT EVENT
	$("#backgroundPopup").click(function(){
		disablePopup(currentPopup);
	});
	//****** End Repeat Section ******//
	
	
	//PRESS ESCAPE EVENT.  You only need one of these.
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
		  disablePopup(currentPopup);
		}
	});

});