var overlay = null;
var overlay_half = null;
var actualPhoto = 0;

function galleryInit() {
	setOverlayDimensions();

	return true;
}

function setOverlayDimensions() {
	if(document.getElementById("overlay")) {
		overlay = document.getElementById("overlay");

		overlay.style.height = (document.documentElement.scrollHeight + 80) + "px";
		overlay.style.width = (document.documentElement.scrollWidth) + "px";
		overlay.style.display = "none";
	}

	if(document.getElementById("overlay_half")) {
		overlay_half = document.getElementById("overlay_half");

		overlay_half.style.height = (document.documentElement.scrollHeight + 80) + "px";
		overlay_half.style.width = (document.documentElement.scrollWidth) + "px";
		overlay_half.style.display = "none";
	}

	return true;
}

function openPhoto(id) {

	actualPhoto = id;

	overlay.style.display = "block";
	overlay_half.style.display = "block";

	var images = overlay.getElementsByTagName("img");

	for(i = 0; i < images.length; i++) {
		images[i].style.display = "none";
	}

	var image = document.getElementById("image_" + id);

	image.style.display = "block";
	image.style.marginTop = (document.documentElement.scrollTop + 10) + "px";

	document.getElementById("gallery_navigation").style.width = image.width + "px";

	return true;
}

function nextPhoto() {
	if(actualPhoto < overlay.getElementsByTagName("img").length - 1) {
		openPhoto(actualPhoto + 1);
	} else {
		openPhoto(0);
	}

	return true;
}

function prevPhoto() {
	if(actualPhoto > 0) {
		openPhoto(actualPhoto - 1);
	} else {
		openPhoto(overlay.getElementsByTagName("img").length - 1);
	}
}

function closePhoto() {

	overlay.style.display = "none";
	overlay_half.style.display = "none";

	return true;
}