/**
 * Page
 */
function lib_Popup()
{
	/**
	 * Open popup window
	 *
	 * @param integer nr
	 * @param integer width
	 * @param integer height
	 */
	this.openPopUp = function(nr, width, height)
	{
		/* Background Filter */

		//set size for background filter
		var docSize = this.getDocumentSize();
		document.getElementById('backgroundFilter'+nr).style.height = docSize.h + 'px';

		//place background filter over background
		document.getElementById('backgroundFilter'+nr).style.display = 'block';

		//remove scrollbars by hiding overflow
		document.body.style.overflow="hidden";


		/* Popup Window */

		//get popup window element
		var popupWindow = document.getElementById('popupWindow'+nr);

		//set dimensions
		popupWindow.style.width = width + 'px';
		popupWindow.style.height = height + 'px';

		//set position (y)
		var y = document.documentElement.scrollTop + 25; //IE + FF
		if(y == 25){y = document.body.scrollTop + 25;}   //Chrome
		popupWindow.style.top = y + 'px';

		//set position (x)
		var x = document.body.clientWidth;
		x = x - width;
		x = parseInt(x / 2);
		popupWindow.style.left = x + 'px';

		//make visible
		popupWindow.style.display = 'block';
	}




	/**
	 * Close popup window
	 *
	 * @param integer nr
	 */
	this.closePopUp = function(nr)
	{
		if(parent.document.getElementById('backgroundFilter'+nr))
		{
			parent.document.getElementById('backgroundFilter'+nr).style.display = 'none';
			parent.document.getElementById('popupWindow'+nr).style.display = 'none';
			parent.document.getElementById('popupWindow'+nr).innerHTML = '';
		}
		else if(document.getElementById('backgroundFilter'+nr))
		{
			document.getElementById('backgroundFilter'+nr).style.display = 'none';
			document.getElementById('popupWindow'+nr).style.display = 'none';
			document.getElementById('popupWindow'+nr).innerHTML = '';
		}

		//return scrollbars by un-hiding overflow
		document.body.style.overflow="visible";
	}




	/**
	 * Get document size
	 */
	this.getDocumentSize = function()
	{
		//get document objects
		var bd = document.body;
		var el = document.documentElement;

		//initialize variables
		var bodyScrollWidth = 0;
		var bodyScrollHeight = 0;
		var bodyOffsetWidth = 0;
		var bodyOffsetHeight = 0;

		var elementScrollWidth = 0;
		var elementScrollHeight = 0;
		var elementOffsetWidth = 0;
		var elementOffsetHeight = 0;

		//set body variables
		if(bd)
		{
			bodyScrollWidth = bd.scrollWidth;
			bodyScrollHeight = bd.scrollHeight;
			bodyOffsetWidth = bd.offsetWidth;
			bodyOffsetHeight = bd.offsetHeight;
		}

		//set element variables
		if(el)
		{
			elementScrollWidth = el.scrollWidth;
			elementScrollHeight = el.scrollHeight;
			elementOffsetWidth = el.offsetWidth;
			elementOffsetHeight = el.offsetHeight;
		}

		//get max width and height
		var width = Math.max(bodyScrollWidth, bodyOffsetWidth, elementScrollWidth, elementOffsetWidth);
		var height = Math.max(bodyScrollHeight, bodyOffsetHeight, elementScrollHeight, elementOffsetHeight);

		//return with and height;
		return {w:width, h:height};
	}
}

