
// 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
	imgs = new Array();
	
	//thumbs
	var thumbId = 0;
	
	var currImg = null;
	
	window.onload = initialize;
	
	
	function initialize() {
		return;
        // initialize the DHTML History
        // framework
        dhtmlHistory.initialize();
        
        // subscribe to DHTML history change
        // events
        dhtmlHistory.addListener(historyChange);
        
        if (dhtmlHistory.isFirstLoad()) {
        	
        }
    }
	
	function historyChange(newLocation, historyData) {
		if (newLocation != ""){
	        openPage(newLocation.substring(1), historyData, true);
        } else {
        	openPage("index.php?id=" + uid + "&type=1", historyData, true);
        }
      }
      
	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";
					}
				}
			}

			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 < 100; i++){
			var m = document.getElementById("thumbs");
			if(m == undefined) return;
			m.innerHTML = "";
		}
	}
	
	function popDiv(theURL, theCap, theUid, theIndex, w, h, historyMode){
		  	popD.style.display = "none";
		  	var str = "";
		  	
		  	str += "<div class='img'><table cellpadding='0' cellspacing='0'><tr><td><img border='0' src='" + theURL + "' alt='&nbsp;' width='"+w+"' height='"+h+"'/></td></tr><tr><td class=\"caption\" >"+theCap+"</td></tr></table></div>";
			str += "<table class='prevNext' cellpadding=\"0\" cellspacing=\"0\"><tr><td id='prevImg'></td><td id='nextImg'></td></tr></table>";

			
		  	popD.innerHTML = str;
		  	
		  	if (theIndex > 0){
		  		writePrevNext(theUid, theIndex-1, "prevImg", "&laquo;");
		  	}
		  	
		  	if((theIndex + 1) < imgs[theUid].length){
		  		writePrevNext(theUid, theIndex+1, "nextImg", "&raquo;");
		  	}			
			document.getElementById("showPic").style.display = "block";
		  	
		  	popD.style.display = "block";
			scrollD.style.display = "block";
			if (historyMode != true){
				//dhtmlHistory.add(theUid + "_" +theIndex, "img");
			}
			

		  }

		  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 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";

		  }


