
// Menue ein/ausschalten

var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
function show(id){
	if(ns4){			document.layers[id].visibility = "show";	}
	else if(ie4){		document.all[id].style.visibility = "visible";	}
	else if(ie5||ns6){	document.getElementById(id).style.visibility = "visible";	}
}
function hide(id){
	if(ns4){			document.layers[id].visibility = "hide";	}
	else if(ie4){		document.all[id].style.visibility = "hidden";	}
	else if(ie5||ns6){	document.getElementById(id).style.visibility = "hidden";	}
}

	// id's of menu divs
	var menuDivs = new Array();
	
	// images
	var imgs = new Array();
	
	//thumbs
	var thumbId = 0;
	
	var currImg = null;
	
	var loadURL, loadCap, loadUid, loadIndex, loadW, loadH;
	var preloadURL;
	
	
	      
	var registerImg = function (theURL, theCap, theUid, theIndex, w, h){
		if(imgs[theUid+""] == undefined){
			imgs[theUid+""] = new Array();
		}
		if (imgs[theUid+""][theIndex] == undefined){
			imgs[theUid+""][theIndex] = new Array(theURL, theCap, w, h);
		}
	}
	
	// define id for thumbnails
	function defineId(id){
		thumbId = id;
	}
	
	function addMenuDiv(id,pid,cid){
		menuDivs[id] = new Array();
		menuDivs[id]["pid"] = pid;
		menuDivs[id]["cid"] = cid;
	}
	
	function closeMenuDivs(){
		for (var key in menuDivs){
			if (document.getElementById(key) == undefined) continue;
			if(menuDivs[key]["pid"] != ""){
				document.getElementById(key).style.display = "none";
			} else {
				document.getElementById(key).style.display = "block";
				var c = document.getElementById(key).childNodes;
				for(var i = 0; i < c.length; i++){
					if (c[i].nodeName == "A"){
						c[i].style.color = "#999999";
						c[i].style.fontWeight = "normal";
						c[i].setAttribute("onmouseover", "hover(this)");
						c[i].setAttribute("onmouseout", "unHover(this, '#999999')");
					}
				}
			}
		}
	}
	
	function hover(node){
		node.style.color = "black";
	}
	
	function unHover(node, color){
		node.style.color = color;
	}
	
	function openChildDivs(id){
		for (var key in menuDivs){
			if(menuDivs[key]["pid"] == id){
				if(document.getElementById(key) == undefined) continue;
				document.getElementById(key).style.display = "block";
			}
		}
	}
	
	function openMenuDiv(id){
		closeMenuDivs();
		openParentMenuDiv(id);
		openChildDivs(id);
	}
	
	function openParentMenuDiv(id){
		if (document.getElementById(id) == undefined) return;
		document.getElementById(id).style.display = "block";
		var c = document.getElementById(id).childNodes;
		for(var i = 0; i < c.length; i++){
			if (c[i].nodeName == "A"){
				c[i].style.color = "black";
				c[i].style.fontWeight = "normal";
				c[i].setAttribute("onmouseover", "hover(this)");
				c[i].setAttribute("onmouseout", "unHover(this, 'black')");

			}
		}

		openChildDivs(id);
		if(menuDivs[id]["pid"] != ""){
			openParentMenuDiv(menuDivs[id]["pid"]);
		}
	}
	
	function openPage(url, title, historyMode){	
		openMenuDiv(url);
		hidePicNoRestore();
		var elem = document.getElementById("content");
		document.getElementById("loading").style.display= "block";
		var page_request = false
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc
			page_request = new XMLHttpRequest();
			if (page_request.overrideMimeType) {
                page_request.overrideMimeType('text/xml');
            }
		} else if (window.ActiveXObject){ // if IE
			try {
				page_request = new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e){
				try{
					page_request = new ActiveXObject("Microsoft.XMLHTTP")
				} catch (e){}
			}
		} else return false;
		
		page_request.onreadystatechange=function(){

			loadpage(page_request, url, title, historyMode);
		}
		
		page_request.open('GET', url, true);
		page_request.send(null);

		return false;
	}
	
	
	
	function loadpage(page_request, url, title, historyMode){
		var id = "content";
		var elem = document.getElementById(id);
		elem.style.display="none";
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){

			if (historyMode != true){
				dhtmlHistory.add("_"+url, title);
			}
			
			elem.innerHTML=page_request.responseText;
			htmlStore = document.getElementById("content").innerHTML;
			var s = document.getElementsByTagName("script");
			thumbId = undefined;
			// ok execute scripts
			for(var i = 0; i < s.length;i++){
				if(s[i].getAttribute("name") == "execMe"){
					eval(s[i].innerHTML);
				}
			}
			var showPics = makeThumbs();
			document.getElementById("loading").style.display= "none";
			if(!showPics) elem.style.display="block";
			
		}

	}
	
	function makeThumbs(){
		// clear old thumbs
			clearThumbs();
			// write new thumbs
			var ts = document.getElementById("thumbs");
			var found = false;

			var as = document.getElementsByTagName("a");			
			for(var i = 0; i < as.length;i++){
				if(as[i].getAttribute("name") == "addToMenu"){
					found = true;
					break;
				}
			}
			
			var tables = document.getElementsByTagName("table");
			for(var i = 0; i < tables.length;i++){
				if(tables[i].getAttribute("class") == "imgtext-table"){
					if(found){
//						 tables[i].style.display="none";
						 tables[i].style.visibility="hidden";
					}
				}
			}

			if (ts != undefined){
				var as = document.getElementsByTagName("a");
				var j = 0;
				for(var i = 0; i < as.length;i++){
					if(as[i].getAttribute("name") == "addToMenu"){
						if(j == 0){
							found = true;
							j++;
						}
						ts.appendChild(as[i]);
					}
				}
			}

			var divs = document.getElementsByTagName("div");
			for(var i = 0; i < divs.length;i++){
				if(divs[i].getAttribute("class") == "caption"){
					if(found){
						divs[i].setAttribute("class", "captionList");
					} 
				}
			}
			return found;
//			document.getElementById('content').style.display='none'; // Tristan
	}
	
	function clearThumbs(){
		for(var i = 1; i < 200; i++){
			var m = document.getElementById("thumbs");
			if(m == undefined) return;
			m.innerHTML = "";
		}
	}
	
	function popDiv(theURL, theCap, theUid, theIndex, w, h, thumbImage){
			document.getElementById('content').style.display = 'none';
			
			if(thumbImage){
				var a = document.getElementById(thumbImage);
				aImg  = a.getElementsByTagName("img");
				fillPopDiv(aImg[0].src, theCap, theUid, theIndex, w, h)
			}
			
			loadURL = theURL;
			loadCap = theCap;
			loadUid = theUid;
			loadIndex = theIndex;
			loadW = w;
			loadH = h;
		  	
		  	startLoader(theURL);

		  }
		  
		  function fillPopDiv(theURL, theCap, theUid, theIndex, w, h){
		  	var nummer = theIndex+1;
			var anzahl = imgs[theUid].length;
		  	
		  	var str = "\n\n ";
		  	str += "<div class='img'>";
		  	
		  	
		  	if((theIndex + 1) < imgs[theUid].length){
		  		var newURL = imgs[theUid][theIndex + 1][0];
			  	var newCap = imgs[theUid][theIndex + 1][1];
			  	var newW = imgs[theUid][theIndex + 1][2];
			  	var newH = imgs[theUid][theIndex + 1][3];
			  	str += "<a href=\"javascript:popDiv('"+ newURL+"', '"+ newCap+"', '"+theUid+"', "+(theIndex + 1)+", "+newW+", "+newH+");\">";;
		  	}
		  	
		  	str += "<img border='0' src='" + theURL + "' alt='' width='"+w+"' height='"+h+"'/>";
		  	if((theIndex + 1) < imgs[theUid].length){
		  		str += "</a>";		
		  	}
		  	str += "</div>\n";
			str += "<table class='prevNext' cellpadding=\"0\" cellspacing=\"0\"><tr>\n";
			str += "<td id='prevImg'></td>\n<td class='nextNumber'>"+ nummer +"/"+ anzahl +"</td>\n";
			str += "<td id='nextImg'></td>\n";
			str += "<td class=\"bildbeschriftung\">"+theCap+"</td></tr></table>\n";
			
		  	popD.innerHTML = str;
		  	
		  	if (theIndex > 0){
		  		writePrevNext(theUid, theIndex-1, "prevImg", "&laquo;");
		  	} else {
		  		writeSpacer("prevImg", "&laquo;");
		  	}
		  	
		  	if((theIndex + 1) < imgs[theUid].length){
		  		writePrevNext(theUid, theIndex+1, "nextImg", "&raquo;");
		  		preloadURL = imgs[theUid][theIndex+1][0];
		  	} else {
		  		writeSpacer("nextImg", "&raquo;");
		  		preloadURL = imgs[theUid][0][0];
		  	}
		  	
			document.getElementById("showPic").style.display = "block";
		  	
		  	popD.style.display = "block";
			scrollD.style.display = "block";
		  }
		  
		  
		  function startLoader(theURL){
		  	var preload = new Image();
			preload.onload = function(){
				fillPopDiv(loadURL, loadCap, loadUid, loadIndex, loadW, loadH);
			  	var preload = new Image();
				preload.src = preloadURL;	
			};
			preload.src = theURL;
		  }
		  
		  
		  
		  function writePrevNext(theUid, theIndex, direction, theString){
		  	var s = document.getElementById(direction);
		  	var theURL = imgs[theUid][theIndex][0];
		  	var theCap = imgs[theUid][theIndex][1];
		  	var w = imgs[theUid][theIndex][2];
		  	var h = imgs[theUid][theIndex][3];
		  	
		  	s.innerHTML="<a href=\"javascript:popDiv('"+ theURL+"', '"+ theCap+"', '"+theUid+"', "+theIndex+", "+w+", "+h+");\">"+theString+"</a>";
		  }
		  
		  function writeSpacer(direction, theString){
		  	var s = document.getElementById(direction);		  	
		  	s.innerHTML="<span class=\"hideMe\">"+theString+"</a>";
		  }
		  
		  
		  
		  function hidePic(){
			  hidePicNoRestore();
			  document.getElementById("showPic").style.display = "none";
			  document.getElementById("content").innerHTML = htmlStore;
		  }
		  
		  function hidePicNoRestore(){
		    popD.innerHTML = "";
			popD.style.display = "none";
		    scrollD.style.display = "none";
    		document.getElementById("content").style.display = "block";
			document.getElementById("scroll").style.display = "block";

		  }



