function openwin(elm,prev,next) {
	var msgWindow = window.open('', '_blank', 'toolbar=no');
	msgWindow.document.writeln('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
	msgWindow.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	msgWindow.document.writeln('<html>');
  msgWindow.document.writeln('<meta http-equiv="content-type" content="text/html; charset=utf-8">');
  msgWindow.document.writeln('<head>');  	
	msgWindow.document.writeln('<title></title>');
	var links = document.getElementsByTagName('link');
	var adr;
	for(var i=0;i<links.length;i++) {
		adr = links[i].getAttribute('href');
		if(adr) {
			if(adr.match('.*mod_photo_main.css')) {
				msgWindow.document.writeln('<link media="screen,tv,projection"  type="text/css" rel="stylesheet" href="'+adr+'" />');
				break;
			}
		}
	}	
	msgWindow.document.writeln('<script type="text/javascript">');
	msgWindow.document.writeln('	function getInnerHeight() { ');
	msgWindow.document.writeln('     	if (window.innerHeight) {');
	msgWindow.document.writeln('     		return window.innerHeight;');
	msgWindow.document.writeln('     	} else {');
	msgWindow.document.writeln('     		return document.documentElement.offsetHeight;'); // document.body.clientHeight;
	msgWindow.document.writeln('     	}');
	msgWindow.document.writeln('	}');								    	
	msgWindow.document.writeln('	function getInnerWidth() { ');
	msgWindow.document.writeln('     	if (window.innerWidth) {');
	msgWindow.document.writeln('     		return window.innerWidth;');
	msgWindow.document.writeln('     	} else {');
	msgWindow.document.writeln('     		return document.documentElement.offsetWidth;'); //document.body.clientWidth;
	msgWindow.document.writeln('     	}');
	msgWindow.document.writeln('	}');								    	
	msgWindow.document.writeln('	function imgSize(controlHeight,fotoMargin) {');
	msgWindow.document.writeln('		image=document.getElementById("image_elm");');
	msgWindow.document.writeln('		if (screen.height <= (image.height + 31)) {');
	msgWindow.document.writeln('			window.resizeTo(image.width + 12,screen.height - 100);');
	msgWindow.document.writeln('		} else {');
	msgWindow.document.writeln('			window.resizeTo(image.width+2*fotoMargin,image.height+controlHeight+fotoMargin);');
	msgWindow.document.writeln('			controlx = image.width+2*fotoMargin - getInnerWidth();');
	msgWindow.document.writeln('			controly = image.height+controlHeight+fotoMargin - getInnerHeight();');
	msgWindow.document.writeln('			window.resizeTo(image.width + controlx+2*fotoMargin, image.height + controly+controlHeight+fotoMargin);');
	msgWindow.document.writeln('		}');
	msgWindow.document.writeln('	}');
	msgWindow.document.writeln('function replaceImg(id) {');
	msgWindow.document.writeln('  if (window.opener) {');
	msgWindow.document.writeln('    var openerdoc = window.opener.document;');
	msgWindow.document.writeln('    var onclck = openerdoc.getElementById("mod_photo_a_"+parseInt(id)).getAttribute("onclick");');
	msgWindow.document.writeln('    var statm = onclck.toString().split(";");');
	msgWindow.document.writeln('    var parts = statm[0].toString().split(",");');
	msgWindow.document.writeln('    var prev = parts[1];');
	msgWindow.document.writeln('    var next = parts[2].substring(0,parts[2].length-1);');
	msgWindow.document.writeln('    if (parseInt(prev) < 0) { ');
	msgWindow.document.writeln('      document.getElementById("photo_prev").onclick = function() { return false; };  ');
	msgWindow.document.writeln('      document.getElementById("photo_prev").style.visibility = "hidden";  ');
	msgWindow.document.writeln('    } else { ');
	msgWindow.document.writeln('      document.getElementById("photo_prev").onclick = function() { replaceImg(prev); return false; };  ');
	msgWindow.document.writeln('      document.getElementById("photo_prev").style.visibility = "visible";  ');
	msgWindow.document.writeln('    }');
	msgWindow.document.writeln('    if (parseInt(next) < 0) { ');
	msgWindow.document.writeln('      document.getElementById("photo_next").onclick = function() { return false; };  ');
	msgWindow.document.writeln('      document.getElementById("photo_next").style.visibility = "hidden";  ');
	msgWindow.document.writeln('    } else { ');
	msgWindow.document.writeln('      document.getElementById("photo_next").onclick = function() { replaceImg(next); return false; }; ');
	msgWindow.document.writeln('      document.getElementById("photo_next").style.visibility = "visible";  ');
	msgWindow.document.writeln('    }');
	msgWindow.document.writeln('    var imgsrc = openerdoc.getElementById("mod_photo_a_"+parseInt(id)).getAttribute("href");');
	msgWindow.document.writeln('    document.getElementById("image_elm").setAttribute("src",imgsrc);');
	msgWindow.document.writeln('    '); 
	msgWindow.document.writeln('  }');
	msgWindow.document.writeln(' }');

	msgWindow.document.writeln('</script>');
	msgWindow.document.writeln('</head>');
	msgWindow.document.writeln('<body id="prevnextbody">');
	msgWindow.document.writeln('	<p id="photos_control"> ');
	msgWindow.document.writeln('		<a href="#" id="photo_prev" onclick="replaceImg('+prev+');return false;">Voriges</a> | ');
	msgWindow.document.writeln('		<script type="text/javascript">if (parseInt('+prev+') < 0) document.getElementById("photo_prev").style.visibility = "hidden";</script>');
	msgWindow.document.writeln('		<a href="#" id="photo_close" onclick="window.close()">Schließen</a> | ');
	msgWindow.document.writeln('		<a href="#" id="photo_next" onclick="replaceImg('+next+');return false;">Nächstes</a>');
	msgWindow.document.writeln('		<script type="text/javascript">if (parseInt('+next+') < 0) document.getElementById("photo_next").style.visibility = "hidden";</script>');
	msgWindow.document.writeln('	</p>');
	msgWindow.document.writeln('	<p><a href="#" onclick="window.close();">');
	msgWindow.document.writeln('		<img onload="imgSize(40,0);" src="'+elm.getAttribute('href')+'" id="image_elm" alt="sys_close_window">');
	msgWindow.document.writeln('	</a></p>');
	msgWindow.document.writeln('</body>');
	msgWindow.document.writeln('</html>');
	msgWindow.document.close();
  msgWindow.focus();
  return true;
}

