/*------------------------------------------------------------------
This function creates a new popup
------------------------------------------------------------------*/
function createPopup_JD(params){
	/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	Avalible params --------------------------------------
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	REQUIRED
	- popupID 	(The ID of the main containing div)
	
	OPTIONAL
	- APIdir	(The directory in which the popup images and styles can be found | defaults as "")
	- type 		(The type of popup - "info", "alert", "critical", "success", "failure", "confirm", "wait" | defaults as "info")
	- width 	(width in px, set to 0 for auto | defaults as 0)
	- height 	(height in px, set to 0 for auto | defaults as 0)
	- title 	(title of the popup | defaults as "")
	- content 	(the main content of the popup | defaults as "")
	_______________________________________________________
	_______________________________________________________*/
	
	if(params.popupID == undefined){alert("JD System Design Popup API Error!  No object ID has been defined");return;}
	
	var popupID = params.popupID || "";
	var APIdir = params.APIdir || "";
	var type = params.type || "info";
	var desiredWidth = params.width || 0;
	var desiredHeight = params.height || 0;
	var title = params.title || "";
	var content = params.content || "";
			
	if(popupID.length == 0){alert("JD System Design Popup API Error! You must enter a popupID");return;}
	if (document.getElementById(popupID)){alert("JD System Design Popup API Error!  A popup already has the ID '"+popupID+"'");return;}				 
	
	if(desiredWidth == 0){desiredWidth = "";}else{desiredWidth+="px";}
	if(desiredHeight == 0){desiredHeight = "";}else{desiredHeight+="px";}
	
	if(type == "info"){var headerImage="info.png";var wrapperClass="infoType";}
	if(type == "alert"){var headerImage="alert.png";var wrapperClass="alertType";}
	if(type == "critical"){var headerImage="critical.png";var wrapperClass="criticalType";}
	if(type == "success"){var headerImage="success.png";var wrapperClass="successType";}
	if(type == "failure"){var headerImage="failure.png";var wrapperClass="failureType";}
	if(type == "confirm"){var headerImage="confirm.png";var wrapperClass="confirmType";}
	if(type == "wait"){var headerImage="loading.gif";var wrapperClass="waitType";}
	
	//Create popup Wrapper
	var popupWrapper = document.createElement("div");
		popupWrapper.id = popupID;
		popupWrapper.className = "popupContainer "+wrapperClass;
		popupWrapper.style.width = desiredWidth;
		popupWrapper.style.height = desiredHeight;
		popupWrapper.style.display = "none";
		popupWrapper.style.backgroundImage = 'url('+APIdir+'_images/background.gif)';
	document.body.appendChild(popupWrapper);
	
	//Create Close Button
	if(type != "wait"){
		var popupButton = document.createElement("a");
			popupButton.className = "popupButton";
			popupButton.setAttribute('href','javascript:closePopup_auto_JD(\''+popupID+'\');');
			popupButton.innerHTML = '<img id="'+popupID+'Button" src="'+APIdir+'_images/close.png" width="32" height="32" class="closeButton" />';
		document.getElementById(popupID).appendChild(popupButton);
	}else{
		var popupButton = document.createElement("div");
			popupButton.id = popupID+'Button';
		document.getElementById(popupID).appendChild(popupButton);
	}
	
	//Create Popup Header
	var popupHeader = document.createElement("div");
		popupHeader.id = popupID + "Header";
		popupHeader.className = "popupHeader";
		popupHeader.innerHTML = '<img src="'+APIdir+'_images/'+headerImage+'" width="32" height="32" alt="Popup Header Image" /><span>'+title+'</span>';
	document.getElementById(popupID).appendChild(popupHeader);
	
	//Create Popup Content
	var popupContent= document.createElement("div");
		popupContent.id = popupID + "Content";
		popupContent.className = "popupContent";
		popupContent.innerHTML = content;
	document.getElementById(popupID).appendChild(popupContent);
	
	if(type != "wait"){
		var popupFooter= document.createElement("div");
			popupFooter.id = popupID + "Footer";
			popupFooter.className = "popupFooter";
			popupFooter.innerHTML = '<a id="'+popupID+'Close" href="javascript:closePopup_auto_JD(\''+popupID+'\');">Close</a>';
		document.getElementById(popupID).appendChild(popupFooter);	
	}else{
		var popupFooter= document.createElement("div");
			popupFooter.id = popupID + "Close";
		document.getElementById(popupID).appendChild(popupFooter);		
	}
}


/*------------------------------------------------------------------
This function eturns the height for the blanket to use
------------------------------------------------------------------*/
function getBlanketHeight(){
	var height = 0;
	if (typeof window.innerWidth != 'undefined') {viewportheight = window.innerHeight;} 
	else {viewportheight = document.documentElement.clientHeight;}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)){height=viewportheight;}
	else{if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight){height = document.body.parentNode.clientHeight;}
	else{height = document.body.parentNode.scrollHeight;}}
	return height;
}

/*------------------------------------------------------------------
This function returns the window width
------------------------------------------------------------------*/
function windowWidth_JD() {
	return filterResults_JD (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function windowHeight_JD() {
	var viewportheight;
 	if (typeof window.innerWidth != 'undefined'){
      	viewportheight = window.innerHeight
 	}else if (typeof document.documentElement != 'undefined' 
	&& typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0){
       viewportheight = document.documentElement.clientHeight
 	}else{
       	viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return viewportheight;
}

function scrollLeft_JD() {
	return filterResults_JD (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function scrollTop_JD() {
	return filterResults_JD (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filterResults_JD(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

/*------------------------------------------------------------------
This function toggles the display of an object
------------------------------------------------------------------*/
function toggle(object){
	if(document.getElementById(object).style.display == "none"){
		document.getElementById(object).style.display = "block";
	}else{
		document.getElementById(object).style.display = "none";
	}
}

function hideBlanket(){document.getElementById('blanket').style.display = "none";}
function openBlanket(){document.getElementById('blanket').style.display = "block";}

function doAfterOpen_JD(popupID){
	eval(afterOpen[popupID]);
	if(openFocus[popupID].length >0){document.getElementById(openFocus[popupID]).focus();}
}

/*
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-------------------------------------------------------------------------------------------------
START OF POPUP OPEN EFFECTS
-------------------------------------------------------------------------------------------------
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*/
var afterOpen = new Array();
var openFocus = new Array();
var closeEffect = new Array();
var closeFocus = new Array();
var closeAction = new Array();
var closeDestroy = new Array();
var closeBlanket = new Array();
/*------------------------------------------------------------------
This function opens a popup
------------------------------------------------------------------*/
function openPopup_JD(params){
	/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	Avalible params --------------------------------------
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	REQUIRED
	- popupID 		(The ID of the main containing div)
	
	OPTIONAL
	- posX			("middle", "left", "right"| Default is "middle")
	- posY			("middle", "top", "bottom"| Default is "middle")
	- effect		(The effect of the opening transition)
	- openFocus		(What should the focus be set to?)
	- openBlanket	(Should the blanket be toggled? | Default is true)
	- afterOpen		(a function to be called after open)
	- closeEffect	(the close effect to be used | Default is "fade")
	- closeFocus	(the item to be focussed on after close)
	- closeAction	(a function to the called after close)
	- closeDestroy	(should the popup be destroyed when closed | default is true)
	- closeBlanket	(should the blanket be closed when the window is?)
	_______________________________________________________
	_______________________________________________________*/
	
	var popupID = params.popupID;
	var positionX = params.posX || "middle";
	var positionY = params.posY || "middle";
	var blanket = params.openBlanket  || "true";
	var effect = params.effect || "fade";
	openFocus[popupID] = params.openFocus  || popupID+"Close";
	afterOpen[popupID] = params.afterOpen  || "";
	closeEffect[popupID] = params.closeEffect || "fade";
	closeFocus[popupID] = params.closeFocus || "";
	closeAction[popupID] = params.closeAction || "";
	closeDestroy[popupID] = params.closeDestroy || "true";
	closeBlanket[popupID] = params.closeBlanket  || "true";
				
	document.getElementById(popupID).style.display="block";
	var width = document.getElementById(popupID).offsetWidth+"";
	var height = document.getElementById(popupID).offsetHeight+"";
	document.getElementById(popupID).style.display="none";
	
	width = width * 1;
	height = height * 1;

	var windowWidth = windowWidth_JD();
	var windowHeight = windowHeight_JD();
	var scrollLeft = scrollLeft_JD();
	var scrollTop = scrollTop_JD();
	
	switch(positionX){
		case "middle":
			var windowLeft = windowWidth/2 - width/2 + scrollLeft;
			if(windowLeft < scrollLeft){windowLeft = scrollLeft+15;}
			break;
		case "left":
			var windowLeft = 60 + scrollLeft;
			break;
		case "right":
			var windowLeft = windowWidth-width-60 + scrollLeft;
			break;			
	}
	
	switch(positionY){
		case "middle":
			var windowTop = windowHeight/2 - height/2+scrollTop;
			if(windowTop < scrollTop){windowTop = scrollTop+15;}
			break;
		case "top":
			var windowTop = 60 + scrollTop;
			break;
		case "bottom":
			var windowTop = windowHeight-height-60+scrollTop;
			break;			
	}
	
	document.getElementById(popupID).style.left = windowLeft + "px";
	document.getElementById(popupID).style.top = windowTop + "px";
	
	if(!document.getElementById('blanket')){
		var popupBlanket = document.createElement("div");
		popupBlanket.id = 'blanket';
		popupBlanket.style.display = "none";
		document.body.appendChild(popupBlanket);
	 }

 	document.getElementById('blanket').style.height = getBlanketHeight()+"px"; 
	
	if(blanket == "true"){
		animate_JD({
			objects: 	'blanket',	
			properties: "opacity",
			start: 		"0",
			end: 		"0.85",
			inerval: 	"20",
			frames: 	"15",
			effect:		"SFS",
			wait:		"0",
			onStart: 	"openBlanket()"
		})
	}
	
	switch(effect){
		
		//-----------------------------------
		//FADE IN
		//-----------------------------------
		case "fade":
				animate_JD({
					objects: 	''+popupID,	
					properties: "opacity",
					start: 		"0",
					end: 		"1",
					interval: 	"20",
					frames: 	"6",
					effect:		"SFS",
					wait:		"0",
					onStart:    "toggle('"+popupID+"')",
					onComplete:	"doAfterOpen_JD(\""+popupID+"\")"
				});	
		break;
		
		
		//-----------------------------------
		//FADE IN AND APPEAR FROM LEFT OR RIGHT
		//-----------------------------------
		case "fromLeft":
		case "fromRight":		
			var endPos = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			if(effect == "fromLeft"){
				var startPos = endPos - 200;
			}else{
				var startPos = (endPos*1) + 200;
			}
	
			animate_JD({
					objects: 	popupID+'		|'+popupID,	
					properties: "opacity	|left",
					start: 		"0			|"+startPos,
					end: 		"1			|"+endPos,
					extension:	"			|px",
					interval: 	"20			|20",
					frames: 	"7			|8",
					effect:		"SFS",
					wait:		"0			|-1",
					onStart:    "			|toggle('"+popupID+"')",
					onComplete:	"			|doAfterOpen_JD(\""+popupID+"\")"
				});	
		break;
		
		//-----------------------------------
		//FADE IN AND APPEAR FROM TOP OR BOTTOM
		//-----------------------------------
		case "fromTop":
		case "fromBottom":
			var endPos = (document.getElementById(popupID).style.top).substring(0,(document.getElementById(popupID).style.top).length-2);
			if(effect == "fromTop"){
				var startPos = endPos - 200;
			}else{
				var startPos = (endPos*1) + 200;
			}
	
			animate_JD({
					objects: 	popupID+'		|'+popupID,	
					properties: "opacity	|top",
					start: 		"0			|"+startPos,
					end: 		"1			|"+endPos,
					extension:	"			|px",
					interval: 	"20			|20",
					frames: 	"7			|8",
					effect:		"SFS",
					wait:		"0			|-1",
					onStart:    "			|toggle('"+popupID+"')",
					onComplete:	"			|doAfterOpen_JD(\""+popupID+"\")"
				});	
		break;
		
		//-----------------------------------
		//FADE IN AND EXPAND VERTICALLY
		//-----------------------------------
		case "verticalExpand":
			document.getElementById(popupID).style.display = "block";
			var endHeight = document.getElementById(popupID).offsetHeight;
			document.getElementById(popupID).style.display = "none";
			document.getElementById(popupID).style.height="50px";
			document.getElementById(popupID+'Content').style.display = "none";
			
			animate_JD({
					objects: 	popupID+'				|'+popupID+'		|'+popupID+'Content',	
					properties: "opacity			|height			|opacity",
					start: 		"0					|50				|0",
					end: 		"1					|"+endHeight+"	|1",
					extension:	"					|px				|",
					interval: 	"40					|20				|40",
					frames: 	"6					|10				|6",
					effect:		"SFS",
					wait:		"0					|0				|0",
					onStart:    "toggle('"+popupID+"')	|				|document.getElementById('"+popupID+"Content').style.display = 'block';",
					onComplete:	"					|				|doAfterOpen_JD(\""+popupID+"\")"
					
				});	
		break;
		
		
		//-----------------------------------
		//FADE IN AND EXPAND HORIZONTALLY
		//-----------------------------------
		case "horizontalExpand":
			document.getElementById(popupID).style.display = "block";
			var endWidth = document.getElementById(popupID).offsetWidth;
			document.getElementById(popupID).style.display = "none";
			var endLeft = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			var startLeft = (endLeft*1) + (endWidth / 2);
			
			document.getElementById(popupID).style.width="0px";
			document.getElementById(popupID+'Content').style.display = "none";
			
			animate_JD({
					objects: 	popupID+'				|'+popupID+'		|'+popupID+'Content',	
					properties: "width				|left			|opacity",
					start: 		"0					|"+startLeft+"	|0",
					end: 		""+endWidth+"		|"+endLeft+"	|1",
					extension:	"px					|px				|",
					interval: 	"20					|20				|40",
					frames: 	"10					|10				|6",
					effect:		"SFS",
					wait:		"0					|-1				|0",
					onStart:    "toggle('"+popupID+"')	|				|document.getElementById('"+popupID+"Content').style.display = 'block';",
					onComplete:	"					|				|doAfterOpen_JD(\""+popupID+"\")"
				});	
		break;
		
		
		//-----------------------------------
		//FADE IN WITH BOTH VERTICAL AND HORIZONTAL
		//-----------------------------------
		case "dualExpand":
			document.getElementById(popupID).style.display = "block";
			var endWidth = document.getElementById(popupID).offsetWidth;
			var endHeight = document.getElementById(popupID).offsetHeight;
			document.getElementById(popupID).style.display = "none";
			
			var endLeft = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			var startLeft = (endLeft*1) + (endWidth / 2);
			
			document.getElementById(popupID).style.height="50px";
			document.getElementById(popupID+'Content').style.display = "none";
			
			animate_JD({
					objects: 	popupID+'				|'+popupID+'		|'+popupID+'		|'+popupID+'Content',	
					properties: "width				|left			|height			|opacity",
					start: 		"0					|"+startLeft+"	|50				|0",
					end: 		endWidth+"			|"+endLeft+"	|"+endHeight+"	|1",
					extension:	"px					|px				|px				|",
					interval: 	"20					|20				|20				|40",
					frames: 	"12					|12				|12				|6",
					effect:		"SFS",
					wait:		"0					|-1				|0				|0",
					onStart:    "toggle('"+popupID+"')	||| document.getElementById('"+popupID+"Content').style.display = 'block';",
					onComplete:	"					|||"+"doAfterOpen_JD(\""+popupID+"\")"
				});	
		break;
		
		
		//-----------------------------------
		//FADE IN WITH EXPLOSION FROM CENTER TO REQUIRED POSITION
		//-----------------------------------
		case "explode":
			document.getElementById(popupID).style.display = "block";
			var endWidth = document.getElementById(popupID).offsetWidth;
			var endHeight = document.getElementById(popupID).offsetHeight;
			document.getElementById(popupID).style.display = "none";
			
			var endLeft = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			var startLeft = (endLeft*1) + (endWidth / 2);
			
			var endTop = (document.getElementById(popupID).style.top).substring(0,(document.getElementById(popupID).style.top).length-2);
			var startTop = (endTop*1) + (endHeight / 2);
			
			document.getElementById(popupID).style.height="0px";
			document.getElementById(popupID).style.width="0px";
			document.getElementById(popupID+'Content').style.display = "none";
			
			animate_JD({
					objects: 	popupID+'			|'+popupID+'	|'+popupID+'	|'+popupID+'	|'+popupID+'Content',	
					properties: "width				|height			|left			|top			|opacity",
					start: 		"0					|0				|"+startLeft+"	|"+startTop+"	|0",
					end: 		endWidth+"			|"+endHeight+"	|"+endLeft+"	|"+endTop+"		|1",
					extension:	"px					|px				|px				|px				|",
					interval: 	"20					|20				|20				|20				|40",
					frames: 	"25					|25				|25				|25				|6",
					effect:		"spring				|spring			|spring			|spring			|SFS",
					wait:		"0					|-1				|-2				|-3				|0",
					onStart:    "toggle('"+popupID+"')|				|||document.getElementById('"+popupID+"Content').style.display = 'block';",
					onComplete:	"									|||"+"doAfterOpen_JD(\""+popupID+"\")"
					
				});	
		
		break;
		
	}
}

/*
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-------------------------------------------------------------------------------------------------
START OF POPUP CLOSE EFFECTS
-------------------------------------------------------------------------------------------------
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*/

/*------------------------------------------------------------------
This function destroys a popup after close
------------------------------------------------------------------*/
function destroyPopup_JD(object){
	var object = document.getElementById(object);
	document.body.removeChild(object);
}


/*------------------------------------------------------------------
This function checks is a popup should be destroyed on close
------------------------------------------------------------------*/
function checkDestroy_JD(popupID){
	if(closeDestroy[popupID] == "true"){
		destroyPopup_JD(popupID);
	}else{
		toggle(popupID);	
	}
}

function doAfterClose(popupID){
	checkDestroy_JD(popupID);	
	eval(closeAction[popupID]);
	if(closeFocus[popupID].length >0){document.getElementById(closeFocus[popupID]).focus();}
}


function closePopup_JD(params){
	var popupID = params.popupID;
	if(params.blanket != 'undefined'){closeBlanket[popupID] = params.blanket;}
	closePopup_auto_JD(popupID);
}


/*------------------------------------------------------------------
This function closes a popup with the desired effect
------------------------------------------------------------------*/
function closePopup_auto_JD(popupID){	
	var effect =  closeEffect[popupID];
	var blanket = closeBlanket[popupID];	
	
	switch(effect){
		//-----------------------------------
		//FADE OUT
		//-----------------------------------
		case "fade":
				animate_JD({
					objects: 	''+popupID,	
					properties: "opacity",
					start: 		"1",
					end: 		"0",
					interval: 	"20",
					frames: 	"5",
					effect:		"SFS",
					wait:		"0",
					onComplete: "doAfterClose(\""+popupID+"\")"
				});	
		break;
		
		
		//-----------------------------------
		//FADE OUT AND DISAPPEAR TO LEFT OR RIGHT
		//-----------------------------------
		case "toLeft":
		case "toRight":
			var startPos = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			
			if(effect == "toLeft"){
				var endPos = startPos - 300;
			}else{
				var endPos = (startPos*1) + 300;
			}
			
			animate_JD({
					objects: 	popupID+'		|'+popupID,	
					properties: "opacity	|left",
					start: 		"1			|"+startPos,
					end: 		"0			|"+endPos,
					extension:	"			|px",
					interval: 	"20			|20",
					frames: 	"11			|12",
					effect:		"SFS",
					wait:		"0			|-1",
					onComplete: "			|doAfterClose(\""+popupID+"\")"
				});
			
		break;
		
		//-----------------------------------
		//FADE OUT AND DISAPPEAR TO TOP OR BOTTOM
		//-----------------------------------
		case "toTop":
		case "toBottom":
			var startPos = (document.getElementById(popupID).style.top).substring(0,(document.getElementById(popupID).style.top).length-2);
			
			if(effect == "toTop"){
				var endPos = startPos - 300;
			}else{
				var endPos = (startPos*1) + 300;
			}
	
			animate_JD({
					objects: 	popupID+'	|'+popupID,	
					properties: "opacity	|top",
					start: 		"1			|"+startPos,
					end: 		"0			|"+endPos,
					extension:	"			|px",
					interval: 	"20			|20",
					frames: 	"11			|12",
					effect:		"SFS",
					wait:		"0			|-1",
					onComplete: "			|doAfterClose(\""+popupID+"\")"
				});
		break;
		
		
		//-----------------------------------
		//FADE IN AND EXPAND VERTICALLY
		//-----------------------------------
		case "verticalCollapse":
			
			var startHeight = document.getElementById(popupID).offsetHeight;
			document.getElementById(popupID+'Content').style.display = "none";
			
			animate_JD({
					objects: 	popupID+'Content	|'+popupID+'		|'+popupID,	
					properties: "opacity			|height			|opacity",
					start: 		"1					|"+startHeight+"|1",
					end: 		"0					|50				|0",
					extension:	"					|px				|",
					interval: 	"40					|20				|40",
					frames: 	"6					|10				|3",
					effect:		"SFS",
					wait:		"0					|0				|0",
					onComplete: "document.getElementById('"+popupID+"Content').style.display = 'none';||doAfterClose(\""+popupID+"\")"
				});				
		break;
		
		
		//-----------------------------------
		//FADE OUT AND EXPAND HORIZONTALLY
		//-----------------------------------
		case "horizontalCollapse":
			var startWidth = document.getElementById(popupID).offsetWidth;
			var startLeft = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			var endLeft = (startLeft*1) + (startWidth / 2);
						
			animate_JD({
					objects: 	popupID+'Content	|'+popupID+'	|'+popupID,	
					properties: "opacity			|left			|width",
					start: 		"1					|"+startLeft+"	|"+startWidth,
					end: 		"0					|"+endLeft+"	|0",
					extension:	"					|px				|px",
					interval: 	"40					|20				|20",
					frames: 	"5					|10				|10",
					effect:		"SFS",
					wait:		"0					|0				|-1",
					onComplete: "document.getElementById('"+popupID+"Content').style.display = 'none';||doAfterClose(\""+popupID+"\")"
				});	
		break;
		
		
		//-----------------------------------
		//FADE OUT WITH BOTH VERTICAL AND HORIZONTAL
		//-----------------------------------
		case "dualCollapse":
						
			var startWidth = document.getElementById(popupID).offsetWidth;
			var startHeight = document.getElementById(popupID).offsetHeight;
			
			var startLeft = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			var endLeft = (startLeft*1) + (startWidth / 2);
			
			animate_JD({
					objects: 	popupID+'Content	|'+popupID+'		|'+popupID+'		|'+popupID,	
					properties: "opacity		|height			|width			|left",
					start: 		"1				|"+startHeight+"|"+startWidth+"	|"+startLeft,
					end: 		"0				|50				|0				|"+endLeft,
					extension:	"				|px				|px				|px",
					interval: 	"40				|20				|20				|20",
					frames: 	"5				|12				|7				|7",
					effect:		"SFS",
					wait:		"0				|0				|0				|-1",
					onComplete: "document.getElementById('"+popupID+"Content').style.display = 'none';||doAfterClose(\""+popupID+"\")"
				});	
		break;
		
		
		//-----------------------------------
		//FADE OUT WITH IMPLOSION
		//-----------------------------------
		case "implode":
			var startWidth = document.getElementById(popupID).offsetWidth;
			var startHeight = document.getElementById(popupID).offsetHeight;
			
			var startLeft = (document.getElementById(popupID).style.left).substring(0,(document.getElementById(popupID).style.left).length-2);
			var endLeft = (startLeft*1) + (startWidth / 2);
			
			var startTop = (document.getElementById(popupID).style.top).substring(0,(document.getElementById(popupID).style.top).length-2);
			var endTop = (startTop*1) + (startHeight / 2);
			
			
			animate_JD({
					objects: 	popupID+'Content	|'+popupID+'Header	|'+popupID+'Footer	|'+popupID+'Button',	
					properties: "opacity			|opacity			|opacity			|opacity",
					start: 		"1					|1					|1					|1",
					end: 		"0					|0					|0					|0",
					extension:	"					|					|					|",
					interval: 	"40					|40					|40					|40",
					frames: 	"5					|5					|5					|5",
					effect:		"speed",
					wait:		"0					|-1					|-2					|-3",
					onComplete: "document.getElementById('"+popupID+"Content').style.display = 'none';|||"
				});	
			
			animate_JD({
					objects: 	popupID+'		|'+popupID+'	|'+popupID+'	|'+popupID,	
					properties: "height			|left			|top			|width",
					start: 		startHeight+"	|"+startLeft+"	|"+startTop+"	|"+startWidth,
					end: 		"0				|"+endLeft+"	|"+endTop+"		|0",
					extension:	"px				|px				|px				|px",
					interval: 	"20				|20				|20				|20",
					frames: 	"15				|15				|15				|16",
					effect:		"speed",
					wait:		"0				|-1				|-2				|-3",
					onComplete: "|||doAfterClose(\""+popupID+"\")"
				});	
		
		break;
	}
	
	if(blanket == "true"){
		animate_JD({
			objects: 	'blanket',	
			properties: "opacity",
			start: 		"0.85",
			end: 		"0",
			interval: 	"40",
			frames: 	"5",
			effect:		"SFS",
			wait:		"1",
			onComplete: "hideBlanket()"
		});	
	}
}




