function relTags() {
  if (document.getElementsByTagName) {
    var anchors = document.getElementsByTagName( 'a' );
    for (var loop = 0; loop < anchors.length; loop++) {
      var anchor = anchors[loop];
      if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
        anchor.target = '_blank';
      }
    }
  }
}

function getElementsByClassName(class_name) {
  var all_obj,ret_obj=new Array(),j=0,teststr;
  if(document.all)all_obj=document.all;
  else if(document.getElementsByTagName && !document.all)all_obj=document.getElementsByTagName('*');
  for(i=0;i<all_obj.length;i++)
  {
    if(all_obj[i].className.indexOf(class_name)!=-1)
    {
      teststr=','+all_obj[i].className.split(' ').join(',')+',';
      if(teststr.indexOf(','+class_name+',')!=-1)
      {
        ret_obj[j]=all_obj[i];
        j++;
      }
    }
  }
  return ret_obj;
}

function changeLinks()	{
	if (document.getElementById('thumbs')) {
		var as,i,islink;
		// grab all links, loop over them;        
		as=document.getElementById('thumbs').getElementsByTagName('a');
		for(i=0;i<as.length;i++) {
			as[i].onclick=function(){	changePic(this); 
										//sameheight('gallery', 'info'); 
										return false;
									};
		}
	}
	if (document.getElementById('gallery')) {
		var asq,q,isqlink;
		// grab all links, loop over them;        
		asq=document.getElementById('thumbs').getElementsByTagName('img');
		for(q=0;q<asq.length;q++) {
			if (!(/.jpg/.test(asq[q].src.toLowerCase()) || /.png/.test(asq[q].src.toLowerCase()) || /.gif/.test(asq[q].src.toLowerCase()))){
			//asq[q].parentNode.parentNode.className+=' hide';
			asq[q].parentNode.parentNode.style.display='none';
			}

		}
		
    if (!(/.jpg/.test(document.getElementById('gpic').src.toLowerCase()) || /.png/.test(document.getElementById('gpic').src.toLowerCase()) || /.gif/.test(document.getElementById('gpic').src.toLowerCase()))){		
			for(t=0;t<asq.length;t++) {
			 if ((/.jpg/.test(asq[t].src) || /.png/.test(asq[t].src) || /.gif/.test(asq[t].src))){
			 document.getElementById('gpic').src = asq[t].src;
			 asq[t].className = 't_aktiv';
			 break;
  		 }
	    }
		}
		if (!(/.jpg/.test(document.getElementById('gpic').src.toLowerCase()) || /.png/.test(document.getElementById('gpic').src.toLowerCase()) || /.gif/.test(document.getElementById('gpic').src.toLowerCase()))){	
		//document.getElementById('gpic').parentNode.className+=' hide';
			document.getElementById('gpic').parentNode.style.display='none';
		}
		
	}
}

		
function MakeCamPop () {
  if (getElementsByClassName('webcampop')){
  	var wcp = getElementsByClassName('webcampop');
  	for (x=0; x < wcp.length; x++) {
  		//var w, h;
  		//w = wcp[x].getElementsByTagName('img')[0].getAttribute('width');
  		//h = wcp[x].getElementsByTagName('img')[0].getAttribute('height');
    	wcp[x].onclick = function(){ 
		alert ("1 " + this.href);
        PopHtml (this.href,"Webcam","Webcam","resizable=1,scrollbars=yes","800","600","true");
			  return false;
			}
		}
	}
}

function PopHtml (theURL,winName,altName,features,myWidth,myHeight,isCenter,isHidden) {
  if(window.screen)if(isCenter)if(isCenter == 'true') {
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}



function PicPopWebcam (theURL,winName,altName,features,myWidth,myHeight,isCenter,isHidden) {

	//window.setInterval("PicPop()", 1000, theURL,winName,altName,features,myWidth,myHeight,isCenter,isHidden);

	PicPop (theURL,winName,altName,features,myWidth,myHeight,isCenter,isHidden);
}
function PicPop (theURL,winName,altName,features,myWidth,myHeight,isCenter,isHidden) {
  if(window.screen)if(isCenter)if(isCenter == 'true') {
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  if (isHidden == 'true') {
    var overflow = 'hidden';
  }else {
    var overflow = 'auto';
  }
  imagepopup = window.open('','',features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
  with (imagepopup) {
    document.open();
    document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    document.write('<html lang="de" xml:lang="de" xmlns="http://www.w3.org/1999/xhtml">');
    document.write('<head>');
    document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
    document.write('<title>'+winName+'</title>');
    document.write('<style type="text/css">');
    document.write('<!--');
    document.write('body {');
    document.write('margin: 0; overflow:'+overflow+';');
    document.write('}');
    document.write('-->');
    document.write('</style>');
    document.write('<meta http-equiv="imagetoolbar" content="no" />');
    document.write('<script type="text/javascript">function refreshCam(){ rfsh = new Date() ; rfsh = "?"+rfsh.getTime(); if (document.getElementById("bild")) {document.getElementById("bild").src = "'+theURL+'"+rfsh;}; window.setTimeout("refreshCam()", 10000);}; window.onload = refreshCam();</script>');
    document.write('</head>');
    document.write('<body>');
    document.write('<img src="'+theURL+'" border="0" alt="'+altName+'" id="bild" onclick="self.close();"/>');
    document.write('</body>');
    document.write('</html>');
    document.close();
  }
}


function printpage() {
  if (window.print) {
    jetztdrucken = confirm('Möchten Sie dieses Expose jetzt ausdrucken?');
  if (jetztdrucken) window.print();
  } else {
    alert ('Leider unterstützt Ihr Browser diese Funktion nicht.')
  }
}


function hinundweg(layID) {
	if (document.getElementById(layID)){
		var myLayer = document.getElementById(layID);
		if (myLayer.style.display=='none') {
			myLayer.style.display='block';
		} else {
			myLayer.style.display='none';
		}
	}	
};

function show(layID) {
	if (document.getElementById(layID)){
		var myLayer = document.getElementById(layID);
			myLayer.style.display='block';
	}	
};

function hide(layID) {
	if (document.getElementById(layID)){
		var myLayer = document.getElementById(layID);
			myLayer.style.display='none';
	}	
};

function sameheight(divone, divtwo) {
	if (document.getElementById(divone) && document.getElementById(divtwo)){
	var div1 = document.getElementById(divone);
	var div2 = document.getElementById(divtwo);
		if (div1.offsetHeight > div2.offsetHeight) {
			div2.style.height = div1.offsetHeight+'px';
		} else {
			div1.style.height = div2.offsetHeight+'px';
		}
	}	
};

function addLiFirstLastChild () {
	if (document.getElementsByTagName('ul')) {
	  var uls = document.getElementsByTagName('ul');
	  for (c=0; c < uls.length; c++) {
	    var lif = uls[c].firstChild;
		if (lif == undefined) continue;
	    if(lif.nodeType==3){
	      lif.nextSibling.className +=' firstchild';
	    } 
	    if(lif.nodeType==1){
	      lif.className +=' firstchild';
	    }
	    
	    var lil = uls[c].lastChild;
	    if(lil.nodeType==3){
	      lil.previousSibling.className +=' lastchild';
	    } 
	    if(lil.nodeType==1){
	      lil.className +=' lastchild';
	    }
	  }
  }
}

function GetSecondDd() {
	if (document.getElementsByTagName('dd')) {
		var dds,i;
		dds=document.getElementsByTagName('dd');
		for(i=0;i<dds.length;i++) {
			if (i%2==0) {
				dds[i].className +=' second';
			}
		}
	}
}

function GetPicUrl(pic){
	if (document.getElementById(pic)) {
		var webcamurl = document.getElementById(pic).src;
		return webcamurl;
	}
}

started = 0;

function RefreshCam(){ 
	if (document.getElementById("webcampic")) {
		if (started == 0) {
			webcamurl = GetPicUrl("webcampic");
			started = 1;
		}
		rfsh = new Date(); 
		rfsh = "?"+rfsh.getTime(); 
		document.getElementById("webcampic").src = webcamurl+rfsh;
		window.setTimeout("RefreshCam()", 10000);
		} 
}


window.onload=function() {
    relTags();
    changeLinks();
    addLiFirstLastChild();
    GetSecondDd();
		MakeCamPop ();
		RefreshCam();
    //sameheight('gallery', 'info');
}

