var g_isSlideshowRunning = false;var g_slideshowTimer;//var g_slideshowTimeout;var g_tabCurrent;var g_imgCurrent;var g_tabBegin;var g_tabPrev;var g_tabNext;var g_tabEnd;var g_imgBegin;var g_imgPrev;var g_imgNext;var g_imgEnd;	var g_slideSrc;var g_slideWidth;var g_slideHeight;var g_slideCaption;var g_slideNr;var g_slideCount;var g_showAtOnce;var g_bigFileName;var g_unid;var g_isNextImageLoaded;  //true, when image is loaded, false, otherwise, is set by preloader imagefunction getCachePreventTime() {	var now = new Date();	return "&rand=" + now.getTime() + escape( Math.round( Math.random() * 10000 ) );}function getNodeValue(obj, tag) {	if (obj.getElementsByTagName(tag)[0].firstChild)		return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;	else		return "&nbsp;";}//is set by preloader image, when it is loaded, with onloadfunction setNextImageIsLoaded() {	//debugAppend('fertig: ' + document.getElementById("galleryimage").src);	g_isNextImageLoaded = true;}//Ajax var xmlHttp = null;function createXMLHttpRequest() { 	if (xmlHttp) xmlHttp.abort();	xmlHttp = null;	/*if (window.ActiveXObject) { 			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 	}	else if (window.XMLHttpRequest) { 		xmlHttp = new XMLHttpRequest(); 	}	var req = false;*/	if(window.XMLHttpRequest){		xmlHttp = new XMLHttpRequest();		if(xmlHttp.overrideMimeType){ xmlHttp.overrideMimeType('text/xml'); }	} 	else if(window.ActiveXObject){		try{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }		catch(e){			try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }			catch(e){}		}	}}function openImageGalleryEntry(tabNr, imgNr) {	g_tabCurrent = tabNr;	g_imgCurrent = imgNr;	var docURL = document.URL;	var pos = docURL.indexOf("?OpenDocument");	if(pos != "-1") {		docURL = docURL.substring(0, pos);	}	var entryURL = replStr(docURL, "/web/", "/webimagegalleryentryxml/") + "?OpenDocument&tab=" + tabNr + "&img=" + imgNr;	getGalleryEntryXML(entryURL);}var incarnationCounter = 0;//open gallery entry for next image, when current one is loadedfunction openImageGalleryEntryWhenLoaded(tabNr, imgNr) {	//debug("jetzt warten");	if (!g_isNextImageLoaded) {		//debugAppend("imgNr: " + String(incarnationCounter++));		//give image some time load		window.setTimeout("openImageGalleryEntryWhenLoaded(" + tabNr + ", " + imgNr + ")", 100);		}	else {		//debug("jetzt ist es da!");		openImageGalleryEntry(tabNr, imgNr);	}}function getGalleryEntryXML(url) {			createXMLHttpRequest();			if (!xmlHttp) {		//showIndeterminate();	}	else {		xmlHttp.onreadystatechange = showGalleryEntryXML;		xmlHttp.open("GET", url + getCachePreventTime(), true);		xmlHttp.send(null);	}}//is called when xmlhttprequest sends resultfunction showGalleryEntryXML() {	var html = "";		var status;	if (xmlHttp.readyState == 4) {			try {      //firefox sometimes throws errors     			status = xmlHttp.status;		}		catch (e) {			status = 404;			/*alert("Network error!\nPlease try later.");            try {            alert("Failure: " +  + xmlHttp.statusText);            }            catch(e) {}*/		}		//result is there		if (status == 200) {     			var response = xmlHttp.responseXML.documentElement;			g_tabBegin = getNodeValue(response, "tabbegin");			g_tabPrev = getNodeValue(response, "tabprev");			g_tabNext = getNodeValue(response, "tabnext");			g_tabEnd = getNodeValue(response, "tabend");			g_imgBegin = getNodeValue(response, "imgbegin");			g_imgPrev = getNodeValue(response, "imgprev");			g_imgNext = getNodeValue(response, "imgnext");			g_imgEnd = getNodeValue(response, "imgend");									g_slideSrc = getNodeValue(response, "src"); 			g_slideWidth = parseInt(getNodeValue(response, "width")); 			g_slideHeight = parseInt(getNodeValue(response, "height")),			g_slideCaption = getNodeValue(response, "caption"),			g_slideNr = getNodeValue(response, "nr"), 			g_slideCount = getNodeValue(response, "count")						g_bigFileName = getNodeValue(response, "bigfilename"); 			g_unid = getNodeValue(response, "unid"); 			//preloading images for slideshow			g_isNextImageLoaded = false;			document.getElementById("imagepreloader").src = g_slideSrc;			if (g_isSlideshowRunning) {				if (g_showAtOnce) {					//called from page, not div, don't wait for image to show					g_showAtOnce = false;					showGalleryEntryAjax();				}				else {											g_slideshowTimer = window.setTimeout("showGalleryEntryAjax()", g_slideshowTimeout);																}			}			else {				showGalleryEntryAjax();			}								}			}}//show gallery entry, information is provided in global variablesfunction showGalleryEntryAjax() {		//g_slideWidth = 640;	//g_slideHeight = 600;	g_slideWidth = g_maximumImageWidth;	g_slideHeight = g_maximumImageHeight;	var shadeborder = 8;	var divWidth = g_slideWidth + 7;  //38;	//var divHeight = height + 20;	var divHeight = g_slideHeight + 72;  //space below image	// magic numbers follow, do not try at home	//var popupWidth = divWidth;	//var popupHeight = divHeight - 36;	var shadeWidth = divWidth + 23;   //56;	var shadeHeight = divHeight + 69;	/*	if (screen.width <= 800) {     	divHeight = 300;          popupHeight = 276;          shadeHeight = 353;	}*/	//showLr("divContent");	//showLr("divContentShade");	//var elmShade = document.getElementById("divContentShade");	var elmPopup = document.getElementById("divLayer");	var elmContent = document.getElementById("divLayerContent");	var elmOverlay = document.getElementById('pageoverlay');	var divX = g_pageWidth / 2 - divWidth / 2;	//var divY = Math.round( (viewportGetHeight() - divHeight) / 2 ) + viewportGetScrollY();	var divAllHeight = (g_slideHeight + 127);	var divY = Math.round( (viewportGetHeight() - divAllHeight + viewportGetScrollY()) / 2);  //107 = space below image + padding-top to image	//debug("divY: " + String(divY));	if (divX < 0) { divX = 0; }	if (divY < 0) { divY = 0; }	/*elmShade.style.left = (divX - shadeborder) + "px";	elmShade.style.top = (divY - shadeborder) + "px";	elmShade.style.width = shadeWidth + "px";	elmShade.style.height = shadeHeight + "px";*/	elmPopup.style.left = divX + "px";	elmPopup.style.top = divY + "px";	elmPopup.style.width = divWidth + "px";	elmPopup.style.height = divHeight + "px";	elmContent.style.width = g_slideWidth + "px";	elmContent.style.height = g_slideHeight + "px";	document.getElementById("divLayerTitle").style.width = (g_slideWidth - 1) + "px";	document.getElementById("closeButtonDivLayer").style.left = (g_slideWidth - 7) + "px";	//document.getElementById("popupDivTitle").innerHTML = "<img src=\"" + layerTitleImg + "\" alt=\"" + layerTitle + "\">";	//g_openpopupDiv = sUrl;	document.getElementById("galleryimage").src = document.getElementById("imagepreloader").src; //g_slideSrc;	//document.getElementById("galleryimage").style.width = String(g_slideWidth) + "px";	//document.getElementById("galleryimage").style.height = String(g_slideHeight) + "px";	//document.getElementById("gallerytable").style.width = String(g_slideWidth + 2) + "px";	//document.getElementById("gallerytableinfo").style.width = String(g_slideWidth + 2) + "px";	//document.getElementById("gallerysp").style.width = String(g_slideWidth - 138) + "px";		document.getElementById("gallerycaption").innerHTML = g_slideCaption;	document.getElementById("gallerynrofcount").innerHTML = "(" + g_slideNr + "/" + g_slideCount + ")";	if (g_imgBegin == "-1") document.getElementById("gallerybegin").style.visibility = "hidden";	else document.getElementById("gallerybegin").style.visibility = "visible";	if (g_imgPrev == "-1") document.getElementById("galleryprev").style.visibility = "hidden";	else document.getElementById("galleryprev").style.visibility = "visible";	if (g_imgNext == "-1") document.getElementById("gallerynext").style.visibility = "hidden";	else document.getElementById("gallerynext").style.visibility = "visible";	if (g_imgEnd == "-1") document.getElementById("galleryend").style.visibility = "hidden";	else document.getElementById("galleryend").style.visibility = "visible";	if (g_imgNext == "-1") document.getElementById("startstop").src = "/icons/ecblank.gif";	else document.getElementById("startstop").src = g_startStopLabel;	elmOverlay.style.display = "block";		elmPopup.style.display = "block";	//elmShade.style.display = "block";	elmContent.style.display = "block";	//debug("g_slideSrc: " + g_slideSrc);	//debugAppend("g_isNextImageLoaded: " + String(g_isNextImageLoaded));	if (g_isSlideshowRunning) {		if(g_imgNext != "-1") {					//if slideshow is running and current image is not the last in the slideshow open the next one			//if current image is already loaded, get the next one				if (g_isNextImageLoaded) {						//debugAppend("weiter");				openImageGalleryEntry(g_tabNext, g_imgNext);										}			else {				//debugAppend("warten!!!!!!");				openImageGalleryEntryWhenLoaded(g_tabNext, g_imgNext)			}		}		else {			//no more images, stop slideshow, so it is also stopped when jumped to another entry			g_startStopLabel = g_startLabel;					g_isSlideshowRunning = !g_isSlideshowRunning;		}	}}function galleryGoto(dest) {	stopSlideshow();	switch (dest) {	case "begin":		tabNr = g_tabBegin;		imgNr = g_imgBegin;		break;	case "prev":		tabNr = g_tabPrev;		imgNr = g_imgPrev;		break;	case "next":		tabNr = g_tabNext;		imgNr = g_imgNext;		break;	case "end":		tabNr = g_tabEnd;		imgNr = g_imgEnd;		break;	}		openImageGalleryEntry(tabNr, imgNr);}function stopSlideshow() {	if(g_isSlideshowRunning) {		window.clearTimeout(g_slideshowTimer);		xmlHttp.abort();		g_startStopLabel = g_startLabel;					document.getElementById("startstop").src = g_startLabel;		g_isSlideshowRunning = false;	}		}function startStopSlideshow() {	if(g_isSlideshowRunning) {		window.clearTimeout(g_slideshowTimer);		xmlHttp.abort();		g_startStopLabel = g_startLabel;				}	else {				openImageGalleryEntry(g_tabNext, g_imgNext);						g_startStopLabel = g_stopLabel;			}	document.getElementById("startstop").src = g_startStopLabel;	g_isSlideshowRunning = !g_isSlideshowRunning;}//is called from page not divfunction startSlideshow() {	g_showAtOnce = true;	g_isSlideshowRunning = true;	g_startStopLabel = g_stopLabel;	openImageGalleryEntry(1, 1);}function openGalleryEntryPrint() {	openGalleryEntryPrintWindow(g_tabCurrent, g_imgCurrent);}function openGalleryEntryPrintWindow(tabNr, imgNr) {	var docURL = document.URL;	var pos = docURL.indexOf("?OpenDocument");	if(pos != "-1") {		docURL = docURL.substring(0, pos);	}	var entryURL = replStr(docURL, "/web/", "/webimagegalleryentryprint/") + "?OpenDocument&tab=" + tabNr + "&img=" + imgNr;		var width = 640;	var height = 480;	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 downloadOriginalImage() {	var docURL = document.URL;		var dbPath = leftStr(rightStr(rightStr(docURL, "http://"), "/"), ".nsf") + ".nsf";	document.location.href = "/servlet/GetNotesAttachment?unid=" + g_unid + "&filename=" + g_bigFileName + "&dbpath=" + dbPath;}
