var realHeight;

window.onload=function() {
	if (document.getElementById('navigation')){
		realHeight = document.getElementById('navigation').offsetHeight;
	}
	resizeNavigation();
	showToTopLink();
}

window.onresize=function()
	{
	resizeNavigation();
	showToTopLink();
	}


function resizeNavigation(){
	if (document.getElementById('navigation') && document.getElementById('mainContent')){
		if (document.getElementById('navigation').offsetHeight < document.getElementById('mainContent').offsetHeight+120){
			document.getElementById('navigation').style.height = document.getElementById('mainContent').offsetHeight+120+'px'
		} 
		else {
			if (window.innerHeight){
				if (window.innerHeight > document.getElementById('navigation').offsetHeight)
				{
					document.getElementById('navigation').style.height = window.innerHeight+'px';
				}
				else{
					document.getElementById('navigation').style.height = realHeight+"px";
				}
			}
			else if (document.body.offsetHeight){
				if (document.body.offsetHeight > document.getElementById('navigation').offsetHeight){
					document.getElementById('navigation').style.height = document.body.offsetHeight-5+'px';
				}
				else{
					document.getElementById('navigation').style.height = realHeight+"px";
				}
			}
		}
		if (window.innerHeight){
			if (window.innerHeight > document.getElementById('mainContent').offsetHeight+120){
				document.getElementById('navigation').style.height = window.innerHeight+'px';
			}
		}
		else if (document.body.offsetHeight){
			if (document.body.offsetHeight > document.getElementById('mainContent').offsetHeight+120){
				document.getElementById('navigation').style.height = document.body.offsetHeight-5+'px';
			}
		}
	}
}	



function imagePopup(path, image, c, i) {
  var win=window.open("/popup.html?path="+path+"&image="+image+"&contentCounter="+c+"&imagesCounter="+i , "imagePopupWindow", "scrollbars=yes,resizable=yes,width=800,height=600");
  // Maybe the user has a popup blocker.
  if (! win)
    alert("Sie müssen Ihren Popup-Blocker deaktivieren, damit Sie das Bild sehen können!");
}


/**
 * Resize an image popup to fit the image.
 */

function resizeImagePopup() {
  var image = document.getElementById("popupImage");
  var imageWidth = image.width;
  var imageHeight = image.height;
  var resizeWidth = imageWidth;
  var resizeHeight = imageHeight;
  // Check if image is wider than screen.
  if (imageWidth >= (screen.width - 150))
    resizeWidth = screen.width - 150;
  // Check if image is higher than screen.
  if (imageHeight >= (screen.height - 150))
    resizeHeight = screen.height - 150;
  // ie needs more space because he always shows the vertical scrollbar
  if (document.all)
    window.resizeTo(resizeWidth + 50, resizeHeight + 120);
  else
    window.resizeTo(resizeWidth + 20, resizeHeight + 100);

  centerImagePopup();
}

/**
 * Center an image popup to the visible screen.
 */

function centerImagePopup() {
  var pixelX=document.all? window.document.body.clientWidth : window.innerWidth;
  var pixelY=document.all? window.document.body.clientHeight : window.innerHeight;
  var left = parseInt(screen.width/2-pixelX/2);
  var top = parseInt(screen.height/2-pixelY/1.3);
  // Check for negative values.
  if (left < 0)
    left = 0;
  if (top < 0)
    top = 0;
  window.moveTo(left, top);
}

function openNewWindow(pfad){
	F1 = window.open(pfad ,"Detailansicht","width=620,height=820,left=0,top=0");
	F1.focus();
}


/**
 * Show back to top link only if the body
 * is longer than the window height.
 */

function showToTopLink() {
  var winHeight = parseInt((self.innerHeight) ? self.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : (document.body) ? document.body.clientHeight : 0);
  var bodyHeight = parseInt(document.getElementById('mainContent').offsetHeight+100);
  if (winHeight <= bodyHeight) {
    var toTopContainer = document.getElementById("toTopContainer"); 
    if (toTopContainer) {
      toTopContainer.style.display = "block";
    }
  }
  else{
  	var toTopContainer = document.getElementById("toTopContainer");
  	if (toTopContainer) {
      toTopContainer.style.display = "none";
    }
  }
}