// JavaScript Document
// Version 2008-01-03

// Globale Variablen
var req;
var folder;
var counter;
var pix;
var pixH;
var actGal;
var xmlDoc;
var winHeight;
var winWidth;
var aGall = new Array;
var catSettings = new Array;
var pixSettings = new Array;
var aCat = new Array;
var exifData = new Array;
var slideID = null;
var isIE6 = false;
var isIE = false;
var galPage = 1;
var catPage = 1;
var slideTime = 5000;
var langLabels;

// Webseitenabhängige Variablen! Nicht überschreiben! ***************************************************************************
// Definitionen
var PIX_SIZE = 120;
var DIV_MARGIN = 20;
var NAV_HEIGHT = 30;
var LAYER_PIX_MARGIN = 20;
var PIX_DIV_HEIGHT = 195;
var PIX_MAX_HEIGHT = 1024;
var PLUGIN_HEIGHT = 480; 
var PLUGIN_WIDTH = 670;
var NO_INFO = true;
var NO_MAP = true;
var NO_COPYRIGHT = true;
var MAINFOLDER_NAME = "gallery/";
var GALLERIES_CATALOG = "catalog.xml";
var PICTURES_CATALOG = "catalog.xml";
var DIRECTORY_PREFIX = "./";
var THUMB_PREFIX = "120_";
var BG_COLOR = "#31031d";
var MULTI_LANGUAGE = false;
var PAGE_LANGUAGE = "de";
var COOKIE_LIFETIME=180000;
// ******************************************************************************************************************************* 


//Anpassen an Fenstergrösse
function GetWindowSize () {

	if (window.innerHeight && isIE == false) {
		winHeight = window.innerHeight;
		winWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		winHeight = document.documentElement.clientHeight;
		winWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		winHeight = document.body.clientHeight;
		winWidth = document.body.clientWidth;
	} else {
		window.alert(unescape("Fenstergr%F6sse konnte nicht bestimmt werden! Darstellungsfehler sind m%F6glich.\n\nCould not calculate window size! Minor errors are possible."));
		winHeight = 768;
		winWidth = 1024;
	};
}
	
function GetCatalogSize () {	
	catSettings[0] = GetColsPPage();
	catSettings[1] = GetRowsPPage(PIX_DIV_HEIGHT);
	catSettings[2] = catSettings[0] * catSettings[1];
}

function GetColsPPage () {
	return Math.floor((PLUGIN_WIDTH - DIV_MARGIN)/(PIX_SIZE + DIV_MARGIN));
}

function GetRowsPPage (divHeight) {
	if (FieldNotEmpty(divHeight) && divHeight != null && divHeight != "") {
		return Math.floor((PLUGIN_HEIGHT - NAV_HEIGHT - DIV_MARGIN)/(PIX_DIV_HEIGHT + DIV_MARGIN));
	} else {
		return Math.floor((PLUGIN_HEIGHT - NAV_HEIGHT - DIV_MARGIN)/(PIX_SIZE + DIV_MARGIN));
	}
}

function GetGallerySize () {
	pixSettings[0] = GetColsPPage();
	pixSettings[1] = GetRowsPPage("");
	pixSettings[2] = pixSettings[0] * pixSettings[1];
}

function CheckBrowserFamily() {
		//Detect IE6+
		version=10;
		isIE = false;
		isIE6 = false;
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			isIE = true;
			temp=navigator.appVersion.split("MSIE");
			version=parseFloat(temp[1]);
		};
		
		if (version<7) {//NON IE browser will return 0
			 alert(unescape('Sie verwenden Internet Explorer Version 6. Diese Seite, vor allem die Galerie, funktioniert nur eingeschr%E4nkt mit dieser Version. Bitte ziehen Sie ein Update auf Version 8 in Betracht. Sie erhöhen damit Ihre Sicherheit im Internet beträchtlich. Ausserdem erleichtern Sie damit allen Web-Designern die Arbeit erheblich!\nSie k%F6nnen das Update kostenlos %FCber das automatische Update von Windows (Start-Men%FC > "Windows Update" bzw. "Microsoft Update") oder die Internetseite von Microsoft (http://www.microsoft.com/germany/windows/internet-explorer/) beziehen.\n\nIch w%FCnsche Ihnen eine angenehme Zeit auf www.aikido-ennetbaden.ch!\n\nYou\'re using Internet Explorer version 6. This site, especially the gallery, is not fully compatible with your browser. Please consider an update to version 8. This version is considerably safer than previous versions. Additionally, you could simplify the life of all web-coders!\nYou can obtain the free update over the update Service of Windows (start > "Windows Update" or "Microsoft Update") or directly from the website of Microsoft (www.microsoft.com/windows/internet-explorer/).\n\nI wish you a pleasant time on www.aikido-ennetbaden.ch!'));
		};
}


// Hauptverzeichnis aufbauen
function FetchCatalog(delCookie) {
		CheckBrowserFamily();
		GetWindowSize();
		GetCatalogSize();
		SetLanguage();
		SetGallLabels();
		
		if ((delCookie) || (getParameter('reset') == "true")){
			EraseAllCookies();
			ResetUrlToMain();
		}
		
		
		if (document.implementation && document.implementation.createDocument && navigator.userAgent.indexOf("Safari") == -1)
		{
			xmlDoc = document.implementation.createDocument("", "", null);
			xmlDoc.onload = ReadCatalog;
		}
		else if(window.XMLHttpRequest && !(window.ActiveXObject)) {
			try {
				req = new XMLHttpRequest();
			} catch(e) {
				req = false;
			}
    	}
		else if(window.ActiveXObject) {
       		try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
        		try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e) {
					req = false;
				}
			}
    	};
		
		if(req) {
			req.onreadystatechange = function () {
   				if (req.readyState == 4) {
					if (req.status == 200) {
						xmlDoc = req.responseXML;
						ReadCatalog();
					}
					else {}
    			};
			};
			req.open("GET", DIRECTORY_PREFIX + MAINFOLDER_NAME + GALLERIES_CATALOG, false);
			req.send("");
		}
		else {
			try {
				xmlDoc.load(DIRECTORY_PREFIX + MAINFOLDER_NAME + GALLERIES_CATALOG);
			}
			catch(e) {
				alert(unescape('Einstellungen konnten nicht eingelesen werden. Der Aufbau der Galerie kann nicht ausgef%FChrt werden.'));
			}
		};
}

function ResetUrlToMain () {
	window.location.href = GetGallUrl();
}

function GetGallUrl () {
	var fullURL = window.location.href;
	partURL = fullURL.split('?');
	return partURL[0];
}

function SetGallLabels () {
		switch (PAGE_LANGUAGE) {
			case "de": langLabels = new Array("Katalog","Zur&uuml;ck","Diashow","Vergr&ouml;ssern","Auf Karte zeigen","Diashow stoppen","K&uuml;rzer zeigen","L&auml;nger zeigen");break;
			case "en": langLabels = new Array("catalog","back","slideshow","zoom in","show on map","stop slideshow","faster","slower");break;
			case "fr": langLabels = new Array("catalogue","retour","diaporama","agrandir","afficher sur la carte","stop diaporama","plus vite","plus lentement");break;
			case "it": langLabels = new Array("catalogo","indietro","dia show","ingrandire","mostrare sulla carta","fermare","plus veloce","piu lento");break;
			default: langLabels = new Array("catalog","back","slide show","zoom in","show on map","stop slideshow","faster","slower");break;
		}
}

function SetLanguage () {
	if (MULTI_LANGUAGE == true) {
		if ((readCookie("lang")!=null) && (readCookie("lang")!="") && (readCookie("lang")!="undefined")) {
			  PAGE_LANGUAGE = readCookie("lang");
		} else {
			if (typeof navigator.language != "undefined") {
				PAGE_LANGUAGE = navigator.language.substring(0,2);
			} else if (typeof navigator.browserLanguage != "undefined") {
				PAGE_LANGUAGE = navigator.browserLanguage.substring(0,2);
			}
			writeCookie("lang",PAGE_LANGUAGE);
		}
	}
}

function getParameter (parameter) {
	var regexS = "[\\?&]"+parameter+"=([^&#]*)";
  	var regex = new RegExp( regexS );
  	var results = regex.exec( window.location.href );
	if( results == null )
    	return "";
  	else
    	return results[1];
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function writeCookie(name,value) {
	var a = new Date();
	a = new Date(a.getTime()+COOKIE_LIFETIME);
	document.cookie = name+'='+value+"; expires="+a.toGMTString()+";path=/;";
}

function eraseCookie(name) {
	writeCookie(name,"");
}

function ReadCatalog() {
	x = xmlDoc.getElementsByTagName('gallery');
	for (i=0;i<x.length;i++) {
		aCat[i] = new Array(6);
		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType == 1) {
				switch (x[i].childNodes[j].nodeName) {
					case "title": aCat[i][2] = XmlReadNode(x,i,j); break;
					case "title_de": if (PAGE_LANGUAGE == "de") {aCat[i][2] = XmlReadNode(x,i,j)}; break;
					case "title_en": if (PAGE_LANGUAGE == "en") {aCat[i][2] = XmlReadNode(x,i,j)}; break;
					case "title_fr": if (PAGE_LANGUAGE == "fr") {aCat[i][2] = XmlReadNode(x,i,j)}; break;
					case "title_it": if (PAGE_LANGUAGE == "it") {aCat[i][2] = XmlReadNode(x,i,j)}; break;
					case "subtitle": aCat[i][3] = XmlReadNode(x,i,j); break
					case "subtitle_de": if (PAGE_LANGUAGE == "de") {aCat[i][3] = XmlReadNode(x,i,j)}; break;
					case "subtitle_en": if (PAGE_LANGUAGE == "en") {aCat[i][3] = XmlReadNode(x,i,j)}; break;
					case "subtitle_fr": if (PAGE_LANGUAGE == "fr") {aCat[i][3] = XmlReadNode(x,i,j)}; break;
					case "subtitle_it": if (PAGE_LANGUAGE == "it") {aCat[i][3] = XmlReadNode(x,i,j)}; break;
					case "desc": aCat[i][4] = XmlReadNode(x,i,j); break;
					case "desc_de": if (PAGE_LANGUAGE == "de") {aCat[i][4] = XmlReadNode(x,i,j)}; break;
					case "desc_en": if (PAGE_LANGUAGE == "en") {aCat[i][4] = XmlReadNode(x,i,j)}; break;
					case "desc_fr": if (PAGE_LANGUAGE == "fr") {aCat[i][4] = XmlReadNode(x,i,j)}; break;
					case "desc_it": if (PAGE_LANGUAGE == "it") {aCat[i][4] = XmlReadNode(x,i,j)}; break;
					case "icon":		aCat[i][1] = XmlReadNode(x,i,j); break;
					case "subfolder":	aCat[i][0] = XmlReadNode(x,i,j); break;
					case "copyrightOff":aCat[i][5] = XmlReadNode(x,i,j); break;
				};
			};
		};
	}
	
	processCatalog();
}

function processCatalog() {
	prePath = getParameter('gall');
	cookieGall = readCookie('folder');
	cookieIdx = parseInt(readCookie('gallidx'));
	if (prePath != "") {
		callPreGall(prePath);
	} else if ((cookieGall != "") && (cookieGall != "null") && (cookieGall != null)) {
		callCookieGall(cookieGall,cookieIdx);
	} else {
		CatalogCoder();
	}
}

function XmlReadNode (XMLObject,parentNode,childNode) {
	if (XMLObject[parentNode].childNodes[childNode].firstChild != null) {
		return XMLObject[parentNode].childNodes[childNode].firstChild.nodeValue;
	} else {
		return null;
	};	
}

function CatalogCoder() {
	var code = "";
	document.title = "";
	
	if (ParameterNotEmpty('catpage')) {
		catPage = parseInt(readParameter('catpage'));
	}
	if (CookieNotEmpty('catpage')) {
		catPage = parseInt(readCookie('catpage'));
	}
	
	writeCookie('catpage',catPage);
	
	catSettings[3] = GetNumOfPages(x,catSettings[2]);
	catSettings[4] = LastEntryID(x,catSettings[2],catPage);
	
	code =  '<div class="layer_top" style="width: ' + ContentWidth() + 'px"><table width="' + ContentWidth() + 'px"><tr><td class="navi_left">' + NaviTurnPage("prev",catSettings[3],"cat") + '</td><td class="layer_title">' + BuildPageNavi(catSettings[3],'cat') + '</td><td class="navi_right">' + NaviTurnPage("next",catSettings[3],"cat") + '</td></tr></table></div><div class="cont">';
	
	
	for (i=(catPage-1)*catSettings[2];i<catSettings[4];i++) {
		code += '<div class="gal_div"' + DivHeightCode() + '><div class="gal_icon"><a class="gal_link" href="javascript:FetchGallery(' + i + ',\'' + MAINFOLDER_NAME + aCat[i][0] + 
				'\')"><image src="' + ThumbPath("gallery") + aCat[i][1] + '"border="0"></a></div><div class="gal_title">'+ aCat[i][2] + '</div><div class="gal_subtitle">' +
				aCat[i][3] + '</div></div>'
	}
	document.getElementById('content').innerHTML = code;
}

function NaviTurnPage (dir, numOfPages,mode) {
	if (numOfPages>1) {
		if (dir == "prev") {
			return '<a class="gal_link" href="javascript:PrevPage(\'' + mode + '\')">&lt;&lt;</a>';
		} else if (dir == "next") {
			return '<a class="gal_link" href="javascript:NextPage(\'' + mode + '\')">&gt;&gt;</a>';
		} else {
			return "";
		}
	} else {
		return "";
	}
}

function getGallIndex (path) {
	for (i=0;i<aCat.length;i++) {
		if (aCat[i][0] == path) {
			return i;
			break;
		}
	}
}

function callPreGall (prePath) {
	prePage = getParameter('page');
	if (prePath != "") {
		FetchGallery(getGallIndex(prePath),MAINFOLDER_NAME+prePath);
	}
}

function callCookieGall(cookieGall,cookieIdx) {
	if (cookieGall != "") {
		FetchGallery(cookieIdx,cookieGall);
	}	
}

function DivHeightCode () {
	if (FieldNotEmpty(PIX_DIV_HEIGHT)) {
		return 'style="height: ' + PIX_DIV_HEIGHT + 'px;"';
	} else {
		return "";
	};
}


// Galerie aufbauen
function FetchGallery (galIdx,galFolder) {
	GetWindowSize();
	GetGallerySize();
	folder = galFolder;
	actGall = galIdx;
	galPage = 1;
	
	writeCookie('folder',galFolder);
	writeCookie('gallidx',galIdx);
	
	if (document.implementation && document.implementation.createDocument && navigator.userAgent.indexOf("Safari") == -1) {
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = ReadGallery;
	} else if(window.XMLHttpRequest && !(window.ActiveXObject)) {
		try {req = new XMLHttpRequest();}
			catch(e) {req = false;}
	} else if(window.ActiveXObject) {
		try {req = new ActiveXObject("Msxml2.XMLHTTP");}
			catch(e) {
			try {req = new ActiveXObject("Microsoft.XMLHTTP");}
				catch(e) {req = false;}
		}
	};
	
	if(req) {
		req.onreadystatechange = function () {
			if (req.readyState == 4) {
				xmlDoc = req.responseXML;
				ReadGallery();
			};
		};
		req.open("GET", DIRECTORY_PREFIX + folder + '/' + PICTURES_CATALOG, true);
		req.send("");
	} else {
		try {xmlDoc.load( DIRECTORY_PREFIX + folder + '/' + PICTURES_CATALOG);}
			catch(e) {}
	};
}

function ReadGallery() {
	y = xmlDoc.getElementsByTagName('picture');
	for (i=0;i<y.length;i++) {
		aGall[i] = new Array(24);
		for (j=0;j<y[i].childNodes.length;j++) {
			if (y[i].childNodes[j].nodeType == 1) {
				switch (y[i].childNodes[j].nodeName) {
					case "comment":			aGall[i][0] = DecodeHtml(XmlReadNode(y,i,j)); break;
					case "comment_de":		if (PAGE_LANGUAGE == "de") {aGall[i][0] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment_en":		if (PAGE_LANGUAGE == "en") {aGall[i][0] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment_fr":		if (PAGE_LANGUAGE == "fr") {aGall[i][0] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment_it":		if (PAGE_LANGUAGE == "it") {aGall[i][0] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment2":		aGall[i][1] = DecodeHtml(XmlReadNode(y,i,j)); break;
					case "comment2_de":		if (PAGE_LANGUAGE == "de") {aGall[i][1] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment2_en":		if (PAGE_LANGUAGE == "en") {aGall[i][1] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment2_fr":		if (PAGE_LANGUAGE == "fr") {aGall[i][1] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "comment2_it":		if (PAGE_LANGUAGE == "it") {aGall[i][1] = DecodeHtml(XmlReadNode(y,i,j))}; break;
					case "file": 			aGall[i][2] = XmlReadNode(y,i,j); break;
					case "thumbnail":		aGall[i][3] = XmlReadNode(y,i,j); break;
					case "width":			aGall[i][4] = XmlReadNode(y,i,j); break;
					case "height":			aGall[i][5] = XmlReadNode(y,i,j); break;
					case "isBigFile":		aGall[i][24] = XmlReadNode(y,i,j); break;
					case "addCode":			aGall[i][6] = DecodeCode(XmlReadNode(y,i,j)); break;
					case "noBig":			aGall[i][7] = XmlReadNode(y,i,j); break;
					case "noCopyright":		aGall[i][8] = XmlReadNode(y,i,j); break;
                    case "exif_make":		aGall[i][9] = XmlReadNode(y,i,j); break;
                    case "exif_model":		aGall[i][10] = XmlReadNode(y,i,j); break;
                    case "exif_date":		aGall[i][11] = XmlReadNode(y,i,j); break;
					case "exif_time":		aGall[i][12] = XmlReadNode(y,i,j); break;
					case "exif_exposure":	aGall[i][13] = DecodeHtml(XmlReadNode(y,i,j)); break;
                    case "exif_aperture":	aGall[i][14] = XmlReadNode(y,i,j); break;
                    case "exif_focal":		aGall[i][15] = XmlReadNode(y,i,j); break;
					case "exif_iso":		aGall[i][16] = XmlReadNode(y,i,j); break;
					case "gps_latitude":	aGall[i][17] = DecodeCoord(XmlReadNode(y,i,j)); break;
					case "gps_longitude":	aGall[i][18] = DecodeCoord(XmlReadNode(y,i,j)); break;
					case "gps_altitude":	aGall[i][19] = XmlReadNode(y,i,j); break;
					case "iptc_location":	aGall[i][20] = DecodeHtml(XmlReadNode(y,i,j)); break;
					case "iptc_city":		aGall[i][21] = DecodeHtml(XmlReadNode(y,i,j)); break;
					case "iptc_province":	aGall[i][22] = DecodeHtml(XmlReadNode(y,i,j)); break;
					case "iptc_country":	aGall[i][23] = DecodeHtml(XmlReadNode(y,i,j)); break;
                };
			};
		};
	};
	
	GalleryCoder();
}

function DecodeHtml(text) {
	if (text != null) {
		var str = text.replace(/\*/g,"&");
		return str.replace(/_/g,"\"");
	}
}

function DecodeCode(text) {
	if (text != null) {
		var str = text.replace(/\*/g,"&");
		return str.replace(/&quot;/g,"\"");
	}
}

function DecodeCoord(coord) {
	coord = coord.replace("d","&deg;");
	coord = coord.replace("p","&prime;");
	return coord;
}


function BuildInfoCode (pix) {
	var code = "<table class=\"infoTable\">";
	if (FieldNotEmpty(aGall[pix][10])) 
		code += InfoAddRow("Modell", aGall[pix][10], "");

	if (FieldNotEmpty(aGall[pix][11]) || FieldNotEmpty(aGall[pix][12])) {
		code += InfoAddEmptyRow();
		code += InfoAddRow("Datum", aGall[pix][11], "");
		code += InfoAddRow("Zeit", aGall[pix][12], " Uhr");
	}
	if (FieldNotEmpty(aGall[pix][13]) || FieldNotEmpty(aGall[pix][14]) || FieldNotEmpty(aGall[pix][15]) || FieldNotEmpty(aGall[pix][16])) {
		code += InfoAddEmptyRow();
		code += InfoAddRow("Belichungszeit",aGall[pix][13]," sec");
		code += InfoAddRow("Blende",aGall[pix][14],"");
		code += InfoAddRow("Brennweite",aGall[pix][15],"");
		code += InfoAddRow("ISO",aGall[pix][16],"");
	}
	if (FieldNotEmpty(aGall[pix][20]) || FieldNotEmpty(aGall[pix][21]) || FieldNotEmpty(aGall[pix][22]) || FieldNotEmpty(aGall[pix][23])) {
		code += InfoAddEmptyRow();
		code += InfoAddRow("Ort",aGall[pix][20],"");
		code += InfoAddRow("Stadt",aGall[pix][21],"");
		code += InfoAddRow("Provinz",aGall[pix][22],"");
		code += InfoAddRow("Land",aGall[pix][23],"");
	}
	if (FieldNotEmpty(aGall[pix][17]) || FieldNotEmpty(aGall[pix][18]) || FieldNotEmpty(aGall[pix][19])) {
		code += InfoAddEmptyRow();
		code += InfoAddRow("Latitude",ConvertCoord(aGall[pix][17],"lat"),"");
		code += InfoAddRow("Longitude",ConvertCoord(aGall[pix][18],"long"),"");
		code += InfoAddRow("H&ouml;he", aGall[pix][19]," m. &uuml;. M.");
	}
	return code += "</table>";
}

function FieldNotEmpty (field) {
	if (typeof field != "undefined") {
		return true;
	} else {
		return false;
	}
}

function InfoAddRow (title,value,suffix) {
	if (FieldNotEmpty(value) && value != "") {
		return "<tr><td class=\"infoTitleCol\">" + title + ":</td><td>" + value + suffix + "</td></tr>";
	} else {
		return "";
	}
}

function InfoAddEmptyRow() {
	return "<tr height=\"10\"><td></td><td></td></tr>";
}

function warningIcon(pixID) {
	document.getElementById("thumb" + pixID).src = ThumbPath("gallery") + "warning.jpg";	
}

function resetIcon(pixID) {
	document.getElementById("thumb" + pixID).src = ThumbPath(folder) + ThumbName(aGall[pixID][2],aGall[pixID][3]);
}

function CookieNotEmpty(name) {
	value = readCookie(name);
	if ((value != "") && (value != null) && (value != "null") && (value != "NaN")) {
		return true;
	} else {
		return false;
	}
}

function ParameterNotEmpty(name) {
	if (getParameter(name) != "") {
		return true;
	} else {
		return false;
	}
}

function GalleryCoder() {
	var code = "";
	var warningCode = "";
	
	if (ParameterNotEmpty('galpage')) {
		galPage = parseInt(getParameter('galpage'));
	}
	if (CookieNotEmpty('galpage')) {
		galPage = parseInt(readCookie('galpage'));	
	}
	
	pixSettings[3] = GetNumOfPages(y,pixSettings[2]);
	pixSettings[4] = LastEntryID(y,pixSettings[2],galPage);
	
	code =  '<div class="layer_top" style="width: ' + ContentWidth() + 'px"><table width="' + ContentWidth() + 'px"><tr><td class="navi_left">' + NaviTurnPage("prev",pixSettings[3],"pix") + '</td><td class="layer_title">' + BuildPageNavi(pixSettings[3],"gal") + '</td><td class="navi_right">' + NaviTurnPage("next",pixSettings[3],"pix") + '</td></tr></table></div><div class="cont">';
		
	for (i=(galPage-1)*pixSettings[2];i<pixSettings[4];i++) {
		if (!FieldNotEmpty(aGall[i][24])) {
			warningCode = "";
		} else {
			warningCode = ' onmouseover="javascript:warningIcon(' + i + ')" onmouseout="javascript:resetIcon(' + i + ')"';
		}	
		
		code += '<div class="gal_div"><div class="gal_icon"><a class="gal_link" href="javascript:ShowPix(' + i + ')"><img id="thumb' + i + '" ' + warningCode + ' src="' + ThumbPath(folder) + ThumbName(aGall[i][2],aGall[i][3]) + '" border="0"></a></div></div>';
	};
	
	code += '</div><div class="layer_bottom"><table width="' + ContentWidth() + 'px"><tr><td class="navi_left"><a class="gal_link" href="javascript:FetchCatalog(true)" ' +
			'style="font-size:14px;font-weight:normal">' + langLabels[0] + '</a></td><td class="layer_title"></td><td class="navi_right"><a class="gal_link" ' + 
			'href="javascript:ColdStartSlide()" style="font-size:14px;font-weight:normal;">' + langLabels[2] + '</a></td></tr></table></div><div id="layer_plugin"></div>';

	document.getElementById('content').innerHTML = code;
	document.title = aCat[actGall][2];
	
	prePix = getParameter('pix');
	cookiePix = readCookie('pix');
	if (prePix != "") {
		ShowPix(parseInt(prePix));
	}
	if ((cookiePix != "") && (cookiePix != null) && (cookiePix != "null") && (cookiePix != "NaN")) {
		ShowPix(parseInt(cookiePix));	
	}	
}

function BuildPageNavi (pages,mode) {
	var code = "";
	if (pages>1) {
		if (mode == "gal") {
			currPage = galPage;
		} else {
			currPage = catPage;
		}
		
		for (i=1;i<pages+1;i++) {
			if (i == currPage) {
				code += '<a class="gal_link" href="javascript:ChangePage(' + i + ',\'' + mode + '\')"><font color="white"><b>' + i + '</b></font></a>   ';
			} else {
				code += '<a class="gal_link" href="javascript:ChangePage(' + i + ',\'' + mode + '\')">' + i + '</a>   ';
			}
		}
	}
	return code;
}

function GetNumOfPages (array, entriesPerPage) {
	return Math.ceil(array.length/entriesPerPage);
}

function LastEntryID (array,entriesPerPage,currPage) {
	if (array.length < entriesPerPage) {return array.length;}
		else {
			if (currPage * entriesPerPage<array.length) {return currPage * entriesPerPage;}
				else {return array.length;
		}
	}
}

function ContentWidth() {
	return (PLUGIN_WIDTH - DIV_MARGIN);
}

function ContentHeight() {
	return (PLUGIN_HEIGHT - DIV_MARGIN);
}

function ThumbPath (galFolder) {
	return DIRECTORY_PREFIX + galFolder + '/thumbs/';
}

function ImagePath (galFolder) {
	return DIRECTORY_PREFIX + galFolder + '/images/';
}

function ThumbName (pixName, thumbName) {
	var pixFile = "";
	if (thumbName != null) {pixFile = thumbName;} 
		else {pixFile = pixName;}
	if (pixFile.indexOf(THUMB_PREFIX) == -1) {return THUMB_PREFIX + pixFile;} 
		else {return pixFile;}
}

// Navigation im Anzeige-Layer
function ShowPix(number) {
		pix = number;
		
		writeCookie('pix',number);
		
		LayerCoder();
		PixSizeLayer('layer');
		PixLayerCoder('image');
}

function ChangePixMode(mode,e,number,layer) {
	if (e.which == 0 || e.which == 1 || e.button == 1 || e.button == 0 || e == 'direkt') {
		if (mode == 'normal') {
			document.getElementById(layer).innerHTML = "";
		} else if (mode == 'big') {
			pix = number;
			code = '<div class="layer_mega" id="img_layer" style="height: ' + winHeight + 'px; width: ' + winWidth + 'px;"></div>';
			document.getElementById('layer_mega').innerHTML = code;
			PixSizeLayer('doc');
			PixLayerCoder('img_layer');		
		};
	};
}

function PrevPix() {
	if (pix!=0) {
		pix -= 1;
	} else {
		pix = aGall.length - 1;
	};
	writeCookie('pix',pix);
	LayerCoder();
	PixSizeLayer('layer');
	PixLayerCoder('image');	
	if (slideID != null)
		window.clearInterval(slideID);
	HideInfo();
}

function NextPix() {
	if (pix<aGall.length - 1) {
		pix += 1;
	}
	else {
		pix = 0;
	};
	writeCookie('pix',pix);
	LayerCoder();
	PixSizeLayer('layer');
	PixLayerCoder('image');
	if (slideID != null)
		window.clearInterval(slideID);
	HideInfo();
}

function PrevPage(mode) {
	if (mode == 'pix') {
		if (galPage!=1) {galPage -= 1;}
			else {galPage = pixSettings[3];};
		writeCookie('galpage',galPage);
		GalleryCoder();
	} else if (mode == 'cat') {
		if (catPage!=1) {catPage -= 1;}
			else {catPage = catSettings[3];};
		writeCookie('catpage',catPage);
		CatalogCoder();
	}
}

function NextPage(mode) {
	if (mode == 'pix') {
		if (galPage<pixSettings[3]) {
			galPage += 1;
			writeCookie('galpage',galPage);
		}
		else {
			galPage = 1;
			writeCookie('galpage',galPage);
		};
		GalleryCoder();
	} if (mode == 'cat') {
		if (catPage<catSettings[3]) {
			catPage += 1;
			writeCookie('catpage',catPage);
		}
		else {
			catPage = 1;
			writeCookie('catpage',catPage);
		};
		CatalogCoder();
	}
}

function ChangePage(pge,mode) {
	if (mode == 'gal') {
		galPage = pge;
		writeCookie('galpage',galPage);
		GalleryCoder();
	} else if (mode = 'cat') {
		catPage = pge;
		writeCookie('catpage',catPage);
		CatalogCoder();
	}
}

function LayerCoder () {
		var mapCode = "";
		GetWindowSize();
		
		if (typeof aGall[pix][0] == "undefined") {
			aGall[pix][0] = "";
		}
		
		code = '<div id="layer_mega"></div><div class="layer" id="layer" style="height: ' + winHeight*0.8 + 'px; width: ' + winWidth*0.8 + '"><div class="layer_top">' + 
					 '<table width="' + winWidth*0.8 + 'px"><tr><td class="navi_left"><a  class="gal_link" href="javascript:PrevPix()">&lt;&lt;</a></td><td class="layer_title">' +
					 aGall[pix][0] + ' (' + (pix+1) + '/' + aGall.length + ')' + '</td><td class="navi_right"><a class="gal_link" href="javascript:NextPix()">&gt;&gt;</a>' + 
					 '</td></tr></table></div><div class="layer_cont" id="image" style="height: ' + (winHeight*0.8-2*DIV_MARGIN-44) + 'px; width: ' + (winWidth*0.8) + 'px"></div>' + 
					 '<div class="layer_bottom"><table width="' + winWidth*0.8 + 'px"><tr><td class="navi_left" id="layerBack" name="layerBack"></td><td class="navi_middle" ' + 
					 'id="slideStop" name="slideStop"></td><td class="navi_right" id="slideShow" name="slideShow"></td></tr></table></div></div>';
		if (isIE6 == false) {
			code = '<div class="layer_transparenz" style="height: ' + winHeight + 'px; width: ' + winWidth+ 'px;"></div>' + code;
		};
		
		document.getElementById('layer_plugin').innerHTML = code;
		LayerCodeNormal();
			
			
}

function PixSizeLayer(parent) {
	if (parent == 'doc') {
		GetCatalogSize();
		pixH = winHeight - 2 * DIV_MARGIN;
		if (pixH > PIX_MAX_HEIGHT) {pixH = PIX_MAX_HEIGHT};
	} else {
		if (isIE == false) {
			pixH = document.getElementById(parent).offsetHeight - NAV_HEIGHT - 2 * LAYER_PIX_MARGIN - 2 * DIV_MARGIN;
		} else {
			pixH = winHeight*0.8 - NAV_HEIGHT - 2 * LAYER_PIX_MARGIN - 2 * DIV_MARGIN;
		};
	};
}

function HideLayer() {
	eraseCookie('pix');
	document.getElementById('layer_plugin').innerHTML = "";
}

function PixLayerCoder(div) {
	var isMovie = false;
	if (aGall[pix][5] != null && aGall[pix][4] != null) {
		sizeCode = 'height="' + pixH +'" width="' + Math.floor(aGall[pix][4]/aGall[pix][5]*pixH) +'"';
	} else {
		sizeCode = 'height="' + pixH + '"'
	};
	
	if (aGall[pix][6] != null) {
		addCode = ' ' + aGall[pix][6];
	} else {
		addCode = "";
	}

	var ending = aGall[pix][2].substring(aGall[pix][2].lastIndexOf("."), aGall[pix][2].length);
	if ((ending == ".mov") || (ending == ".avi") || (ending == ".flv")) {
		if (ending == ".mov") {
			isMovie = true;
		} else {
			divType = 'object';
			divSrc = 'data';
		}
	} else {
		divType = 'img';
		divSrc = 'src';
	}
	
	if (div == 'image') {
		modeCode = '\'big\',event,' + pix + ',\'\'';
	} else if (div == 'img_layer') {
		modeCode = '\'normal\',event,\'\',\'layer_mega\'';
	};
	
	if (aGall[pix][7] == false) {
		mouseCode = "";
	} else {
		mouseCode = 'onmousedown="javascript:ChangePixMode(' + modeCode + ')"';
	};
	
	if (NO_COPYRIGHT = false) {
		copyrightCode = 'oncontextmenu="javascript:CopyrightWarning();return false;" ondragstart="javascript:CopyrightWarning();return false;"';
	} else {
		copyrightCode = '';
	}
    
	if (!isMovie) {
		code = '<a><' + divType + ' ' + mouseCode + ' ' + copyrightCode + ' onmouseover="javascript:ShowInfo(' + pix + ')" onmouseout="javascript:HideInfo()" border="0" ' + 
			   sizeCode + ' ' + addCode + ' ' + divSrc + '="' + ImagePath(folder) + aGall[pix][2] + '"></' + divType + '></a>';
	} else {
		code = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" ' + sizeCode + '><param name="src" value="' +
			   ImagePath(folder) + aGall[pix][2] +'" ><param name="Controller" value="true"><embed src="' + ImagePath(folder) + aGall[pix][2] + '" ' + sizeCode + 
			   ' type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" controller="true" bgcolor="' + BG_COLOR + '"/></object>';
	}
	
	document.getElementById(div).innerHTML = code;
}

function CopyrightWarning() {
	window.alert(unescape("Dieses Bild ist urheberrechtlich gesch%FCtzt!\nThis image is copyright protected!"));
}

function StartSlide() {
	if (slideID == null) {
		pix += 1;
		ShowPix(pix);
		writeCookie('pix',pix);
		pix += 1;
		
		HideInfo();
		LayerCodeSlide();
		slideID = window.setInterval(SlideShow,slideTime);
	}
}

function StopSlide() {
	LayerCodeNormal();
	window.clearInterval(slideID);
	slideID = null;
}

function SlowerSlide() {
	slideTime += 1000;
	window.clearInterval(slideID);
	slideID = window.setInterval(SlideShow,slideTime);
	LayerCodeSlide();
}

function FasterSlide() {
	if (slideTime != 1000) {
		slideTime -= 1000;
		window.clearInterval(slideID);
		slideID = window.setInterval(SlideShow,slideTime);
		LayerCodeSlide();
	}
}

function LayerCodeNormal() {
	var mapCode = "";
	if ((FieldNotEmpty(aGall[pix][17])) && (FieldNotEmpty(aGall[pix][16])))
			mapCode = ' | <a class="gal_link" href=' + ShowOnMap(aGall[pix][17],aGall[pix][18]) + ' style="font-size:12px;font-weight:normal" target="_new">' + langLabels[4] + '</a>';
			
	document.getElementById('slideShow').innerHTML = '<a class="gal_link" href="javascript:StartSlide()" style="font-size:14px;">' + langLabels[2] + '</a>';
	document.getElementById('slideStop').innerHTML = '<a class="gal_link" href="javascript:ChangePixMode(\'big\',\'direkt\',' + pix + ',\'\')" style="font-size: 12px;">' + 
													 langLabels[3] + mapCode + '</a>';
	document.getElementById('layerBack').innerHTML = '<a class="gal_link" href="javascript:HideLayer()" style="font-size:14px;">' + langLabels[1] + '</a>';
}

function LayerCodeSlide() {
	document.getElementById('slideShow').innerHTML = '<a class="gal_link" href="javascript:SlowerSlide()" style="font-size:14px;">' + langLabels[7] + ' (' + (slideTime*0.001+1) + ' sek)</a>';
	document.getElementById('slideStop').innerHTML = '<a class="gal_link" href="javascript:StopSlide()" style="font-size:14px;">' + langLabels[5] + '</a>';
	if (slideTime >= 1000) {
		document.getElementById('layerBack').innerHTML = '<a class="gal_link" href="javascript:FasterSlide()" style="font-size:14px;">' + langLabels[6] + ' (' + (slideTime*0.001-1) + 
														 ' sek)</a>';
	} else {
		document.getElementById('layerBack').innerHTML = '';
	}
}

function SlideShow() {
	ShowPix(pix);
	LayerCodeSlide();
	HideInfo();
	if (pix < aGall.length-1) {
		pix += 1;
	} else {
		pix = 0;
	}
}

function ColdStartSlide() {
	ShowPix(1);
	StartSlide();
}

function ShowInfo (pix) {
	if (NO_INFO == false) {
		var top = pixH/3;
		var text = BuildInfoCode(pix);
		if (text != "<table class=\"infoTable\"></table>") {
			document.getElementById('tooltip').innerHTML = '<div class="infoDiv" style="left: ' + (winWidth*0.1+35) + 'px; top: ' + (winHeight*0.3) + 'px;">' + text + '</div>';
		}
	}
}

function HideInfo () {
	document.getElementById('tooltip').innerHTML = "";	
}

function ConvertCoord(coord,mode) {
	var hemi = "";
	if (mode == "lat") {
		if (coord.substring(0,1) == "-") {
			hemi = "S";
		} else {
			hemi = "N";
		}
	} else if (mode == "long") {
		if (coord.substring(0,1) == "-") {
			hemi = "E";
		} else {
			hemi = "W";
		}
	}
	coord = coord.substring(1,coord.length);
	return coord + "&Prime; " + hemi;
}

function CleanCoord(coord) {
	coord = coord.replace("d","*deg;");
	coord = coord.replace("p","*prime;");
	return coord;
}

function ShowOnMap(lat,long) {
	return "http://maps.google.com/maps?q=Das%20Bild%20wurde%20hier%20gemacht.@" + lat + "," + long;	
}

function EraseAllCookies() {
	eraseCookie('folder');
	eraseCookie('galpage');
	eraseCookie('catpage');
	eraseCookie('gallidx');
	eraseCookie('pix');
}