var photoZoomOpen = false;
var photoZoomTimeout = null;

function onClickedPhoto()
{
	openZoomedPhoto(selectedPhoto);
}

function openZoomedPhoto(index)
{
	if (photoZoomOpen)
		return;

	photoZoomOpen = true;

	var docSize = HTMLUtils.getDocumentSize();
	var clientSize = HTMLUtils.getWindowInnerSize();

	var containerElt = document.createElement("div");
	containerElt.id = "photo-zoom-container";
	containerElt.style.position = "absolute";
	HTMLUtils.setElementPos(containerElt, new Point(0, 0));
	HTMLUtils.setElementSize(containerElt, docSize);
	containerElt.style.width = "100%";
	containerElt.onclick = containerElt.onmousedown = closeZoomedPhoto;
	containerElt.style.visibility = "hidden";

	var grayElt = document.createElement("div");
	grayElt.className = "background";
	grayElt.style.position = "absolute";
	HTMLUtils.setElementPos(grayElt, new Point(0, 0));
	HTMLUtils.setElementSize(grayElt, docSize);
	HTMLUtils.setElementOpacity(grayElt, 95);
	grayElt.style.width = "100%";

	var img = document.createElement("img");
	img.id = "photo-zoom-photo";
	img.className = "photo";
	img.align = "absmiddle";
	img.style.position = "absolute";
	img.style.verticalAlign = "middle";
	img.style.left = img.style.top = "-10000px";
	img.src = photoLocation[index - 1];

	moveZoomedPhoto();

	containerElt.appendChild(grayElt);
	containerElt.appendChild(img);

	document.body.appendChild(containerElt);

	if (photoZoomTimeout) clearInterval(photoZoomTimeout);
	photoZoomTimeout = setInterval(moveZoomedPhoto, 100);

	HTMLUtils.animateFading(containerElt, "show", null);
}

function closeZoomedPhoto()
{
	if (photoZoomTimeout)
		clearInterval(photoZoomTimeout);

	var containerElt = document.getElementById("photo-zoom-container");

	if (containerElt)
		containerElt.parentNode.removeChild(containerElt);

	photoZoomOpen = false;
}

function moveZoomedPhoto()
{
	var img = document.getElementById("photo-zoom-photo");
	if (!img) return;

	var containerElt = document.getElementById("photo-zoom-container");
	if (!containerElt) return;

	var imgSize = HTMLUtils.getElementSize(img);
	var clientSize = HTMLUtils.getWindowInnerSize();
	var scrollPos = HTMLUtils.getScrollPos();

	if (imgSize.width < 100 && imgSize.height < 100)
		return;

	var x = Math.round((clientSize.width - imgSize.width) / 2);
	var y = Math.round((clientSize.height - imgSize.height) / 2) + scrollPos.y;

	HTMLUtils.setElementPos(img, new Point(x, y));
}

function onClickedPhotoThumbnail(index, url)
{
	if (index == selectedPhoto)
		return;

	var item = document.getElementById("photo" + selectedPhoto);
	item.className = "";

	item = document.getElementById("photo" + index);
	item.className = "selected";

	selectedPhoto = index;

	document.getElementById("photo-source").src = photoLocation[index - 1];
}

function hideWCSubmitButton()
{
	/*
	var btn = document.getElementById("wc-submit-button");
	if (btn) btn.style.display = "none";
	*/
}


