/*
 * render background in 3 parts (top half, bottom half, one bar with no onclick at the height and yposition of the buttons next and prev
 */

function moralis_popup(dynamicPath,type,show_more_than_one,id,group_id,goToLocation,deleteName,form,formMode,serverMessage,appealStatus,serverName)
{
	var animationInterval;
	
	var dataInterval;
	
	var contentInterval;
	
	var loadingInterval;
	
	var resizeInterval;
	
	var contentHTML;
	
	var contentHTMLContainer;
	
	var _targetNode;
	
	var _contentContainerId	= '';
	
	var animationLock		= false;
	
	var currentAnimation	= "";
	
	var currentTargetId		= "";
	
	var popupTarget			= document.getElementById('html-body');
	
	var contentTargetNode;
	
	var dymensions			= getCanvasDimensions();
	
	var maxWidth			= dymensions[0] - 400; 

	var maxHeight			= dymensions[1] - 50;
	
	var initWidth			= 293;
	
	var initHeight			= 220;
	
	var contentAmount		= 0;
	
	var currentContentId	= id;
	
	var originalWidth		= 0;
	
	var originalHeight		= 0;
	
	var currentWidth		= 0;
	
	var currentHeight		= 0;
	
	var targetWidth			= 0;
	
	var targetHeight		= 0;
	
	var contentArray 		= false;
	
	var loadingCheck		= false;
	
	var widthChangeDone		= false;
	
	var heightChangeDone	= false;
	
	var allowSetContent		= false;
	
	var isFirstItem			= false;
	
	var isLastItem			= false;
	
	var nextItemId			= false;
	
	var previousItemId		= false;
	
	var contentSetCleared	= true;
	
	var counter				= 0;
	
	var previousPreload		= new Image();
	
	previousPreload.src		= dynamicPath+'img/previous.png';
	
	var nextPreload			= new Image();
	
	nextPreload.src			= dynamicPath+'img/next.png';
	
	var previousPreloadI	= new Image();
	
	previousPreloadI.src	= dynamicPath+'img/previous_inactive.png';
	
	var nextPreloadI		= new Image();
	
	nextPreloadI.src		= dynamicPath+'img/next_inactive.png';
	
	var closePreload		= new Image();
	
	closePreload.src		= dynamicPath+'img/close.png';
	
	createPopupBackground(popupTarget,dymensions);
	
	createPopupWindow(initWidth,initHeight,(initWidth/2*-1),(initHeight/2*-1));
	
	setLoadingAnimation();
	
	loadContent();
	
	dataInterval		= setInterval(initPopupContent, 40);
	
	function initPopupContent()
	{
		if(contentArray)
		{
			clearInterval(dataInterval);
			
			if(type == 'img')
			{
				var currentContentData 	= getContentData(currentContentId);
			
				targetWidth				= currentContentData[2];
				
				targetHeight			= currentContentData[3];
				
				resizePopup();
				
				contentHTML				= '<img src="'+dynamicPath+'files/images/'+currentContentData[1]+'" width="'+targetWidth+'" height="'+targetHeight+'" onclick="openImageInBrowser(this.src);" />';
				
				contentHTMLContainer	= 'contentAnimationContainer';
				
				contentInterval			= setInterval(setPopupWindowContent, 40);
			}
			else if(type == 'form')
			{
				pathCount				= Math.floor( dynamicPath.length/3 );
				
				var updateVar			= formMode == 'update' ? '&id='+id : '';
				
				req = new Request(
				{
					method: 'get',
					url: dynamicPath+'php/popup.php?form='+form+'&from_tab='+lastActiveTab+'&type='+formMode+'&path='+pathCount+updateVar,
					onComplete: function(response)
					{
						contentHTMLContainer		= 'contentAnimationContainer';
						
						var separation_char 		= '{,}';
						
						response					= new Array(response.substr(0,stripos(response,separation_char)),response.substr(stripos(response,separation_char)+separation_char.length));
						
						targetWidth					= 780;

						targetHeight 				= parseInt(response[1])+80 < maxHeight && parseInt(response[1]) != 0 ? parseInt(response[1])+80 : maxHeight;

						resizePopup('instant');
						
						contentTargetNode.innerHTML	= response[0];
						
						document.getElementById('form_container').style.height	= targetHeight-80+'px';
						
						tinyMCE.init(
						{
							mode: "textareas",
							theme: "advanced",
							plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
							
							theme_advanced_buttons1: "newdocument,preview,fullscreen,|,undo,redo,|,bold,italic,underline,charmap,sub,sup,strikethrough,|,cut,copy,paste,pastetext,pasteword,|,search,replace,|,justifyleft,justifycenter,justifyright,justifyfull,blockquote,forecolor,backcolor,|,link,unlink,charmap,image,hr,removeformat",
							theme_advanced_buttons2: "formatselect,fontselect,fontsizeselect,bullist,numlist,|,outdent,indent,|,tablecontrols,|,visualaid,cleanup,code,styleprops",
							theme_advanced_buttons3: "",
							theme_advanced_buttons4: "",
							
							content_css : dynamicPath+"css/tinymce_real_style.css",
		
							theme_advanced_toolbar_location: "top",
							theme_advanced_toolbar_align: "left",
							theme_advanced_statusbar_location : "bottom",
		       				theme_advanced_resizing : true,
							
							skin: "o2k7",
							skin_variant: "silver"
						});
					}
				}).send();
			}
			else if(type == 'confirmDelete')
			{
				contentHTML					= '<h3 style="color:333;text-align:center;">confirm delete</h3><p>Are you sure you wish to delete the selected item?</p><p class="popup_text_highlight">'+deleteName+'</p><a id="save_btn" href="'+goToLocation+'&delete=yes" class="popup_confirm_btn"> </a> <a href="" class="popup_decline_btn" onclick="closePopup();return false;"> </a>';
				
				contentHTMLContainer		= 'contentAnimationContainer';
				
				contentTargetNode.innerHTML	= contentHTML;
			}
			else if(type == 'blacklistMessage')
			{
				//vars: appealStatus, serverMessage
				
				contentHTML	= '';
				
				if(appealStatus == "idle")
				{
					contentHTML	+= '<h3 style="color:333;text-align:center;">Unable to preform action</h3>';
					
					if(serverMessage)
						contentHTML += '<p class="popup_reason">You are not allowed to post messages,<br/>because you have been blacklisted on '+serverName+' for:</p><p class="popup_reason" ><span style="color:#0000ff;font-size:15px;">'+serverMessage+'</span></p>';
					else
						contentHTML += '<p class="popup_reason">You are not allowed to post messages,<br/>because you have been blacklisted on '+serverName+'.</p>';
					
					contentHTML += '<p class="popup_reason">You are allowed to appeal this ban once, but your<br/>situation will not change untill an administrator or moderator<br/>from '+serverName+' approves or denies your ban appeal.</p>';
					
					// appeal
					contentHTML += '<a id="appeal_btn" href="" onclick="closePopup();moralis_popup(\''+dynamicPath+'\',\''+type+'\',\''+show_more_than_one+'\',\''+id+'\',\''+group_id+'\',\''+goToLocation+'\',\''+deleteName+'\',\''+form+'\',\''+formMode+'\',\''+serverMessage+'\',\'processing\',\''+serverName+'\');return false;" class="popup_appeal_btn">&nbsp;</a>';
					// close
					contentHTML += '<a id="close_btn" href="" onclick="closePopup();return false;" class="popup_continue_btn">&nbsp;</a>';
					
					targetWidth		= 480;

					targetHeight 	= 270;
	
					resizePopup('instant');
				}
				else if(appealStatus == "processing")
				{
					contentHTML	+= '<h3 style="color:333;text-align:center;">Appealing to ban</h3>';
								
					contentHTML += '<p class="popup_reason" id="statusAppeal">Processing your ban appeal request.</p>';
								
					targetWidth		= 480;
			
					targetHeight 	= 220;
				
					resizePopup('instant');
					
					req = new Request(
					{
						method: 'get',
						url: dynamicPath+'php/popup.php?appeal_request='+id,
						onComplete: function(response)
						{
						 	if(response == "appeal_processed")
							{
								responseMessage	= '<span style="color:#0000ff;font-size:15px;">Your ban appeal has been submitted</span></p>.';
								
								responseMessage	+= '<p class="popup_reason">This appeal is now awaiting reassessment by an administrator or moderator.</p>';
								
								responseMessage	+= '<p class="popup_reason">Your ban will remain in effect, pending the reassesment. Untill then you will be unable to submit data to '+serverName+'.</p>';
								
								if(document.getElementById('statusAppeal'))
									document.getElementById('statusAppeal').innerHTML	= responseMessage;
							}
							else
							{
								responseMessage	= '<span style="color:#0000ff;font-size:15px;">Your ban appeal could not be processed because you are not eligiable for a ban appeal.</span></p>.';
								
								if(document.getElementById('statusAppeal'))
									document.getElementById('statusAppeal').innerHTML	= responseMessage;
							}
							
							if(document.getElementById('statusAppeal'))
								document.getElementById('statusAppeal').innerHTML	+= '<a id="close_btn" href="" onclick="closePopup();return false;" class="popup_continue_btn align_center">&nbsp;</a>';
						}
					}).send();
				}
				else if(appealStatus == "pending")
				{
					contentHTML	+= '<h3 style="color:333;text-align:center;">Ban appeal request pending</h3>';
					
					contentHTML += '<p class="popup_reason">Your ban appeal is waiting for reassessment by an administrator or moderator of '+serverName+'.</p>';
					
					contentHTML += '<p class="popup_reason">Should your ban appeal be approved, your ban will be lifted.</p>';
					
					contentHTML += '<p class="popup_reason">Pending the reassessment however, your ban will remain in effect and you will not be able to post messages on '+serverName+'.</p>';
					
					contentHTML += '<a id="close_btn" href="" onclick="closePopup();return false;" class="popup_continue_btn align_center">&nbsp;</a>';
				
					targetWidth		= 480;
			
					targetHeight 	= 220;
				
					resizePopup('instant');
				}
				else if(appealStatus == "rejected")
				{
					contentHTML	+= '<h3 style="color:333;text-align:center;">Ban appeal request denied</h3>';
					
					contentHTML += '<p class="popup_reason">An administrator or moderator of '+serverName+' has denied your ban appeal request.</p>';
					
					contentHTML += '<p class="popup_reason">Your ban will remain in effect and you will not be allowed to post messages on '+serverName+'.</p>';
					
					contentHTML += '<a id="close_btn" href="" onclick="closePopup();return false;" class="popup_continue_btn align_center">&nbsp;</a>';
				
					targetWidth		= 480;
			
					targetHeight 	= 190;
				
					resizePopup('instant');
				}
				
				contentHTMLContainer		= 'contentAnimationContainer';
				
				contentTargetNode.innerHTML	= contentHTML;
			}
			else if(type == 'serverMessage')
			{
				if(serverName && serverName > '')
					contentHTML	+= '<h3 style="color:333;text-align:center;">Message from '+serverName+'</h3>';
				else
					contentHTML	+= '<h3 style="color:333;text-align:center;">Message from server</h3>';
				
				if(serverMessage)
				{			
					contentHTML 	+= '<p class="popup_reason">'+serverMessage+'.</p>';
				}
				
				contentHTML 	+= '<a id="close_btn" href="" onclick="closePopup();return false;" class="popup_continue_btn align_center">&nbsp;</a>';
					
				targetWidth		= 480;
		
				targetHeight 	= 180;
			
				resizePopup('instant');
				
				contentHTMLContainer		= 'contentAnimationContainer';
			
				contentTargetNode.innerHTML	= contentHTML;
			}
		}
	}
	
	function loadNext()
	{	
		animationLock 		= false;
				
		currentAnimation 	= '';
				
		currentTargetId 	= '';
				
		clearInterval(animationInterval);
		
		contentSetCleared	= true;
					
		clearInterval(contentInterval);
		
		if(nextItemId)
		{
			widthChangeDone		= false;
					
			heightChangeDone	= false;
			
			clearInterval(dataInterval);
			
			if(!isLastItem)
			{
				setLoadingAnimation(nextItemId);
				
				dataInterval		= setInterval(loadNextContent, 40);
			}
		}
	}
	
	function loadNextContent()
	{
		if(!loadingCheck)
		{
			clearInterval(dataInterval);
			
			var currentContentData 	= getContentData(nextItemId);
				
			targetWidth				= currentContentData[2];
				
			targetHeight			= currentContentData[3];
			
			resizePopup();
				
			contentHTML				= '<img src="'+dynamicPath+'files/images/'+currentContentData[1]+'" width="'+targetWidth+'" height="'+targetHeight+'" onclick="openImageInBrowser(this.src);" />';
				
			contentInterval			= setInterval(setPopupWindowContent, 40);
		}
	}
	
	function loadPrevious()
	{
		animationLock 		= false;
				
		currentAnimation 	= '';
		
		currentTargetId 	= '';
		
		clearInterval(animationInterval);
		
		contentSetCleared	= true;
					
		clearInterval(contentInterval);
		
		if(previousItemId)
		{
			widthChangeDone		= false;
					
			heightChangeDone	= false;
			
			clearInterval(dataInterval);
			
			if(!isFirstItem)
			{
				setLoadingAnimation(previousItemId);
				
				dataInterval		= setInterval(loadPreviousContent, 40);
			}
		}
	}
	
	function loadPreviousContent()
	{
		if(!loadingCheck)
		{
			clearInterval(dataInterval);
			
			var currentContentData 	= getContentData(previousItemId);
				
			targetWidth				= currentContentData[2];
				
			targetHeight			= currentContentData[3];
			
			resizePopup();
				
			contentHTML				= '<img src="'+dynamicPath+'files/images/'+currentContentData[1]+'" width="'+targetWidth+'" height="'+targetHeight+'" onclick="openImageInBrowser(this.src);" />';
				
			contentInterval			= setInterval(setPopupWindowContent, 40);
		}
	}
	
	function loadContent()
	{
		if(type == 'img')
		{
			detailString	= show_more_than_one ? '&gid='+group_id : '&pid='+id;
		
			req = new Request(
			{
				method: 'get',
				url: dynamicPath+'php/popup.php?m='+type+"&w="+maxWidth+"&h="+maxHeight+detailString,
				onComplete: function(response)
				{
					contentArray	= eval(response);
					
					contentAmount	= contentArray.length;
				}
			}).send();
		}
		else
		{
			contentArray	= new Array('filler');
			
			contentAmount	= contentArray.length;
		}
	}
	
	function getContentData(_id)
	{
		var _output = null;
		
		if(contentArray)
		{
			for(i=0;i<contentArray.length;i++)
			{
				var img	= new Image();
				
				img.src	= dynamicPath+'files/images/'+contentArray[i][1];
				
				if(contentArray[i][0] == _id)
				{
					_output			= contentArray[i];
					
					isFirstItem		= i <= 0 ? true : false; 
						
					isLastItem		= i >= contentArray.length-1 ? true : false;
					
					nextItemId		= !isLastItem ? contentArray[i+1][0] : false;
					
					previousItemId	= !isFirstItem ? contentArray[i-1][0] : false;
					
					if(isLastItem)
					{
						if(document.getElementById('popup_next_button'))
						{
							next				= document.getElementById('popup_next_button');
							
							next.className		= 'popupNextInactive';
							
							next.href			= "";
					
							next.onclick		= function()
							{
								return false;
							}
						}
					}
					
					if(isFirstItem)
					{
						if(document.getElementById('popup_previous_button'))
						{
							prev				= document.getElementById('popup_previous_button');
							
							prev.className		= 'popupPreviousInactive';
							
							prev.href			= "";
					
							prev.onclick		= function()
							{
								return false;
							}
						}
					}
				}
			}
		}
		
		return _output;
	}
	
	function getContentDataSingle(_id)
	{
		var _output = null;
		
		if(contentArray)
		{
			for(i=0;i<contentArray.length;i++)
			{
				if(contentArray[i][0] == _id)
				{
					_output			= contentArray[i];
				}
			}
		}
		
		return _output;
	}
	
	function createPopupBackground(_popupTarget,dymensions)
	{
		var popupBackground				= document.createElement('div');
		
		popupBackground.id				= "popup_bg";
		
		popupBackground.style.cssText = "width:"+dymensions[0]+"px;height:"+dymensions[1]+"px;";
		
		//popupBackground.style.width		= dymensions[0]+"px;";
		//popupBackground.style.height	= dymensions[1]+"px;";
		/*
		popupBackground.onclick			= function()
		{
			closePopup();
		}
		*/
		_popupTarget.appendChild(popupBackground);
	}
	
	function createPopupWindow(_width,_height,_x_correction,_y_correction)
	{
		var popupWindow					= document.createElement('div');
		
		popupWindow.id					= "popup_content";
		popupWindow.style.width			= _width+"px";
		popupWindow.style.height		= _height+"px";
		popupWindow.style.marginTop		= _y_correction+"px";
		popupWindow.style.marginLeft	= _x_correction+"px";
		
		popupTarget.appendChild(popupWindow);
		
		createPopupCloseButton(_x_correction,_y_correction);
		
		contentTargetNode				= document.getElementById('popup_content');
	}
	
	function createPopupCloseButton(_x_correction,_y_correction)
	{
		_x_correction				= _x_correction * -1;
		
		var closeBtn				= document.createElement('a');
		
		closeBtn.id					= "popup_close_btn";
		closeBtn.href				= "javascript:closePopup();";
		closeBtn.style.marginLeft	= (_x_correction-12)+"px";
		closeBtn.style.marginTop	= (_y_correction-12)+"px";
		closeBtn.onclick			= function()
		{
			closePopup();
			
			return false;
		} 
		
		popupTarget.appendChild(closeBtn);
	}
	
	function resizePopup(mode)
	{
		if(mode && mode == 'instant')
		{
			var contentTarget					= document.getElementById('popup_content');
		
			var contentCloseTarget				= document.getElementById('popup_close_btn');
			
			widthChangeDone						= true;
				
			heightChangeDone					= true;
			
			contentTargetNode.style.height		= targetHeight+"px";
					
			contentTargetNode.style.marginTop	= (Math.round((targetHeight)/2)*-1)+"px";
			
			contentCloseTarget.style.marginTop	= (Math.round(((targetHeight)/2)*-1)-12)+"px";
			
			contentTargetNode.style.width		= targetWidth+"px";
					
			contentTargetNode.style.marginLeft	= (Math.round((targetWidth)/2)*-1)+"px";
				
			contentCloseTarget.style.marginLeft	= (Math.round((targetWidth)/2)-12)+"px";
		}
		else
		{
			widthChangeDone			= false;
				
			heightChangeDone		= false;
			
			currentWidth			= document.getElementById('popup_content').style.width.replace("px",'');
			
			currentHeight			= document.getElementById('popup_content').style.height.replace("px",'');
			
			resizeInterval			= setInterval(changeSize, 20);
		}
	}
	
	function changeSize()
	{
		var contentTarget				= document.getElementById('popup_content');
		
		var contentCloseTarget			= document.getElementById('popup_close_btn');
		
		if(document.getElementById('popup_next_button'))
			var nextButtonTarget		= document.getElementById('popup_next_button');
		else
			var nextButtonTarget		= false;
					
		if(document.getElementById('popup_previous_button'))
			var previousButtonTarget	= document.getElementById('popup_previous_button');
		else
			var previousButtonTarget	= false;
			
		var ie_corr	= 0;
		
		if (navigator.appName == 'Microsoft Internet Explorer')
		{
		   ie_corr = 8;
		}

		
		if (!animationLock || (currentAnimation == 'resize' && currentTargetId == contentTarget.id)) 
		{
			animationLock 		= true;
			
			currentAnimation 	= 'resize';
			
			currentTargetId 	= contentTarget.id;
			
			allowSetContent		= false;
			
			if(widthChangeDone && heightChangeDone)
			{
				animationLock 		= false;
				
				currentAnimation 	= '';
			
				currentTargetId 	= '';
				
				allowSetContent		= true;
				
				widthChangeDone		= false;
				
				heightChangeDone	= false;
				
				clearInterval(resizeInterval);
				
				currentWidth				= parseInt(contentTargetNode.style.width.replace("px",''));
				
				var correctionPreviousBtn	=  ((dymensions[0] - currentWidth)/2) - 50 - 8;
		
				var correctionNextBtn		=  dymensions[0] - ((dymensions[0] - currentWidth)/2) - 3;
				
				if(previousButtonTarget)
					previousButtonTarget.style.marginLeft	= (correctionPreviousBtn+ie_corr)+"px";
						
				if(nextButtonTarget)
					nextButtonTarget.style.marginLeft	= (correctionNextBtn+ie_corr)+"px";
			}
			else
			{
				var stepSize			= 16;
				
				var marginCorrection	= stepSize/2;
				
				currentWidth			= parseInt(contentTargetNode.style.width.replace("px",''));
				
				currentHeight			= parseInt(contentTargetNode.style.height.replace("px",''));
				
				var diffrenceWidth		= targetWidth-currentWidth;
				
				var diffrenceHeight		= targetHeight-currentHeight;
				
				if((diffrenceWidth > 0 && diffrenceWidth <= stepSize) || (diffrenceWidth < 0 && diffrenceWidth >= (stepSize*-1)) || diffrenceWidth == 0)
				{
					widthChangeDone						= true;
					
					contentTargetNode.style.width 		= targetWidth+"px";
					
					contentTargetNode.style.marginLeft	= (Math.round((targetWidth)/2)*-1)+"px";
					
					contentCloseTarget.style.marginLeft	= (Math.round((targetWidth)/2)-12)+"px";
				}
				else if(diffrenceWidth > 0)
				{
					contentTargetNode.style.width 		= (currentWidth+stepSize)+"px";
					
					contentTargetNode.style.marginLeft	= (Math.round(((currentWidth+stepSize))/2)*-1)+"px";
					
					contentCloseTarget.style.marginLeft	= (Math.round(((currentWidth+stepSize))/2)-12)+"px";
					
					if(previousButtonTarget)
						previousButtonTarget.style.marginLeft	=  parseInt(previousButtonTarget.style.marginLeft.replace('px',''))-(stepSize/2)+"px";
						
					if(nextButtonTarget)
						nextButtonTarget.style.marginLeft	=  parseInt(nextButtonTarget.style.marginLeft.replace('px',''))+(stepSize/2)+"px";
				}
				else if(diffrenceWidth < 0)
				{
					contentTargetNode.style.width 		= (currentWidth-stepSize)+"px";
					
					contentTargetNode.style.marginLeft	= (Math.round(((currentWidth-stepSize))/2)*-1)+"px";
					
					contentCloseTarget.style.marginLeft	= (Math.round(((currentWidth+stepSize))/2)-12)+"px";
					
					if(previousButtonTarget)
						previousButtonTarget.style.marginLeft	=  parseInt(previousButtonTarget.style.marginLeft.replace('px',''))+(stepSize/2)+"px";
						
					if(nextButtonTarget)
						nextButtonTarget.style.marginLeft	= parseInt(nextButtonTarget.style.marginLeft.replace('px',''))-(stepSize/2)+"px";
				}
				else
				{
					widthChangeDone						= true;
					
					contentTargetNode.style.width		= targetWidth+"px";
					
					contentTargetNode.style.marginLeft	= (Math.round((targetWidth)/2)*-1)+"px";
					
					contentCloseTarget.style.marginLeft	= (Math.round((targetWidth)/2)-12)+"px";
				}
				
				if((diffrenceHeight > 0 && diffrenceHeight <= stepSize) || (diffrenceHeight < 0 && diffrenceHeight >= (stepSize*-1)) || diffrenceHeight == 0)
				{
					heightChangeDone					= true;
					
					contentTargetNode.style.height		= targetHeight+"px";
					
					contentTargetNode.style.marginTop	= (Math.round((targetHeight)/2)*-1)+"px";
					
					contentCloseTarget.style.marginTop	= (Math.round(((targetHeight)/2)*-1)-12)+"px";
				}
				else if(diffrenceHeight > 0)
				{
					contentTargetNode.style.height		= (currentHeight+stepSize)+"px";
					
					contentTargetNode.style.marginTop	= (Math.round(((currentHeight+stepSize))/2)*-1)+"px";
					
					contentCloseTarget.style.marginTop	= (Math.round((((currentHeight+stepSize))/2)*-1)-12)+"px";
				}
				else if(diffrenceHeight < 0)
				{
					contentTargetNode.style.height		= (currentHeight-stepSize)+"px";
					
					contentTargetNode.style.marginTop	= (Math.round(((currentHeight-stepSize))/2)*-1)+"px";
					
					contentCloseTarget.style.marginTop	= (Math.round((((currentHeight+stepSize))/2)*-1)-12)+"px";
				}
				else
				{
					heightChangeDone					= true;
					
					contentTargetNode.style.height		= targetHeight+"px";
					
					contentTargetNode.style.marginTop	= (Math.round((targetHeight)/2)*-1)+"px";
					
					contentCloseTarget.style.marginTop	= (Math.round(((targetHeight)/2)*-1)-12)+"px";
				}
			}
		}
	}
	
	function fadeIn(targetNode)
	{
		if (targetNode) 
		{
			_targetNode				= targetNode;
			
			_targetNode.xOpacity	= _targetNode.xOpacity <= 1 ? _targetNode.xOpacity : 0;
			
			animationLock 		= false;
				
			currentAnimation 	= '';
			
			currentTargetId 	= '';
			
			clearInterval(animationInterval);
			
			animationInterval		= setInterval(fadeInOpacity, 40);
		}
	}
	
	function fadeOut(targetNode)
	{
		if (targetNode) 
		{
			_targetNode				= targetNode;
			
			_targetNode.xOpacity	= _targetNode.xOpacity >= 0 ? _targetNode.xOpacity : .99;
			
			animationLock 		= false;
				
			currentAnimation 	= '';
			
			currentTargetId 	= '';
			
			clearInterval(animationInterval);
			
			animationInterval		= setInterval(fadeOutOpacity, 40);
		}
	}
	
	function fadeOutOpacity(targetNode)
	{
		if (!animationLock || (currentAnimation == 'fadeOut' && currentTargetId == _targetNode.id)) 
		{
			animationLock 		= true;
			
			currentAnimation 	= 'fadeOut';
			
			currentTargetId 	= _targetNode.id;
			
			if (_targetNode.xOpacity <= 0)
			{
				animationLock 		= false;
				
				currentAnimation 	= '';
			
				currentTargetId 	= '';
				
				clearInterval(animationInterval);
			} 
			else 
				_targetNode.xOpacity -= .05;
			
			_targetNode.xOpacity			= _targetNode.xOpacity < 0 ? 0 : _targetNode.xOpacity;
			
			_targetNode.style.filter		= 'alpha(opacity=' + (_targetNode.xOpacity * 100) + ')';
			
			_targetNode.style.opacity		= _targetNode.xOpacity;
			
			_targetNode.style.MozOpacity	= _targetNode.xOpacity;
		}
	}
	
	function fadeInOpacity()
	{
		if (!animationLock || (currentAnimation == 'fadeIn' && currentTargetId == _targetNode.id)) 
		{
			animationLock		= true;
			
			currentAnimation	= 'fadeIn';
			
			currentTargetId		= _targetNode.id;
			
			if (_targetNode.xOpacity >= .99) 
			{
				animationLock 		= false;
				
				currentAnimation 	= '';
			
				currentTargetId 	= '';
				
				clearInterval(animationInterval);
			}
			else 
				_targetNode.xOpacity += .05;
			
			_targetNode.xOpacity			= _targetNode.xOpacity > .99 ? .99 : _targetNode.xOpacity;
			
			_targetNode.style.filter		= 'alpha(opacity=' + (_targetNode.xOpacity * 100) + ')';
			
			_targetNode.style.opacity		= _targetNode.xOpacity;
			
			_targetNode.style.MozOpacity	= _targetNode.xOpacity;
			
			_targetNode.style.visibility	= 'visible';
		}
	}
	
	function setPopupWindowContent(_loadId)
	{
		if(allowSetContent)
		{
			if(_loadId)
			{
				contentSetCleared	= false;
				
				var loading			= getContentDataSingle(_loadId);
				
				var imgLoad 		= new Image();
				
				imgLoad.src			= dynamicPath+'files/images/'+imgLoad[1];
				
				if(imgLoad.height > 0)
				{
					contentSetCleared	= true;
					
					clearInterval(contentInterval);
				}
			}
			else
			{
				contentSetCleared	= true;
				
				clearInterval(contentInterval);
			}
			
			if(contentSetCleared)
			{
				if(show_more_than_one)
					setControls();
				
				var contentTarget	= document.getElementById('popup_content');
				
				if(contentHTML)
				{
					if(type == 'img')
						contentTarget.innerHTML	= "<div id=\""+contentHTMLContainer+"\" style=\"visibility:hidden;\">"+contentHTML+"</div>";
					else if(type == 'confirmDelete')
						contentTarget.innerHTML	= "<div id=\""+contentHTMLContainer+"\" style=\"\">"+contentHTML+"</div>";
						
					_contentContainerId	= contentHTMLContainer;
					
					if(animationTarget	= document.getElementById(_contentContainerId))
					{
						if(type	== 'img')
							fadeIn(animationTarget);
					}
				}
				else
				{
					setLoadingAnimation();
				}
			}
		}
	}
	
	function setLoadingAnimation()
	{
		var contentTarget	= document.getElementById('popup_content');
		
		if(contentTarget.innerHTML != '')
		{
			var fadeOutTarget	= document.getElementById(contentHTMLContainer);
			
			if(type == 'img')
			{
				animationLock 		= false;
				
				currentAnimation 	= '';
			
				currentTargetId 	= '';
				
				clearInterval(animationInterval);
				
				fadeOut(fadeOutTarget);
			}
			
			loadingCheck		= false;
			
			clearInterval(loadingInterval);
				
			loadingInterval		= setInterval(checkLoadingAnimation, 40);
		}
		else
		{		
			contentTarget.innerHTML	= "<div class=\"loader\" id=\"loader\"><object width=\"100\" height=\"100\" id=\"loading\" align=\"middle\"><param name=\"movie\" value=\""+dynamicPath+"img/loading/loading.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" /><embed src=\""+dynamicPath+"img/loading/loading.swf\" quality=\"high\" bgcolor=\"#ffffff\" width=\"100\" height=\"100\" name=\"loading\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object></div>";
		}
	}
	
	function checkLoadingAnimation()
	{
		loadingCheck	= true;
		
		if(!animationLock)
		{
			loadingCheck		= false;
			
			var contentTarget	= document.getElementById('popup_content');
			
			clearInterval(loadingInterval);
			
			contentTarget.innerHTML	= "<div class=\"loader\" id=\"loader\"><object width=\"100\" height=\"100\" id=\"loading\" align=\"middle\"><param name=\"movie\" value=\""+dynamicPath+"img/loading/loading.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" /><embed src=\""+dynamicPath+"img/loading/loading.swf\" quality=\"high\" bgcolor=\"#ffffff\" width=\"100\" height=\"100\" name=\"loading\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object></div>";
		}
	}
	
	function setControls()
	{
		var ie_corr	= 0;
		
		if (navigator.appName == 'Microsoft Internet Explorer')
		{
		   ie_corr = 8;
		}
		
		var containerWidth			= targetWidth;
		
		var correctionPreviousBtn	= ((dymensions[0] - containerWidth)/2) - 50 - 8 + ie_corr;
		
		var correctionNextBtn		= dymensions[0] - ((dymensions[0] - containerWidth)/2) - 3 + ie_corr;
		
		if(document.getElementById('popup_previous_button'))
		{
			var prev	= document.getElementById('popup_previous_button');
			
			prev.style.marginLeft	= correctionPreviousBtn+"px";
			
			if(!isFirstItem)
			{
				prev.className		= 'popupPreviousActive' ;
				
				prev.href			= "javascript:loadPrevious();";
				
				prev.onclick		= function()
				{
					loadPrevious();
					
					return false;
				}
			}
			else
			{
				prev.className		= 'popupPreviousInactive';
				
				prev.href			= "";
				
				prev.onclick		= function()
				{
					return false;
				}
			}
		}
		else
		{	
			var previousBtn					= document.createElement('a');
			
			previousBtn.id					= "popup_previous_button";
			
			previousBtn.style.marginLeft	= correctionPreviousBtn+"px";
			
			if(isFirstItem)
			{
				previousBtn.className			= "popupPreviousInactive";
			}
			else
			{
				previousBtn.className			= "popupPreviousActive";
				
				previousBtn.href				= "javascript:loadPrevious();";
				
				previousBtn.onclick				= function()
				{
					loadPrevious();
					
					return false;
				}
			}
			
			popupTarget.appendChild(previousBtn);
		}
		
		if(document.getElementById('popup_next_button'))
		{	
			var next				= document.getElementById('popup_next_button');
			
			next.style.marginLeft	= correctionNextBtn+"px";
			
			if(!isLastItem)
			{
				next.className		= 'popupNextActive';
				
				next.href			= "javascript:loadNext();";
				
				next.onclick		= function()
				{
					loadNext();
					
					return false;
				}
			}
			else
			{
				next.className		= 'popupNextInactive' ;
				
				next.href			= "";
				
				next.onclick		= function()
				{
					return false;
				}
			}
		}
		else
		{
			var nextBtn					= document.createElement('a');
			
			nextBtn.id					= "popup_next_button";
			
			nextBtn.style.marginLeft	= correctionNextBtn+"px";
			
			if(isLastItem)
			{
				nextBtn.className			= 'popupNextInactive';
			}
			else
			{
				nextBtn.className			= 'popupNextActive';
				
				nextBtn.href				= "javascript:loadNext();";
				
				nextBtn.onclick				= function()
				{
					loadNext();
					
					return false;
				} 
			}
			
			popupTarget.appendChild(nextBtn);
		}
	}
	
	function getCanvasDimensions()
	{
		dymensions = new Array(0,0);
		
		if (typeof(window.innerWidth) == 'number') 
        {
            //Non-IE
            dymensions[0] 	= window.innerWidth;
            dymensions[1] 	= window.innerHeight;
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
        {
            //IE 6+ in 'standards compliant mode'
            dymensions[0] 	= document.documentElement.clientWidth;
            dymensions[1] 	= document.documentElement.clientHeight;
        }
        else if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
        {
            //IE 4 compatible
            dymensions[0] 	= document.body.clientWidth;
            dymensions[1] 	= document.body.clientHeight;
        }
		
		return dymensions;
	}
	
}

function openImageInBrowser(location)
{
	var imgDetail	= window.open(location,"_blank");
	
	imgDetail.focus();
}

function closePopup()
{
    var targetBg	= document.getElementById('popup_bg');
    var targetCt	= document.getElementById('popup_content');
    var targetBt	= document.getElementById('popup_close_btn');
	
	if(document.getElementById('popup_next_button') && document.getElementById('popup_previous_button'))
	{
	    var targetNBt	= document.getElementById('popup_next_button');
	    var targetPBt	= document.getElementById('popup_previous_button');
	}
    
    targetBg.parentNode.removeChild(targetBg);
    targetCt.parentNode.removeChild(targetCt);
    targetBt.parentNode.removeChild(targetBt);
	
	if(document.getElementById('popup_next_button') && document.getElementById('popup_previous_button'))
	{
	    targetNBt.parentNode.removeChild(targetNBt);
	    targetPBt.parentNode.removeChild(targetPBt);
	}
}

