
var bg = null;
var container = null;
var image = null;



function windowHeight () { 
      if (window.innerHeight) { 
           return window.innerHeight; 
      } else if (document.body && document.body.offsetHeight) { 
           return document.body.offsetHeight; 
      } 
 } 
 function windowWidth () { 
      if (window.innerWidth) { 
           return window.innerWidth; 
      } else if (document.body && document.body.offsetWidth) { 
           return document.body.offsetWidth; 
      } 
 }

function verlauf(a)	{
	bg.style.opacity = a;
	a = a + 0.05;

	if (a < 0.7)	{
		setTimeout('verlauf('+ a +')', 20);
	}
}

function viewImage (imageSrc,width,height) {
	 bg = document.getElementById("galeryBg"); 
     container = document.getElementById("imageContainer"); 
     image = document.getElementById("galeryImage"); 


	pr = width/height; //Verhältnis zwischen Höhe und Breite
	
	if(height > windowHeight()-50) { 
           height = windowHeight()-50; 
           width=pr*height; 
    } 
    if(width > windowWidth()-50) { 
           width = windowWidth()-50; 
           height=(width/pr); 
    }

	containerWidth = parseInt(width) + 10; 
    containerHeight = parseInt(height) + 10; 
    containerOffX = -containerWidth/2; 
    containerOffY = -(containerHeight/2);

	image.src = imageSrc; 
    image.style.width = width + "px"; 
    image.style.height = height + "px";

	bg.style.display = "block";

	container.style.marginLeft = containerOffX + "px"; 
    container.style.marginTop = containerOffY + "px";
	container.style.display = "block";
 }

 function displayImage() {
      image.style.visibility = "visible";
      container.style.backgroundImage = "none";
 }

 function closeImage () { 
      bg.style.display = "none"; 
      image.src = "";
      image.style.visibility = "hidden";
      container.style.display = "none";
      container.style.backgroundImage =  "url(./img/loading.gif)";
 }



// Infobox

 function closeperclick () { 
      
	 if (document.all) { 
           infobox = document.all['closeperclick']; 
     } else { 
           infobox = document.getElementById('closeperclick'); 
     }
	 
	 infobox.style.display = "block";

 }

 function endcloseperclick () { 
      
	 infobox.style.display = "none";

 }

document.onmousemove = infoboxposition;


 function infoboxposition(e) {

	if (document.all) { 
		   infobox = document.all['closeperclick']; 
           posX = event.x; 
           posY = event.y; 
      } else { 
		   infobox = document.getElementById('closeperclick'); 
           posX = e.pageX; 
           posY = e.pageY; 
      }

		   posX = posX + 15;
		   posY = posY + 24;


	 infobox.style.left = posX + "px"; 
     infobox.style.top = posY + "px";
 
 }