﻿/*
HELP WINDOW POPUPS
 - The Content should come from an include residing in the DIR where the calling page resides
 -  The MAIN DIV for the content should have:
	- a ClassName of 'helpButton'
 	- an ID which is the same as the TITLE of the trigger link
 	ie: Trigger link:
	<img class="helpButton" title="genericHelp" src="/img/icn_help.gif" height="16" width="16" />

	and the Main Content DIV for the Help Popup:
	<div id="performanceHelp" class="popupWindow"> 

The JS for the pop-up is included by the default_fam layout, as is the background cover DIV
*/
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
//The title of the trigger will set this var, and be referenced to determine which helpPopup to display
var whichPopup = null;

function loadPopup(e){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#previewCurtain").css({
			"opacity": "0.7"
		});
		$("#previewCurtain").fadeIn("fast");
		$("#previewCurtain").css("width",document.documentElement.clientWidth);
		$("#popupContent").fadeIn("slow");
		popupStatus = 1;
		$("embed").css("visibility","hidden");
		$("object").css("visibility","hidden");
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#previewCurtain").fadeOut("fast");
		$("#popupContent").fadeOut("fast");
		popupStatus = 0;
		$("embed").css("visibility","");
		$("object").css("visibility","");
	}
}

//centering popup
function centerPopup(e){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = $('#home').height();
	var popupHeight = $("#popupContent").height();
	var popupWidth = $("#popupContent").width();
	//centering
	$("#popupContent").css({
		"position": "absolute",
		//Actually, let's not center vertically
		//"top": windowHeight/2-popupHeight/2,
		
		//Instead, we go with where the click was
		"top" : 200,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#previewCurtain").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".showPopup").click(function(e){
		//centering with css
		centerPopup(e);
		//load popup
		loadPopup(e);
		return false;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#previewCurtain").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
