//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var popupInstructionStatus = 0;
var popupMomsSayStatus = 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");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadInstructionPopup(){
	//loads popup only if it is disabled
	if(popupInstructionStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupInstructions").fadeIn("slow");
		popupInstructionStatus = 1;
	}
}

function loadMomsSayPopup(){
	//loads popup only if it is disabled
	if(popupMomsSayStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupMomsSay").fadeIn("slow");
		popupMomsSayStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

function disableInstructionPopup(){
	//disables popup only if it is enabled
	if(popupInstructionStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupInstructions").fadeOut("slow");
		popupInstructionStatus = 0;
	}
}

function disableMomsSayPopup(){
	//disables popup only if it is enabled
	if(popupMomsSayStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupMomsSay").fadeOut("slow");
		popupMomsSayStatus = 0;
	}
}


//centering popup
function centerPopup(){
	//request data for centering	
var windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
var windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
var scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
var scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
var pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
var pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;

windowHeight=windowY + scrollY;
windowWidth=windowX + scrollX;

	var backHeight = window.top.document.body.scrollHeight;
	//if (windowHeight > backHeight)
		//backHeight = windowHeight;

	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();

	var popupInstrHeight = $("#popupInstructions").height();
	var popupInstrWidth = $("#popupInstructions").width();

	var popupMomsSayHeight = $("#popupMomsSay").height();
	var popupMomsSayWidth = $("#popupMomsSay").width();
	

	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2-14,
		"left": windowWidth/2-popupWidth/2
	});

	$("#popupInstructions").css({
		"position": "absolute",
		"top": windowHeight/2-popupInstrHeight/2-14,
		"left": windowWidth/2-popupInstrWidth/2
	});

	$("#popupMomsSay").css({
		"position": "absolute",
		"top": windowHeight/2-popupMomsSayHeight/2-14,
		"left": windowWidth/2-popupMomsSayWidth/2
	});


	//only need force for IE6
	
		//"height": window.top.document.body.scrollHeight,
		//"width": windowWidth

	$("#backgroundPopup").css({
		"height": backHeight,
		"width": windowWidth
	});
	
}




//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#largebutton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				

	$("#instructionsbutton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadInstructionPopup();
	});

	$("#wmasbutton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadMomsSayPopup();
	});


	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});

	$("#popupInstructionsClose").click(function(){
		disableInstructionPopup();
	});

	$("#popupMomsSayClose").click(function(){
		disableMomsSayPopup();
	});


	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
		disableInstructionPopup();
		disableMomsSayPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disableInstructionPopup();
			disableMomsSayPopup();
		}
	});

});
