iOpenedPhoto = 0;

function showBigPhoto(iID, sExt)
{
	oDarkener = document.getElementById("darkener");

	iDocWidth = document.body.offsetWidth;
	iDocHeight = document.body.offsetHeight;

	iScreenHeight = document.documentElement.clientHeight;

	if(iScreenHeight > iDocHeight) iDocHeight = iScreenHeight;

	oDarkener.style.width = iDocWidth + 'px';
	oDarkener.style.height = iDocHeight + 'px';

	var oPopin = document.createElement("div");
	oPopin.id = 'popin';
	document.body.appendChild(oPopin);

	oPopin.style.left = ((iDocWidth - 320) / 2) + 'px';
	oPopin.style.top = (((iScreenHeight - 320) / 2) + getScrollPos()) + 'px';

	if(iOpenedPhoto) iID = iOpenedPhoto;

	oPopin.style.backgroundImage = 'url(/shared/images/custom/loading.gif)';

	loadImage(iID, sExt);
}

function checkImageLoaded()
{
	oImg = document.getElementById('newmainimage');
	if(oImg.complete)
	{
		iImageWidth = oImg.width;
		iImageHeight = oImg.height;

		if(iImageWidth < 500) iImageWidth = 500;

		oPopin = document.getElementById("popin");
		iDocWidth = document.body.offsetWidth;
		iScreenHeight = document.documentElement.clientHeight;

		oPopin.style.left = ((iDocWidth - (iImageWidth + 20)) / 2) + 'px';
		oPopin.style.top = (((iScreenHeight - (iImageHeight + 40)) / 2) + getScrollPos()) + 'px';
		oPopin.style.width = (iImageWidth + 20) + 'px';
		oPopin.style.height = (iImageHeight + 40) + 'px';
		oImg.style.visibility = 'visible';
	}
	else
	{
		setTimeout('checkImageLoaded()', 50);
	}
}

function loadImage(iID, sExt)
{
	if(!iID) return false;

	oPopin = document.getElementById("popin");

	sHTML = '<img src="/content/image/images/original/'+iID+'.'+sExt+'" alt="" id="newmainimage" style="visibility:hidden;" onclick="closePhoto();"  />';
//	sHTML += '<div class="kruizert" onclick="closePhoto();"></div>';

	oPopin.innerHTML = sHTML;

	setTimeout('checkImageLoaded()', 50);
}

function getScrollPos()
{
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
		    ScrollTop = window.pageYOffset;
		else
		    ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return ScrollTop;
}

function closePhoto()
{
	oDarkener = document.getElementById("darkener");

	oDarkener.style.width = '0px';
	oDarkener.style.height = '0px';

	oPopin = document.getElementById("popin");
	if(oPopin) document.body.removeChild(oPopin);
}
