function openGalleryEntry(nr, width, height, slideshow) {
	var docURL = document.URL;
	var pos = docURL.indexOf("?OpenDocument");
	if(pos != "-1") {
		docURL = docURL.substring(0, pos);
	}
	var entryURL = docURL + "?OpenDocument&nr=" + nr;
	if (slideshow) entryURL += "&slideshow";
	var windowWidth =  width + 30;
	var windowHeight = height + 130;
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;
	var parameters = "width=" + windowWidth + ", height=" + windowHeight + ", left=" + windowX + ", top=" + windowY + ", location=no, status=no, toolbar=no, menubar=no, dependent=yes";
	var entryWindow = window.open(entryURL, "entry", parameters);
	if (entryWindow) entryWindow.focus();		
}

function openGalleryEntryEdit(nr, width, height, slideshow) {
	var entryURL= "web/" + refUNID + "?OpenDocument&nr=" + nr;	
	var windowWidth =  width + 20;
	var windowHeight = height + 130;
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;
	var parameters = "width=" + windowWidth + ", height=" + windowHeight + ", left=" + windowX + ", top=" + windowY + ", location=no, status=no, toolbar=no, menubar=no, dependent=yes";
	var entryWindow = window.open(entryURL, "entry", parameters);
	if(entryWindow) entryWindow.focus();	
}


function openZip(title) {
	var docURL = document.URL;
	var pos = docURL.indexOf("index.php?OpenDocument");
	if(pos != "-1") {
		docURL = docURL.substring(0, pos);
	}
	var entryURL = docURL + title;
	window.location.href = entryURL;
}


function downloadOriginalImage(fileName) {
	var docURL = document.URL;
	var pos = docURL.indexOf("index.php?OpenDocument");
	if(pos != "-1") {
		docURL = docURL.substring(0, pos);
	}
	var downloadURL = docURL + fileName;
	window.location.href = downloadURL;
}

function resizeWindow(width, height) {
	var windowWidth = width + 30;
	var windowHeight = height + 130;
	window.resizeTo(windowWidth, windowHeight);

	/*alert(window.outerHeight);
	alert(window.innerHeight);
	alert(document.documentElement.clientHeight);
	
	alert(document.body.clientHeight);
	alert(document.body.offsetHeight);
	
	self.resizeTo(width, height);
alert(self.document.body.clientWidth);
alert(self.innerWidth);
alert(self.document.body.clientHeight);	
alert(self.window.innerHeight);	

alert(width - self.document.body.clientWidth + 10);
	alert(height - self.document.body.clientHeight + 110);
	
	
	
	self.resizeBy(width - self.document.body.clientWidth + 10, height - self.document.body.clientHeight + 110);
	*/
}

function resizeMoveWindow(width, height) {
	//alert(document.images["imgend"].offsetTop);
	var windowWidth =  width + 30;
	var windowHeight = height + 130;
	//alert(windowHeight);
	//alert(windowHeight);
	//alert(document.images["imgend"].offsetTop);
	
	if(document.images["imgend"].offsetTop) {
		while(document.images["imgend"].offsetTop + 50 > windowHeight) {
			windowHeight += 10;
		}
	}
	//alert(windowHeight);
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;
	window.resizeTo(windowWidth, windowHeight);
	window.moveTo(windowX, windowY);	
}


//Slideshow
var slideshowTimer;
var isSlideshowRunning;
var slideshowNextURL;
var beginNr;
var prevNr;
var nextNr;
var endNr;
var slideshowTimeout;

function galleryGoto(dest) {
	switch (dest) {
	case "begin":
		nr = beginNr;
		break;
	case "prev":
		nr = prevNr;
		break;
	case "next":
		nr = nextNr;
		break;
	case "end":
		nr = endNr;
		break;
	}

	var docURL = document.URL;
	var pos = docURL.indexOf("&nr");
	if(pos != "-1") {
		docURL = docURL.substring(0, pos);
	}
	var entryURL = docURL + "&nr=" + nr;	
	self.location.href = entryURL;
}

function slideshowNext() {
	var docURL = document.URL;
	var pos = docURL.indexOf("&nr");
	if(pos != "-1") {
		docURL = docURL.substring(0, pos);
	}
	var entryURL = docURL + "&nr=" + nextNr +"&slideshow";
	if(nextNr != '') self.location.href = entryURL;	
}

function continueSlideshow() {
		slideshowTimer = window.setTimeout("slideshowNext()", slideshowTimeout);
}

function startStopSlideshow() {
	if(isSlideshowRunning) {
		window.clearTimeout(slideshowTimer);
		document.getElementById("startstop").innerHTML = startLabel;
	}
	else {	
		slideshowTimer = window.setTimeout("slideshowNext()", slideshowTimeout);
		document.getElementById("startstop").innerHTML = stopLabel;
	}
	isSlideshowRunning = !isSlideshowRunning;
}

function startSlideshow() {
	openGalleryEntry(1, 640, 480, true);
}
