/* Created by Kevin Dibble 
 * Uses Mootools 1.2
 * Expects page elements to be:
 * class "popInPage" must be entered (Supports multiple classes. e.g: class="linkStyle popInPage anotherStyle")
 * href = path to file (absolute or Relative)
 * rel Option 1	= "Caption"   		Enter the text to appear
 * rel Option 2 = "call type"		ajax, json, image, id
 * rel option 3 = "image Libray"    the name to group images by or null
 * rel option 4 = "width"			the desired width
 * rel option 5 = "height"			the desired height
 * 
 * SAMPLE IMAGE LIBRARY CALL
 * <a href="http://localhost/javascript/images/m1.jpg"  rel="Adventure in Paint,image,lib1,400,300" class="popInPage"><img src="../lib/thumbs/m1.jpg" /></a>
 * <a href="../lib/images/m2.jpg" 								rel="Horsey Ride! Horsey Ride,image,lib1,400,300" class="popInPage"><img src="../lib/thumbs/m2.jpg" /></a>
 * 
 * SIMPLE (STANDARD) popup
 * <a href="../lib/page1.php"  								rel="Window Name,ajax,null,400,300" class="simplePop">A simple Link</a>
 * Option 2 can be ajax, json or left empty
 * if it is ajax or json - then it will open inside the page if the user has popup windows blocked
 * if it is nothing - then the popup will not open if the person has popups blocked
 * 
 * SAMPLE PAGE ELEMENT CALL - displays text inside the element to appear
 * <a href="../lib/intent1" rel="Page call,intent1,null,400,300" class="popInPage">PAGE ID CALL</a>
 * 
 * SAMPLE AJAX CALL
 * <a href="../lib/page1.php" rel="Whole Self Journey,ajax,null,500,400" class="popInPage">Page One</a>
 * 
 * AJAX WITH SCRIPT EVALULATED
 * <a href="../lib/json.php" rel="Ajax Call,ajax,eval" class="popInPage">ajax Request - with script eval</a>
 * 
 * SAMPLE JSON CALL
 * <a href="http://localhost/javascript/json.php" title="json" class="popInPage">JSON Request - No JSON Object</a>
 * Script must be in the page between <script> </script> tags
 * 
 * JSON CALL WITH CUSTOM FUNCTION TO HANDLE JSON RESULT
 * <a href="../lib/getChat.php" rel="Json Call,json,<function name>" class="popInPage">JSON Request - Returns a JSON object</a>
 * function must accept a single obj function(obj){}
 */
 
 /*
var PopUpContent = new Class({
	Implements : [Options],
	options : {
		type	: 'ajax'
	},
	initialize : function(obj,options){
		this.setOptions(options);	
		this.object		= $(obj);
	}
});

var PopUp = new Class({
	Implements  : [Options],
	items		: [],
	options : {
		top 		: 'auto',
		left		: 'auto',
		width 		: 'auto',
		height  	: 'auto',
		opacity		: 0.8
	},
 	initialize : function(obj,options){
		this.setOptions(options);
		this.object = obj;
		var show 	= this.show.bind(this);
		var hide 	= this.hide.bind(this);
		var resize 	= this.resize.bind(this);
		$(this.object).getElements(".popup").each(function(item,index){
			this.items[index] = new PopUpContent(item);	
			item.addEvent("click",function(event){new Event(event).stop(); show()});
		},this);
		this.hideBg = new Element("div",{
			'class' : 'hideBG',
			'width'   : (this.options.width=="auto")?  ($(this.object).getSize().x + $(this.object).getScrollSize().x): this.options.width.toInt(),
			'height'  : (this.options.height=="auto")? ($(this.object).getSize().y + $(this.object).getScrollSize().x) : this.options.height.toInt(),
			'opacity' : 0
		});
		this.bgFx = new Fx.Morph($(this.hideBg));
		$(this.hideBg).addEvent("click",hide);
		$(this.hideBg).setStyle("display","none");
		$(this.hideBg).inject($(this.object),"top");
		$(this.object).addEvent("resize",resize);
	},
	resize:function(){
		$(this.hideBg).setStyles({
			'width'   : (this.options.width=="auto")?  ($(this.object).getSize().x + $(this.object).getScrollSize().x): this.options.width.toInt(),
			'height'  : (this.options.height=="auto")? ($(this.object).getSize().y + $(this.object).getScrollSize().y) : this.options.height.toInt(),					 
		});
	},
	show: function(){
		$(this.hideBg).setStyle("display","block");
		$(this.hideBg).morph({"opacity": this.options.opacity});
	},
	hide: function(){
		$(this.hideBg).morph({"opacity": 0});
	}
});
window.addEvent('domready',function(){
	var popups = new PopUp(document.body);							
});
*/
var displayPopUp={
	imagePreloader: null,
	imageLibrary:	"",
	caption: 		null,
	URL: 			null,
	callType:		null,
	scripts : 		null,			// the scripts called back from the ajax page to eval
	width:			300,			// The default width
	height:			200,			// The Default height
	contentTop:		0,				// The default location for the top
	contentLeft:	0,				// The default location for the left
	hideBG:			null,			// The background hider
	bodyWidth:		null,
	bodyHeight:		null,
	content: 		null,
	popTop: 		null,
	popTopClose: 	null,
	theWindow:		null,
	popImageNav:	null,
	popImage:		null,
	imageNum:		null,
	direction:		"next",
	fxMoveTop:		null,
	fxMoveLeft: 	null,
	ajax:			null,
	jsonResult:		null,
	jsonFunction:	null,
	canMove: 		true,
	isAdmin:		false,
	fromTop:		0,
	fromLeft:		0,
	reset: function(){
		$$('a.popInPage').each(function(item,index){
			$(item).removeEvents('click');
		});
		$$("a.simplePop").each(function(item,index){
			$(item).removeEvents('click');
		});
	},
	init: function(){
		var self = displayPopUp;
		self.reset();
		self.imagePreloader = Array();						// Create the preloader Array
		$$('.popInPage').each(function(item,index){		// GET ALL ANCHOR TAGS
			item.addEvent('click',function(event){
				event = new Event(event).stop();			// CANCEL ON CLICK EVENT
				displayPopUp.showPopUp(item);
			});
			var tmp = $(item).get("rel");
			if(tmp.contains("#")){
				tmp = tmp.split("#");	
			}else{
				tmp = tmp.split(",");					// Split the REL Tag
			}
			if(tmp[1]=="image"){							// Create the image preloader
				var details = Array();
				details['image'] 	 = new Asset.image(item.href,{id:'thePopImage'}); // Pre-Load Image
				details['obj'] 		 = $(item).get("rel");			// Save image options
				if(!$defined(displayPopUp.imagePreloader[tmp[2]])){
					displayPopUp.imagePreloader[tmp[2]] = Array();
				}
				displayPopUp.imagePreloader[tmp[2]].push(details); // Save image library
			}
		});
		$$("a.simplePop").each(function(item,index){
			item.addEvent('click',function(event){
				event = new Event(event).stop();			// CANCEL ON CLICK EVENT
				displayPopUp.simplePop(item);
			});
		});
	},
	showPopUp: function(obj){								// Show POP Function
		var self 			= displayPopUp;
		var objValues 		= $(obj).get("rel");
		if(objValues.contains("#")){
			 objValues = objValues.split("#");	
		}else{
			objValues = objValues.split(",");					// Split the REL Tag
		}
		self.fromTop		= $(obj).getCoordinates($(document.body)).top;
		self.fromLeft		= $(obj).getCoordinates($(document.body)).left;
		self.URL			= obj.href;
		self.caption		= objValues[0] 	|| "Window";
		self.callType		= objValues[1]	|| "ajax";
		self.imageLibrary 	= objValues[2]	|| null;
		self.width			= (objValues[3])?	objValues[3] : self.width;  
		self.height 		= (objValues[4])?	objValues[4] : self.height; // Height = 300;
		self.isAdmin		= (objValues[5])?	false : true;
		self.hideBackground(); 	
	},
	simplePop: function(obj){								// DO Simple Popup Function
		var self		= displayPopUp;
		var options 	= $(obj).get("rel").split(",");
		self.url 		= obj.href;
		var thisName 	= options[1]	|| "popup";
		var thisWidth	= options[3]	|| self.width;
		var thisHeight 	= options[4] 	|| self.height;
		var windowSize 	= window.getSize();
		var left		= (windowSize.x/2)-(thisWidth/2);
		var top 		= (windowSize.y/2)-(thisHeight/2);
		if($defined(self.theWindow)){
			try{self.theWindow.close();}catch(e){}
			self.theWindow = null;
		}
		try{
			self.theWindow = window.open(self.url, thisName, "left = "+left+", top = "+top +", status = 0, height = "+parseInt(thisHeight)+", width = "+ parseInt(thisWidth) +", resizable = 0, scrollbars = 1");
			self.theWindow.focus();
		}catch(e){
			if (options[2] == "ajax" || options[2] == "json") {
				self.showPopUp(obj);
			}else{
				alert("Please Enable popups in your browser");
			}
		}	
	},
	getSize: function(){
		var self 			= displayPopUp;
		var windowSize 		= window.getSize();
		var scrollSize		= window.getScroll();
		var bodySize 		= $(document.body).getSize();
		var bodyScroll		= $(document.body).getScrollSize();
		self.contentLeft 	= ((windowSize.x)/2) - (self.width/2) + scrollSize.x;
		self.contentTop 	= (windowSize.y/2)-(self.height/2)    + scrollSize.y;
		self.bodyWidth 		= (bodyScroll.x);
		self.bodyHeight 	= (bodyScroll.y);
	},
	hideBackground: function(){
		var self 			= displayPopUp;
		self.getSize();
		
		// hide select Boxes
		try{
			if(Browser.Engine.trident && Browser.Engine.version < 5) {
				$(document.body).getElements('select').each(function(item,index){
					item.style.display = "none";
				});
			}
		}catch(e){}
		// hide image loader
		try{
			$$('.uploaderWrapper').each(function(item,index){
				item.style.display = "none";									 
			});
		}catch(e){}
		if (self.hideBG == null) {
			self.hideBG = new Element('div', {
				'styles': {	'top'	: "0px", 
							'left'	: "0px",
							'height': self.bodyHeight 	+ "px",
							'width'	: self.bodyWidth 	+ "px"},
				'class': 'hideBG',
				'id': 'hideBG'
			});
			self.hideBG.setOpacity(0.7);
			self.hideBG.addEvent("click",displayPopUp.popupClose);
			$(self.hideBG).injectInside($(document.body));
			window.addEvent('resize', displayPopUp.resize);
			window.addEvent('scroll', displayPopUp.resize);
			$$('select').each(function(item,index){
				item.setOpacity(0);
			});
			displayPopUp.displayContent();
		}else{
			if(self.callType =="ajax" || self.callType=="json"){
				self.closeContent();
				self.displayContent();
			}
		}
	},
	resize: function(fx){									// resize function - to control the moving functions
		var self=displayPopUp;							// It is possible to add a delay to this call here
		if (self.hideBG != null){
			if (self.canMove == true) {
				self.moveit();
			}
		}
	},
	moveit: function(){									// Function to move the popup to the middle of the page
		var self 	= displayPopUp;
		if(self.isAdmin){
			self.getSize();									// Get the new size of the document
			displayPopUp.canMove = false;
			if(self.contentTop < 0){
				self.contentTop = 0;
			}
			if(self.contentLeft < 0){
				self.contentLeft = 0;
			}
			self.hideBG.style.height=self.bodyHeight + "px";
			self.hideBG.style.width=self.bodyWidth + "px";
			var top =0;
			var left = 0;
			if(self.height < self.bodyHeight){
				top = self.contentTop;
			}
			if(self.width < self.bodyWidth){
				left = self.contentLeft;
			}
			if(self.fxMoveLeft){
				self.fxMoveLeft.cancel();	
			}
			self.fxMoveLeft = new Fx.Morph(self.content,{duration: 'long',onComplete: function(){
				displayPopUp.canMove = true;
				displayPopUp.resize();
			}});
			self.fxMoveLeft.start({
				'left': left,
				'top' : top
			});
		}
	},
	closeContent: function(){
		var self = displayPopUp;
			if (self.callType == "image") {
				$(self.popImage).destroy();
				$(self.popImageNav).destroy();
			}else {
				// check if Tiny MCE is being used on the page and then remove it
				$(self.popText).getElements('textarea').each(function(item,index){
					if(item.getStyle("display")=="none"){
						try{
							if($(item).get("id")!= ""){
								tinyMCE.execCommand('mceRemoveControl', false, $(item).get("id"));
							}else{
								tinyMCE.execCommand('mceRemoveControl', false, $(item));
							}
						}catch(e){}
					}
				});
				$(self.popText).empty();
				$(self.popText).destroy();
			}
			$(self.popTopClose).removeEvent('click', displayPopUp.popupClose);
			$(self.popTopClose).removeEvent('mouseover', function(){
				this.className = "popOver";
			});
			$(self.popTopClose).removeEvent('mousedown', function(){
				this.className = "popDown";
			});
			$(self.popTopClose).removeEvent('mouseout', function(){
				this.className = "popClose";
			});
			$(self.popTopClose).destroy();
			$(self.popTop).destroy();
			$(self.content).destroy();
			self.content 	= null;
			self.popImage 	= null;
			self.popText 	= null;
			self.popTop 	= null;
			self.popBtm 	= null;
			self.popTopClose= null;
	},
	displayContent: function(){							// Function to display the popup content for the page
		var self = displayPopUp;
		var temp = "";
		self.content = new Element('div', {
				'id': "popContent",
				'class': "popContent",
				'styles': {
					'position': "absolute",
					'top': self.contentTop + "px",
					'left': self.contentLeft + "px",
					'height': "0px",
					'width': "0px"
				}
			});
			self.popTop = new Element('div', {
				'id': "popTop",
				'class': "popTop"
			});
			var theText = self.caption.split(';');
			var popInner = new Element('div', {
				'id': "popCaption",
				'class': "popCaption",
				'html' : theText[0]
			});
			self.popTopClose = new Element('div', {
				'id': "popClose",
				'class': "popClose",
				'html' : "close"
			});
			$(popInner).injectInside(self.popTop);
			$(self.popTopClose).addEvent('click', displayPopUp.popupClose);
			$(self.popTopClose).addEvent('mouseover', function(){
				this.className = "popOver";
			});
			$(self.popTopClose).addEvent('mousedown', function(){
				this.className = "popDown";
			});
			$(self.popTopClose).addEvent('mouseout', function(){
				this.className = "popClose";
			});
			$(self.content).setOpacity(0);
			$(self.content).injectInside($(document.body));
			$(self.popTop).injectInside(self.content);
			$(self.popTopClose).injectInside(self.popTop);
			var adjustedHeight = false;
			var imageSrc = "";
			if (self.callType == "image") {
				if ($defined(self.imagePreloader[self.imageLibrary])) {
					var tempArray = self.imagePreloader[self.imageLibrary];
					tempArray.each(function(item, index){
						if (item.image.src == self.URL) {
							self.imageNum = index;
						}
					});
					self.popImageNav = new Element('div', {
						'class': "popImageNavContainer",
						'id': "popImageNavContainer",
						'html' : "<div id='popImageNum' class='popImageNum'>Image " +(self.imageNum + 1) +" of " +
								self.imagePreloader[self.imageLibrary].length +
								"</div><div class='popImageNav' id='popImageNav'>" +
								"<a href='javascript: void(0)' id='popImageBack' class='popImageBack'" +
								" title='" + self.imageArrayName + "'>Back</a>" +
								" | <a href='javascript: void(0);' id='popImageNext' class='popImageNext' title='" +
								self.imageLibrary + "'>Next</a></div>"
					});	
					imageSrc = self.imagePreloader[self.imageLibrary][self.imageNum]['image'].src;
				}else{
					self.popImageNav = new Element('div');
					imageSrc = self.URL;
					adjustedHeight = true;
				}
				self.popImage = new Element('div', {
					'class': "popImage",
					'id': "popImage",
					'styles': {
						'height': 'auto',
						'width':  parseInt(self.width)  + "px",
						'text-align': 'center'
					}
				});
				self.popImage.addEvent("click",displayPopUp.popupClose);
				var imageCenterTrick = "<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
				"<tr><td align='center' valign='top' id='popImageContainer'><img src='../js/" +
				imageSrc +
				"' alt='" +
				self.caption +
				"' border='0' class='thePopImage' id='thePopImage'/></td></tr>";
				
				if($defined(theText[1])){
					imageCenterTrick += "<tr><td class='popTextArea' id='popTextArea'><div>"+ theText[1]  +"</div><div class='second'> </div></td></tr></table>"; 
				}else{
					imageCenterTrick += "</table>";
				}
				
				$(self.popImage).innerHTML = imageCenterTrick;
				$(self.popImageNav).injectInside(self.content);
				$(self.popImage).injectInside(self.content);
				try{
					$('popImageBack').addEvent('click', function(){
						displayPopUp.swapImage("back");
					});
					$('popImageNext').addEvent('click', function(){
						displayPopUp.swapImage("next");
					});
				}catch(e){}
				var height = parseInt(self.height) + $(self.popTop).getSize().y
				if($('popTextArea')){
					var height = parseInt(self.height) + $(self.popTop).getSize().y + $('popTextArea').getSize().y;
				}
				if(Browser.Engine.trident){				 // If Is IE
					if(adjustedHeight){
						self.height = parseInt(height) + 8;
					}else{
						self.height = parseInt(height) + 20;
					}
				}
				self.width = parseInt(self.width) + 14;
				if(adjustedHeight){
					self.height = parseInt(height) + 14;
				}else{
					self.height = parseInt(height) + 36;
				}
			}else {
				var height = $(self.popTop).getSize().y;
				if(Browser.Engine.trident){				 // If Is IE
					height =  20;
				}
				self.popText = new Element('div', {
					'id': "popText",
					'class': "popText popAnimation",
					'styles': {
						'width': (self.width - 14),
						'height': (self.height - height - 14)
					}
				});
				if (self.callType != "ajax" && self.callType != "json") {
					if ($defined($(self.callType))){						
						var clone = $(self.callType).clone();   // Get all the elements
						$(clone).injectInside(self.popText);
						$(clone).removeClass("hide");
					}
					$(self.popText).className="popText"; 
				}else {
					if (self.callType == "json") {
						if (self.imageLibrary != null) {
							try{
								self.jsonFunction = eval(self.imageLibrary);
							}catch(e){}
						}
						self.Ajax = new Request.JSON({
							onSuccess: function(response){
								displayPopUp.showJsonResult(response);
								$(displayPopUp.popText).className = "popText"; // Remove Animation Effect
							},
							onFailure: function(){
								$(displayPopUp.popText).className = "popText"; // Remove Animation Effect
								$(displayPopUp.popText).removeEvents();
								var ElmResponse = new Element("div",{
										"id": "ajaxResponseHTML",
										"html" : "Json Call Failed",
										"class" : "error"
									});
								$(ElmResponse).injectInside($(displayPopUp.popText));
							},
							onException : function(){
								$(displayPopUp.popText).className = "popText"; // Remove Animation Effect
								var ElmResponse = new Element("div",{
										"id": "ajaxResponseHTML",
										"html" : "Sorry - An Exception has occured",
										"class" : "error"
									});
								$(ElmResponse).injectInside($(displayPopUp.popText));
							}
						}).get(self.URL);
					}
					if (self.callType == 'ajax') {
						self.Ajax = new Request.HTML({
							onSuccess: function(response,elements,html,scripts){
								displayPopUp.showAjaxResult(response,elements,html,scripts);
							},
							onFailure: function(){
								$(displayPopUp.popText).className = "popText"; // Remove Animation Effect
								var ElmResponse = new Element("div",{
										"id": "ajaxResponseHTML",
										"html" : "Sorry, The Request has failed. Please Try Again Later",
										"class" : "error"
									});
								$(ElmResponse).injectInside($(displayPopUp.popText));
							},
							onException : function(){
								$(displayPopUp.popText).className = "popText"; // Remove Animation Effect
								var ElmResponse = new Element("div",{
										"id": "ajaxResponseHTML",
										"html" : "Sorry, An Exception has occured for the request",
										"class" : "error"
									});
								$(ElmResponse).injectInside($(displayPopUp.popText));
							},
							evalScripts: false
						}).get(self.URL);
					}
				}
			}
			//self.getSize();
			//self.moveit();
			var tmpImage = "";
			if($('popImage')){
				tmpImage = $('popImage').style.backgroundImage;
				$('popImage').style.backgroundImage = "none";
			}
			$('popContent').style.overflow = "hidden";
			$('popClose').style.display = "none";
			var fxOpen = new Fx.Morph('popContent',{'duration': 500,onComplete: function(){
				if($defined(self.popText)){
					$(self.popText).injectInside(self.content);
				}
				$('popContent').style.overflow = "visible";
				$('popClose').style.display = "block";
				if($('popImage')){
					$('popImage').style.backgroundImage = tmpImage;
				}
			}});
			var theTop  = self.contentTop;
			var theLeft = self.contentLeft;
			fxOpen.start({
				'opacity':[0,1],
				'top'    :[(self.fromTop - 100),theTop],
				'left'	 :[(self.fromLeft-50),theLeft],
				'height': [5,displayPopUp.height],
				'width':  [5,displayPopUp.width]});	
	},
	showJsonResult: function(response){
		var self = displayPopUp;
		$(self.popText).className = "popText";
		if (self.jsonFunction != null) {
			self.jsonFunction(response);
		}
	},
	showAjaxResult: function(response,elements,html,scripts){
		var self = displayPopUp;
		if($(self.popText)){
			$(self.popText).removeEvents();
			var ElmResponse = new Element("div",{
						"id": "ajaxResponseHTML",
						"html" : html
					});
			$(ElmResponse).setOpacity(0);
			$(ElmResponse).injectInside($(self.popText));
		}
		displayPopUp.scripts = scripts;
		displayPopUp.evalScripts.delay(1000); 
	},
	evalScripts: function(){
		try{
			eval(displayPopUp.scripts);
		}catch(e){}
		try{validate.init();}catch(e){}
		try{editInPlace.init();}catch(e){}
		try{displayPopUp.init();}catch(e){}
		try{DisplayDate.init();}catch(e){}
		if(displayPopUp.popText){
			$(displayPopUp.popText).removeClass("popAnimation");
			var myFx= new Fx.Tween($('ajaxResponseHTML'));
			myFx.start('opacity',1);
		}
		try{
			$(displayPopUp.popText).getElements('input[type=file]').each(function(item,index){
				var newup = new uploader(item);
				uploaders.push(newup);								// Add uploader to the upload array								  
			});
		}catch(e){}
	},
	swapImage: function(direction){
		var self 		= displayPopUp;
		var nextImage 	= (direction=="next")? self.imageNum+1 : self.imageNum-1;
		if(!$defined(self.imagePreloader[self.imageLibrary][nextImage])){
			if(nextImage > 0){
				nextImage = 0;
			}else{
				nextImage = self.imagePreloader[self.imageLibrary].length -1;
			}
		}
		self.imageNum 	= nextImage;
		var values		= self.imagePreloader[self.imageLibrary][self.imageNum]['obj'];//.split(",");
		if(values.contains("#")){
			values= values.split("#");	
		}else{
			values= values.split(",");					// Split the REL Tag
		}
		self.width		= (parseInt(values[3])>0)?parseInt(values[3]): self.width;
		self.height 	= (parseInt(values[4])>0)?parseInt(values[4]): self.height;
		self.width		= self.width + 14;
		var theText 	= values[0].split(';');
		$('popCaption').set("html",theText[0]);
		//$('popTextArea').set("html",theText[1]);
		self.fadeout(theText[1]);
	},
	fadeout: function(tmpText){
		var fx = new Fx.Tween('popImage',{duration: 'short', onComplete: function(){
				if($(displayPopUp.content)){
					var self 	  = displayPopUp;
					$('popImageNum').innerHTML = "Image " + ((self.imageNum+1)+" of "+self.imagePreloader[self.imageLibrary].length);
					$('thePopImage').destroy();																								// Removes the image								
					$(self.imagePreloader[self.imageLibrary][self.imageNum]['image']).injectInside($('popImageContainer'));				// Inserts the new image
					if($('popTextArea')){
						$('popTextArea').set("html",tmpText);																					// Set the text
					}
					displayPopUp.fadein();
				}
			}
		}).start('opacity',0);
	},
	fadein: function(){
		var self 	  = displayPopUp;
		var durationnum = 1500;
		var height = self.height;
		if($('popTextArea')){
			height += 2.5 * parseInt($('popTextArea').getSize().y);
		}
		if($(self.content)){
			if($(self.content).getSize().x > (self.width-10) && $(self.content).getSize().y > (self.height-10) && $(self.content).getSize().x < (self.width+10)){
				durationnum = 'short';
			}
			var sizeFx = new Fx.Morph($(self.content),{duration: durationnum,onComplete: function(){
					if($(displayPopUp.content)){
						var fx = new Fx.Tween($('popImage'),{duration: 'short'}).start('opacity',1);
					}
				}}).start({
					'width'  : (self.width) + "px",
					'height' : (height)+ "px"
			});
			self.popImage.style.width = (self.width - 14) + "px";
			height = 0;
			if($('popTextArea')){
				height = 2.5 * parseInt($('popTextArea').getSize().y);
			}
			self.popImage.style.height= (self.height - $(self.popTop).getSize().y - 14 - 22) + height +  "px";
			self.getSize();
			self.resize();
		}
	},
	popupClose: function(){
		var self = displayPopUp;
		if($('popImage')){
			$('popImage').style.backgroundImage = "none";
		}
		$('popClose').style.display = "none";
		$('popContent').style.overflow = "hidden";
		$('hideBG').set('opacity',0);
		var fxContent = new Fx.Morph($('popContent'),{'duration':300,onComplete: displayPopUp.popupRemove}).start({
			'opacity':0,
			'width': 5,
			'height': 5,
			'top' : self.fromTop - 100,
			'left': self.fromLeft - 50
		});
		if(self.Ajax){
			self.Ajax.cancel();
		}
	},
	popupRemove: function(){
		var self 	= displayPopUp;
		$(self.hideBG).destroy();
		$$('select').each(function(item,index){
			item.setOpacity(1);
		});
		self.closeContent();
		try{
			if(Browser.Engine.trident && Browser.Engine.version < 5) {
				$(document.body).getElements('select').each(function(item,index){
					item.style.display = "inherit";
				});
			}
		}catch(e){}
		// hide image loader
		try{
			$$('.uploaderWrapper').each(function(item,index){
				item.style.display = "inherit";									 
			});
		}catch(e){}
		self.hideBG		= null;
	},
	unloader: function(){
		if(displayPopUp.Ajax){
			displayPopUp.Ajax.cancel();			// Stop loading requests.	
		}
	}
};
window.addEvent('domready', displayPopUp.init);
window.addEvent('beforeunload',displayPopUp.unloader);
