// geht die divs durch und versteckt alle mit der Klasse Content
function hideall() {
 if(!document.getElementById('termineDiv')) { return; }
 container = document.getElementById('termineDiv');
 contained = container.getElementsByTagName('div');
 for(i = 0; i<contained.length; i++) {
  if(contained[i].className == "content") {
	 contained[i].style.display = "none";
	}  
	if(contained[i].className == "header") {
	 swapHeadline(contained[i].id,"fro");
	}  
 }
}

function swapHeadline(id,tofro) {
 container2 = document.getElementById(id);
 contained2 = container2.getElementsByTagName('h2');
 for(r=0;r<contained2.length;r++) {
  if(tofro == "to") {
   contained2[r].className = "down";
	}
	if(tofro == "fro") {
   contained2[r].className = "up";	
	}
 }
}



function showEvents() {
 if(!document.getElementById('termineDiv')) { return; }
 container = document.getElementById('termineDiv');
 contained = container.getElementsByTagName('div');
 for(i = 0; i<contained.length; i++) {
  if(contained[i].className == "header") {
	 contained[i].onclick = function() {
		 hiddenElementId = this.id.replace("Header","Content");
		 if(document.getElementById(hiddenElementId).style.display == "block") { 	
		  elemHeight = document.getElementById(hiddenElementId).offsetHeight;
			document.getElementById(hiddenElementId).style.display = "none";
			swapHeadline(this.id,"fro");
			root = document.documentElement;
			w = document.getElementById('outerwrapper');
			//if(root.offsetHeight < w.offsetHeight) {
			// w.style.height = w.offsetHeight - elemHeight + "px";
			// }
		 } else {
		 	hideall();
		  document.getElementById(hiddenElementId).style.display = "block";
		  swapHeadline(this.id,"to");
		 }
	 }  
  }  
 }
}




 function swapnavi() {

  if(!document.getElementById('navi')) { return; }

  navcontainer = document.getElementById('navi');
	nav_links = navcontainer.getElementsByTagName('a');
	for(i=0;i<nav_links.length;i++) {
	 nav_links[i].onmouseover = function() {
	  if(this.id == 'active' || this.className == "nohl" ||  this.className == "hlactive" ) { return; }
		swapheadline(this.href,'on');
	 }
  nav_links[i].onmouseout = function() {
	  if(this.id == 'active' || this.className == "nohl" ) { return; }
		swapheadline(this.href,'off');		
	 }	 
 }
}
 
 function swapheadline(item,state) {
  var headline = "";
	lastslash = item.lastIndexOf("/");
	active = item.slice(lastslash+1).replace(".gif","").replace("_o","");
  if(item.indexOf('ueberuns')  > -1  || item.indexOf('mitarbeiter')  > -1 || item.indexOf('links')  > -1) {
	 headline = "h_institut";
	}  
	if(item.indexOf('unsereschwerpunkte') > -1) {
	 headline = "h_schwerpunkte";
	}
  if(item.indexOf('veranstaltungen')  > -1 || item.indexOf('workshops') > -1) {
	 headline = "h_veranstaltungen";
	}	
  if(item.indexOf('google')  > -1 || item.indexOf('dokumentationen')  > -1 || item.indexOf('archiv')  > -1 ) {
	 headline = "h_archiv";
	}		
  if(item.indexOf('adresse')  > -1 || item.indexOf('newsletter')  > -1 || item.indexOf('impressum')  > -1  || item.indexOf('admin')  > -1 ) {
	 headline = "h_kontakt";
	}		
  if(!headline) { return; }
	hlheadline = document.getElementById(headline);

	if(state == "on") {
	 if(hlheadline.src.indexOf("_o") > -1) { return; }
	 hlheadline.src = hlheadline.src.replace(".gif","_o.gif");
	}
	if(state == "off") {
	 if(hlheadline.className == "hlactive") { return; }
	 hlheadline.src = hlheadline.src.replace("_o.gif",".gif");
	}
 }
 
  function mkImgLink() {
  imgs = document.getElementById('innercontent').getElementsByTagName('img');
	for(i=0;i<imgs.length;i++) {
   imgs[i].onclick = function() {
	  window.open(this.src.replace('thumb_',''));
		return false;
	 }
  }
 }

 function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
   obj['e'+type+fn] = fn;
   obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
   obj.attachEvent( 'on'+type, obj[type+fn] );
   } else
  obj.addEventListener( type, fn, false );
 }
 
 
 addEvent( window, 'load', swapnavi );
 addEvent( window, 'load', hideall );
 addEvent( window, 'load', showEvents );
 addEvent( window, 'load', mkImgLink );
