// JavaScript Document
//Requires JQUERY

$(window).resize(function() {
  resizeWin();
});


function displayPopup(content){
	if ($("#frame").length == 0){
		$('body').append('<div id="frame"><div id="closeButton"><a href="javascript:closePop();"><img src="assets/images/misc/closebox.png" width="30" height="30" alt="Close" /></a></div><div class="first"><span class="first"></span><span class="last"></span></div><div id="frameContent"></div><div class="last"><span class="first"></span><span class="last"></span></div></div><a href="javascript:closePop();" id="coverLink"><div id="cover" class="blackout"> </div></a>');
		if(content == null){
			content = "";	
		}
	
		$("#frameContent").html(content);
		
		$("#cover").width($(window).width()).height($(window).height());
		$("#cover").show();
		
		centerDiv("frame");
	}
	
	
}

function centerDiv(myDiv){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+myDiv).height();
	var popupWidth = $("#"+myDiv).width();
	var popupLeft = windowWidth/2-popupWidth/2;
	if(popupLeft<0){ popupLeft = 0; }
	//centering
	$("#"+myDiv).css({
		"position": "absolute",
		"left": popupLeft
	});
	
}

function resizeWin(){
	if ($("#frame").length > 0){
		centerDiv("frame");
		$("#cover").width($(window).width()).height($(window).height());
	}
}
  
function closePop(){
	$("#frame").remove();
	$("#cover").remove();
	$("#coverLink").remove();
}