function setupAjaxPopUp ()
{
	popups = document.getElementsByClassName('openPopUpBox');
	for(i=0;i<popups.length;i++)
	{
		popups[i].onclick = function ()
		{
			openPopUpBox(this.getAttribute('popupImage'));
		}
	}	
}


function openPopUpBox (img)
{
	variables = "bild=" + img;
	new Ajax.Updater('container', '/extensions/templates/popup.php', {asynchronous:true, parameters:variables, onComplete: function () { openPopUpLightbox(); } });
}

function openPopUpLightbox ()
{
	var arrayPageSize = getPageSize();
	$('popupoverlay').style.width = arrayPageSize[0] + "px";
	$('popupoverlay').style.height = arrayPageSize[1] + "px";
	
	new Effect.Appear('popupoverlay', {from: 0.0, to: 0.8});
	new Effect.Appear('popuplightbox', {from: 0.0, to: 0.999});
	
	$('popupoverlay').onclick = function() { closePopUpLightbox(); }
}

function closePopUpLightbox ()
{
	new Effect.Appear('popupoverlay', {from: 0.8, to: 0.0, afterFinish: function () { $('popupoverlay').style.display = 'none'; } });
	new Effect.Appear('popuplightbox', {from: 0.999, to: 0.0, afterFinish: function () { $('popuplightbox').style.display = 'none'; } });
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
