//written by Ralf Einhorn - ein, einhorn-net.de (c) 19981101, 19990128, 20020416, 20020501, 20020917
//do not reuse without permission

var wSample=null;
var sTitle="";
var sUrl="";
var iPic=null;
var nVer;
var nH=0, nW=0;
var sDefBgCol="#ffffff";
var sBgColor=sDefBgCol;
var nVer=parseInt(navigator.appVersion.charAt(0));
var p=navigator.appVersion.indexOf("MSIE");
if (p>0) nVer=parseInt(navigator.appVersion.charAt(p+5));


//call onUnload
function cleanUp() {
if(wSample) if (!wSample.closed) wSample.close();
}

function sFN(sURL) {
nStart=sURL.lastIndexOf("/");
nEnd=sURL.lastIndexOf(".");
return (sURL.substring(nStart+1, nEnd));
}


function showPic(sUrl, nW, nH, spTitle, sBgC) {
if(wSample) if (!wSample.closed) wSample.close();
if (spTitle) sTitle=spTitle; else sTitle="";
if(sBgC) sBgColor=sBgC; else sBgColor=sDefBgCol;
var sOpts="width="+nW+",height="+nH+",resizable=no";
wSample=window.open("", "pic", sOpts);
wSample.focus();
var dSample=wSample.document;
dSample.open("text/html");
dSample.writeln("<html>\n<head>\n<title>"+sTitle+"</title>\n</head>");
dSample.writeln("<body bgcolor=\""+sBgColor+"\" background=\""+sUrl+"\">");
dSample.writeln("</body>\n</html>");
dSample.close();
}

function showPicture(spUrl, spTitle, sBgC) {
var sOpts="width=100,height=100";
if (nVer<=4) sOpts+=",resizable=yes"; else sOpts+=",resizable=no";
wSample=window.open("", "pic", sOpts);
if (spTitle) sTitle=spTitle; else sTitle="";
if(sBgC) sBgColor=sBgC; else sBgColor=sDefBgCol;
sUrl=spUrl;
iPic=new Image();
iPic.src=sUrl;
var dSample=wSample.document;
dSample.open("text/html");
dSample.writeln("<html>\n<head>\n<title>"+sTitle+"</title>\n</head>");
dSample.writeln("<body bgcolor=\""+sBgColor+"\" text=\"#e0e0e0\">\n"+sTitle+"...");
dSample.writeln("</body>\n</html>");
dSample.close();
finishPic();
}

function finishPic(){
if (!iPic.complete) {
 setTimeout('finishPic()', 200);
 } else {
 nW=iPic.width;
 nH=iPic.height;
 if(wSample.innerWidth) { //mozilla
  wSample.resizeTo(nW,nH); //wrong, but needed
  wSample.innerWidth=nW;
  wSample.innerHeight=nH;
  } else { //IE
  var sOpts="width="+nW+" height="+nH;
  if (nVer<=4) sOpts+=",resizable=yes"; else sOpts+=",resizable=no";
  if (wSample) if (!wSample.closed) wSample.close();
  wSample=window.open("", "pic", sOpts);
  }
 wSample.focus();
 var dSample=wSample.document;
 dSample.open("text/html");
 dSample.writeln("<html>\n<head>\n<title>"+sTitle+"</title>\n</head>");
 dSample.writeln("<body bgcolor=\""+sBgColor+"\" background=\""+sUrl+"\">");
 dSample.writeln("</body>\n</html>");
 dSample.close();
 }
}


function zoomImg(iPic, nZoom, sBgC) {
if (wSample) if (!wSample.closed) wSample.close();
var sOpts="";
var sInfo="";
var pc=0;
if(!nZoom) nZoom=2;
if(nZoom==100) { nZoom=1; pc=1; }
nW=iPic.width*nZoom;nH=iPic.height*nZoom;
sUrl=iPic.src;
sTitle=iPic.name;
if (sTitle=="") sTitle=sFN(sUrl);
if(sBgC) sBgColor=sBgC; else sBgColor=sDefBgCol;
if (pc==0) {
 sInfo=" (X"+nZoom+")";
 if ((nW>screen.width) || (nH>screen.height)) {
  if (nW>screen.width) {nWn=screen.width-300;} else {nWn=nW+20;}
  if (nH>screen.height) {nHn=screen.height-300;} else {nHn=nH+20;}
  sOpts="width="+nWn+",height="+nHn+",scrollbars=yes,resizable=yes";
  } else {
  sOpts="width="+nW+",height="+nH+",scrollbars=no,resizable=no";
  }
 } else {
 sOpts="width="+nW+",height="+nH+",scrollbars=no,resizable=yes";
 }
sOpts+=",dependent=no";
//sOpts+=",dependent=no,toolbar=yes,menubar=yes,location=yes,status=yes";
wSample=window.open("", "pic", sOpts);
wSample.focus();
var dSample=wSample.document;
dSample.open("text/html");
dSample.write("<html>\n<head>\n<title>"+sTitle+sInfo+"</title>\n</head>\n<body bgcolor=\""+sBgColor+"\" marginwidth=\"0\" marginheight=\"0\" topmargin=\"0\" leftmargin=\"0\">");
if(pc==0) dSample.write("<img title=\""+iPic.alt+"\" width=\""+nW+"\" height=\""+nH+"\" src=\""+sUrl+"\"></body>\n</html>");
else dSample.write("<img width=\"100%\" height=\"100%\" src=\""+sUrl+"\"></div></body>\n</html>");
dSample.close();
}

function zoomImage(sPic, nZoom, sBgC) {
var iPic=eval("document.images."+sPic);
zoomImg(iPic, nZoom, sBgC);
}

function zoomInfo() {
if (wSample) if (!wSample.closed) alert("Title="+sTitle+"\nURL="+sUrl+"\nW/H="+nW+"/"+nH+"\ninnerWidth/Height="+wSample.innerWidth+"/"+wSample.innerHeight+"\n\nNavigator Version="+nVer); else alert("window closed");
else alert("no active window");
}
