function JQueryPopup(containerId, triggerOpener) {
	this._popupStatus = 0;
	this._background  = containerId + " .background";
	this._contentDiv 	= containerId + " .content";
	this._opener			= triggerOpener;
	this._closer			= containerId + " .close";
}

JQueryPopup.prototype._popupStatus;
JQueryPopup.prototype._background;
JQueryPopup.prototype._contentDiv;
JQueryPopup.prototype._opener;
JQueryPopup.prototype._closer;

//loads popup only if it is disabled
JQueryPopup.prototype.loadPopup = function() {
	if(this._popupStatus==0){
		$(this._background).css({
			"opacity": "0.7"
		});
		$(this._background).fadeIn("slow");
		$(this._contentDiv).fadeIn("slow");
		this._popupStatus = 1;
	}
}

//disables popup only if it is enabled
JQueryPopup.prototype.disablePopup = function() {
	if(this._popupStatus==1){
		$(this._background).fadeOut("slow");
		$(this._contentDiv).fadeOut("slow");
		this._popupStatus = 0;
	}
}

//request data for centering
JQueryPopup.prototype.centerPopup = function() {
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(this._contentDiv).height();
	var popupWidth = $(this._contentDiv).width();
	//centering
	$(this._contentDiv).css({
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6

	$(this._background).css({
		"height": windowHeight
	});
}

JQueryPopup.prototype.activate = function() {
	$(document).ready(function(){
		//LOADING POPUP
		//Click the button event!
		$(this._opener).click(function(){
			this.centerPopup();
			this.loadPopup();
		});
				
		//CLOSING POPUP
		//Click the x event!
		$(this._closer).click(function(){
			this.disablePopup();
		});
		//Click out event!
		$(this._background).click(function(){
			this.disablePopup();
		});
		//Press Escape event!
		$(document).keypress(function(e){
			if(e.keyCode==27 && this._popupStatus==1){
				this.disablePopup();
			}
		});
	});
}

function popActivate(pop) {
	$(document).ready(function(){
		//LOADING POPUP
		//Click the button event!
		$(pop._opener).click(function(){
			pop.centerPopup();
			pop.loadPopup();
		});
				
		//CLOSING POPUP
		//Click the x event!
		$(pop._closer).click(function(){
			pop.disablePopup();
		});
		//Click out event!
		$(pop._background).click(function(){
			pop.disablePopup();
		});
		//Press Escape event!
		$(document).keypress(function(e){
			if(e.keyCode==27 && pop._popupStatus==1){
				pop.disablePopup();
			}
		});
	});
}
