function build_tpicgal(id){
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");
	// loop through all anchor tags
  var z = 1;
  for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "tplink")){
      anchor.target = "_blank";
			anchor.onclick = function () {fademe(this); return false;}
			if (z == 1){
        switchImgs(anchor);
      }
      z++;
		}
	}
}

function fademe(link){
  $('#pictitle').fadeOut("normal");
  $('#bigImg').fadeOut("normal",function(){
    $('div.bigImgBox').empty();
    $('div.bigImgBox').html('<img id="bigImg" style="display: none;" /><p id="pictitle" style="display:none;"></p>&nbsp;');
    switchImgs(link);
  });
}

function switchImgs(link){
	// preload image
	imgPreload = new Image();
  var objImage = document.getElementById('bigImg');
	imgPreload.onload = function(){
		objImage.src = link.href;
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		}
	}
	imgPreload.src = link.href;
	$('#bigImg').fadeIn("normal");
	if (link.getAttribute("rev")){
    $('#bigImg').wrap("<a href=\""+link.getAttribute("rev")+"\" target=\"_blank\" title=\"klick zum Vergrößern\"></a>");
  }
	
  $('#pictitle').text(link.title);
  $('#pictitle').fadeIn("normal");
}

function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}
