/*class*/ function Popup() 
{
	this.popupId = "";
	this.isOpened = false;
	
	this.viewportX = 0;
	this.viewportY = 0;
	this.viewportWidth = 0;
	this.viewportHeight = 0;
	
	this.setPopupId = function(id)
	{
		this.popupId = "#" + id;
	}
	
	this.openPopup = function() 
	{
		if (!this.isOpened)
		{
			this.positionPopup();
			
			$(".popup-background").css({"opacity": "0.8"});
			$(".popup-background").fadeIn("fast");
			$(this.popupId).fadeIn("fast");
			this.isOpened = true;
		}
	}
	
	this.closePopup = function()
	{
		if (this.isOpened)
		{
			$(".popup-background").fadeOut("fast");
			$(this.popupId).fadeOut("fast");
			this.isOpened = false;
		}
	}
	
	this.centerPopup = function()
	{
		this.initializeViewport();
		
		var popupHeight = $(this.popupId).height();
		var popupWidth = $(this.popupId).width();
		
		$(this.popupId).css({
			"position": "absolute",
			"top": this.viewportHeight/2 - popupHeight/2 + this.viewportY,
			"left": this.viewportWidth/2 - popupWidth/2 + this.viewportX
		});

		$(".popup-background").css({
			"height": this.viewportHeight
		});
	}

        this.positionPopup = function()
	{
		this.initializeViewport();
		
		var popupHeight = $(this.popupId).height();
		var popupWidth = $(this.popupId).width();
		
		$(this.popupId).css({
			"position": "absolute",
			"top": 100,
			"left": this.viewportWidth/2 - popupWidth/2 + this.viewportX
		});

		$(".popup-background").css({
			"height": this.viewportHeight
		});
	}
	
	this.initializeViewport = function() 
	{
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		if (typeof window.innerWidth != 'undefined')
		{
			this.viewportX = window.pageXOffset
			this.viewportY = window.pageYOffset;
            this.viewportWidth = window.innerWidth;
            this.viewportHeight = window.innerHeight;
		}
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		else if (typeof document.documentElement != 'undefined' && 
				typeof document.documentElement.clientWidth != 'undefined' && 
				document.documentElement.clientWidth != 0)
		{
			this.viewportX = document.documentElement.scrollLeft;
			this.viewportY = document.documentElement.scrollTop;
			this.viewportWidth = document.documentElement.clientWidth;
			this.viewportHeight = document.documentElement.clientHeight;
		}
		// older versions of IE
		else 
		{
			this.viewportWidth = document.getElementsByTagName('body')[0].clientWidth;
			this.viewportHeight = document.getElementsByTagName('body')[0].clientHeight;
		}
	}
	
}
