////////////////////////////////////////////////////////////////////////////////////
//
//    ZemPopLib.js 'Zemaiciams'
//
////////////////////////////////////////////////////////////////////////////////////

window.onerror=null; 

var pop=null; 
var popwin=null;

var filwin=null;
var filwinName="FileW";

var scrX, scrY;
var scrW, scrH;


function RodykFile(FileNr)
{ 
  w=640; h=screen.availHeight/2+16;
  if ( h<480 ) h=480;

  scrX=12; scrY=screen.availHeight-h-48;
  if ( scrY<32) scrY=32; 

  File="../Straipsniai/"+FileNr+".htm";
  OpenFileWin(File,scrX,scrY,w,h);
}


function RodykFile0(FileNr)
{ 
  w=640; h=screen.availHeight/2+16;
  if ( h<480 ) h=480;

  scrX=12; scrY=screen.availHeight-h-48;
  if ( scrY<32) scrY=32; 

  File="../Straipsniai/"+FileNr+"_s.htm";
  OpenFileWin(File,scrX,scrY,w,h);
}





function RodykFileFr1(FileNr)
{ 
  w=640; h=screen.availHeight/2+16;
  if ( h<480 ) h=480;

  scrX=12; scrY=screen.availHeight-h-48;
  if ( scrY<32) scrY=32; 

  File="../Straipsniai/Frames1.htm?";
  File=File + FileNr; 

  OpenFileWin(File,scrX,scrY,w,h);
}

function RodykFileFr2(FileNr)
{ 
  w=640; h=screen.availHeight/2+16;
  if ( h<480 ) h=480;

  scrX=12; scrY=screen.availHeight-h-48;
  if ( scrY<32) scrY=32; 

  File="../Straipsniai/Frames2.htm?";
  File=File + FileNr; 

  OpenFileWin(File,scrX,scrY,w,h);
}



function RodykFileKampe(File,w,h)
{ 
  scrX=screen.availWidth-w-12;
  if ( scrX<0 ) scrX=0;  

  scrY=screen.availHeight-h-32;
  if ( scrY<0 ) scrY=0;  

  OpenFileWin(File,scrX,scrY,w,h);
}

function OpenFileWin(url,x,y,w,h) 
{
  ClosePopWindow(); 
  CloseFileWindow(); 

  if ( window.opener )
  {
    window.opener.FileWin=window.open(url,window.opener.FileWinName,
      "resizable=no,scrollbars=yes,menubar=no,width="+w+",height="+h+",left="+x+",top="+y);

    if ( window.opener.FileWin.focus ) window.opener.FileWin.focus();  
  }
  else
  {
    filwin=window.open(url,filwinName,
      "resizable=no,scrollbars=yes,menubar=no,width="+w+",height="+h+",left="+x+",top="+y);

    if ( filwin.focus ) filwin.focus();  
  }
}

function CloseFileWindow() 
{
  if ( window.opener )
  { 
    if ( window.opener.FileWin!=null && window.opener.FileWin.open ) window.opener.FileWin.close();     window.opener.FileWin=null; 
  }
  else
  {
    if ( filwin!=null && filwin.open ) filwin.close(); 
    filwin=null; 
  }
}


function MyScreen() 
{
  scrW=screen.availWidth-32;
  scrH=screen.availHeight-96;
}
 

function ClosePopWindow() 
{
  CloseFileWindow(); 

  if ( parseInt(navigator.appVersion)<4 ) return;

  if ( popwin!=null && popwin.open ) popwin.close(); 
  popwin=null; 
}

function CloseAllWindows() 
{
  ClosePopWindow();
  CloseFileWindow(); 
}

function OpenZoomed(nr) 
{
  var str;
  var Zoom=1;            

  if ( parseInt(navigator.appVersion)<4 ) return;  

  ClosePopWindow(); 

  url="../Vaizdai/"; 
  url=url+nr; 
  url=url+"_d.jpg";

  txth="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  txt="Nuotrauka"+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth+txth;

  str="<html><head><title>"+txt+"</title>";

  str=str+"<SCRIPT language=JavaScript1.2> ";

  str=str+"var curElement, imgHeight=0, imgWidth=0, oldLeft=0, oldTop=0; "; 

  str=str+"var kf=1; ";
  str=str+"var wMark; ";
  str=str+"var wPosFl=0; ";
  str=str+"var theIm=null; ";
  str=str+"var imReady=null; ";
  str=str+"var ZoomFl=0; ";
  str=str+"var hZoomFl=0; ";
  str=str+"var zooming=1; ";
  str=str+"var windowHeight, pictHeight, pictActHeight; "; 
  str=str+"var windowWidth, pictWidth, pictActWidth; ";  

  str=str+"function DisplayNewSize(theImg){ "; 
  str=str+"windowHeight=pictHeight=pictActHeight=theImg.height; "; 
  str=str+"windowWidth=pictWidth=pictActWidth=theImg.width; ";  

//  str=str+"alert('Img: '+theImg.name+' '+pictActWidth+' '+pictActHeight); ";
//  str=str+"alert('Scr: '+screen.width+' '+screen.height); ";

//  str=str+"window.document.close();";

  str=str+"if ( windowWidth>screen.width-64 ) { ";
  str=str+"kf=windowWidth/(screen.width-64); ";
  str=str+"windowWidth=windowWidth/kf; ";
  str=str+"windowHeight=windowHeight/kf; ";
  str=str+"ZoomFl=1; } ";

  str=str+"windowHeight=pictHeight=parseInt(windowHeight); "; 
  str=str+"windowWidth=pictWidth=parseInt(windowWidth); ";  

  str=str+"if ( zooming==1 ) { ";
  str=str+"theImg.height=pictHeight; "; 
  str=str+"theImg.width=pictWidth; ";  
  str=str+"} else { ";
  str=str+"theImg.height=pictActHeight; "; 
  str=str+"theImg.width=pictActWidth; ";  
  str=str+"} ";

  str=str+"windowWidth=windowWidth+28; ";
  str=str+"windowHeight=windowHeight+60; ";
//  str=str+"alert('Win: '+windowWidth+' '+windowHeight); ";

  str=str+"if ( windowHeight>screen.height-96 ) ";
  str=str+"{ windowHeight=screen.height-96; ZoomFl=1; hZoomFl=1; }";

  str=str+"self.resizeTo(windowWidth,windowHeight); "; 
  str=str+"theIm=theImg; imReady=true; "; 

  str=str+"return; } ";

  str=str+"function imChange() { ";

  str=str+"if ( imReady==null || ZoomFl==0 ) return; ";

  str=str+"if ( zooming==1 ) zooming=0; else zooming=1; ";

  str=str+"if ( zooming==1 ) { ";
  str=str+"theIm.height=pictHeight; "; 
  str=str+"theIm.width=pictWidth; ";  

  str=str+"hZoomFl=1; "; 
  str=str+"if ( pictHeight<=windowHeight+4 ) { ";
  str=str+" hZoomFl=0; } ";  

  str=str+"} ";
  str=str+"else { ";
  str=str+"theIm.height=pictActHeight; "; 
  str=str+"theIm.width=pictActWidth; "; 
  str=str+"} ";

  str=str+"theIm.style.pixelLeft=0; "; 
  str=str+"theIm.style.pixelTop=0; ";

  str=str+"return; } ";

  str=str+"</SCRIPT>";

  str=str+"</head>";

  str=str+"<body bgcolor='#eeeeee' topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>";

  str=str+"<center>";

  str=str+"<div style='position:absolute; left:0px; top:0px'>";
  str=str+"<img src="+url+" alt='' name='imnm' onload='DisplayNewSize(this)' style='position:absolute; top:0pt; left:0pt; z-index:1;'>";
  str=str+"</div>";

  str=str+"</center></body></html>"; 

  if ( Zoom==0 ) 
  {
    str="<html><head><title>Zoom</title></head>";

    str=str+"<body bgcolor='#dddddd'><center>";

    str=str+"<div style='position:absolute; left:0px; top:0px'>";
    str=str+"<img src="+url+" id='pav' alt=''>";
    str=str+"</div>"; 

    str=str+"</center></body></html>"; 
  }

  MyScreen();

pop='menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhist=no,width='+scrW/2+',height='+scrH/2+',top=16,left=4';

  popwin=window.open("",'Popupas',pop);

  popwin.document.write(str); 
  popwin.document.close();

  if ( popwin.focus ) popwin.focus(); 
}

function ClosePopWindow() 
{
  if ( parseInt(navigator.appVersion)<4 ) return;  

  if ( popwin!=null && popwin.open ) popwin.close(); 
  popwin=null; 
}






