function getMouseY(e) {
  if (IE) { 
    tempY = event.clientY + document.body.scrollTop
  } else {  
     tempY = 	e.screenY
  }  
   if (tempY < 0){tempY = 0}  

   positionY = tempY


 var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myHeight = document.body.clientHeight;
  }
  windowCenter = myHeight / 2;

  return true;
}


function openBox(matkey) {

	if(isClicked == false) {

	var imageId = "";
	if(matkey == "0") {
		$("a#image" + matkey).fancybox({
		'titleShow' :	false,
		'titlePosition'  : 'inside',
		transitionIn	:	'fade',
		transitionOut : 	'fade',
		overlayOpacity : 0.5,
		opacity: true,
		speedIn	:	1,
		speedOut	:	1
	});

	} else {

	imageId = "image_" + matkey;
	$("a#" + imageId).fancybox({
		'titleShow' :	false,
		'titlePosition'  : 'inside',
		transitionIn	:	'fade',
		transitionOut : 	'fade',
		overlayOpacity : 0.5,
		opacity: true,
		speedIn	:	1,
		speedOut	:	1
	});
	
	}
				
	document.getElementById("fancybox-overlay").style.position = "fixed";
	document.getElementById("fancybox-overlay").style.top = "0px";
	document.getElementById("fancybox-overlay").style.left = "0px";
	document.getElementById("fancybox-overlay").style.bottom = "0px";
	document.getElementById("fancybox-overlay").style.right = "0px";
	document.getElementById("fancybox-overlay").style.opacity= "0.50";
	document.getElementById("fancybox-overlay").style.filter = "alpha(opacity=50)";

	//document.getElementById("fancybox-inner").style.margin = "50px 0px 0px 4%";
	document.getElementById("fancybox-outer").style.width = "108%";
	var outerHoehe = 267 + 160;
	document.getElementById("fancybox-outer").style.height = "100%";
	document.getElementById("fancybox-outer").style.padding = "0px";
	document.getElementById("fancybox-outer-header").style.padding = "10px 28px 10px 28px";
	document.getElementById("fancybox-outer").style.top = "0px";
	document.getElementById("fancybox-outer").style.left = "0px"; 


	isClicked = true;
	if(matkey == "0") {
		$("a#image_100016912").click();
	} else {
		$("a#" +  imageId).click();
	}
	


	}
}

function getOffset(strID){
	var objStart = document.getElementById(strID);
	var intOffsetLeft = objStart.offsetLeft;
	var objOffset = {
		left: objStart.offsetLeft,
		top: objStart.offsetTop
	}

	var objHelpOffset = objStart.offsetParent;
	while(objHelpOffset){
		objOffset.left += objHelpOffset.offsetLeft;
		objOffset.top += objHelpOffset.offsetTop;
		objHelpOffset = objHelpOffset.offsetParent;
	}

	return objOffset;
}


function openPopupBild(matkey, imageHeight, imageWidth, imageUrl, bildPosition) {
	
	if(document.all) {
		var popupDiv = document.getElementById("popupDiv_" + matkey);
		var divInhalt = "<div id='bildPopup_" + matkey + "' style='position:absolute; border:1px solid #CCC; background-color:#FFF; width:";
		divInhalt +=	(imageWidth + 20) + "px; height:" + (imageHeight + 20) + "px;'>";
		divInhalt += "<img src='" + imageUrl + "' style='position:relative; top:10px;left:10px;' />";

		popupDiv.innerHTML = divInhalt;
	} else {
		var divPopup = document.createElement("div");
		divPopup.setAttribute("id", "bildPopup_" + matkey);
		divPopup.setAttribute("style", "position:absolute; border:1px solid #CCC; background-color:#FFF; width:"+(imageWidth + 20)+"px; height:" + (imageHeight + 20) + "px;");
		var imgPopup = document.createElement("img");
		imgPopup.setAttribute("src", imageUrl);
		imgPopup.setAttribute("style", "position:relative; top:10px;left:10px;"); 

		divPopup.appendChild(imgPopup);
		document.getElementById("divbox_" + matkey).appendChild(divPopup);

	}
			
			if(positionY < windowCenter) {
				document.getElementById("bildPopup_" + matkey).style.top = (getOffset("divbox_" + matkey).top + 170) + "px";
			} else {
				var topAbstand = getOffset("divbox_" + matkey).top - imageHeight -40;
				if(topAbstand > 0) {
					document.getElementById("bildPopup_" + matkey).style.top = (topAbstand) + "px";
				} else {
					document.getElementById("bildPopup_" + matkey).style.top = 0 + "px";
				}
			}

			if(bildPosition == 1) {
				document.getElementById("bildPopup_" + matkey).style.left = "60px";
			} else if(bildPosition == 2) {
				document.getElementById("bildPopup_" + matkey).style.left = "230px";
			} else if(bildPosition == 3) {
				document.getElementById("bildPopup_" + matkey).style.left = 480 - (imageWidth/2) + "px";
			} else if(bildPosition == 4) {
				document.getElementById("bildPopup_" + matkey).style.left = (728 - imageWidth - 20) + "px";
			} else if(bildPosition == 5 || bildPosition == 0) {
				document.getElementById("bildPopup_" + matkey).style.left = (898 - imageWidth - 20) + "px";
			}					
}

function closePopupBild(matkey) {

	if(document.all) {
		var popupDiv = document.getElementById("popupDiv_" + matkey);
		popupDiv.innerHTML = null;
		popupDiv.innerHTML = "&nbsp;";
		popupDiv.style.height = "0px";
		popupDiv.style.border = "0px";
	} else {
		var popup = document.getElementById("bildPopup_" + matkey);
		document.getElementById("divbox_" + matkey).removeChild(popup);
	}
}
