if(baseURL==undefined){var baseURL="/";}
if(baseDIR==undefined){var baseDIR="/testpix";}
var blankfile=baseURL + "blank.html";
var innerx, innery, outerx, outery, ecks, why;
var fudge_x,fudge_y;
fudge_x=(navigator.appVersion.toLowerCase().indexOf("win") != -1)?32:
        (navigator.userAgent.toLowerCase().indexOf("safari") != -1)?26:
         26; 
fudge_y=(navigator.appVersion.toLowerCase().indexOf("win") != -1)?80:
        (navigator.userAgent.toLowerCase().indexOf("safari") != -1)?37:
         26; 
var lastfix;

var min_x=(navigator.appVersion.toLowerCase().indexOf("win") != -1)?120:
                (navigator.userAgent.toLowerCase().indexOf("safari") != -1)?100:                 15; 
var min_y=(navigator.appVersion.toLowerCase().indexOf("win") != -1)?65:
                (navigator.userAgent.toLowerCase().indexOf("safari") != -1)?100:                 15; 

var curFontSize = 0.87;

var togglekeeper=0;

function clickertoggle(){
        if(!togglekeeper){
                document.getElementById('clicker').style.background='white';
        }else{
                document.getElementById('clicker').style.background='transparent';
        }
        togglekeeper=!togglekeeper;
}

function setFontSize(inc) {
  if( inc >= 1 ) curFontSize *= 1.05;
  else if( inc < 0 ) curFontSize = 0.87;
  else curFontSize *= (1/1.05);
  document.body.style.fontSize = curFontSize+'em';
  return false;
}

function fuxme(height, width){ 
        //alert(height + " w:" + width);
        window.moveTo(0,0);
        window.resizeTo(window.screen.availWidth,window.screen.availHeight);
        document.getElementById("reit").style.height="100%";
}

function fixme(height, width){ 
        var it=document.getElementById("reit");
        if(it.src==lastfix){return;}//firefox loads pix twice for some reason
        if((it.width==0 || it.width==24 )&& (!width && !height)){  // firefox reports 24 sometimes
                setTimeout("fixme()", 100);
                // alert(width + " waiting on Safari" +height);
                return; }  // wait for Safari to load image
        else if(!width && !height){
                var height=it.height ;
                var width = it.width ;
        }
        lastfix=it.src;
        inout();
        var done=0;
        var scale;
        var maxy=(innery-thumbnails-50); 
        var maxx=(innerx-leftright);
        var delta_x=delta_y=100;
        var fixy=height-maxy; // difference in height
        var fixx=width-maxx;  // difference in width
        var track;
        if((fixy<0)&&(fixx<0)){  //best case, both dimensions fit the window
                delta_x=width;
                delta_y=height;
                track="both good";
                document.getElementById("clicked").title="Already Full Size";
                document.getElementById("clicked").href="javascript:return true;";
        }else{ // one or the other side won't fit
                if((fixy>0)&&(fixx>0)){  //worst case, neither dimension fits 
                        if(fixy>fixx){  // height problem is worse than width 
                                delta_y=maxy;
                                scale=height/delta_y;
                                delta_x=Math.floor(width/scale);
                                if(delta_x>maxx){ //if this is really bad
                                        delta_x=maxx;
                                        scale=width/delta_x;
                                        delta_y=Math.floor(height/scale);
                                }
                                track="both bad, height worse";
                        }else{  // width problem is worse than height
                                delta_x=maxx;
                                scale=width/delta_x;
                                delta_y=Math.floor(height/scale);
                                if(delta_y>maxy){ //if this is really bad
                                        delta_y=maxy;
                                        scale=height/delta_y;
                                        delta_x=Math.floor(width/scale);
                                }
                                track="both bad, width worse";
                        }
                }else if((fixy>0)&&(fixx<0)){ // ok width, but height sux
                                delta_y=maxy;
                                scale=height/delta_y;
                                delta_x=Math.floor(width/scale);
                                if(delta_x>maxx){ //if this is really bad
                                        delta_x=maxx;
                                        scale=width/delta_x;
                                        delta_y=Math.floor(height/scale);
                                }
                                track="ok width height sux";
                }else{  // must be ok height, but width adjustment
                                delta_x=maxx;
                                scale=width/delta_x;
                                delta_y=Math.floor(height/scale);
                                if(delta_y>maxy){ //if this is really bad
                                        delta_y=maxy;
                                        scale=height/delta_y;
                                        delta_x=Math.floor(width/scale);
                                }
                                track="ok height width sux";
                }
        }
        msg= "Line 24 iwin.js: \n\n"
        msg+="IMG: w:" + width + " h:" + height + "\n";
        msg+="WMX: w:" + maxx + " h:" + maxy + "\n";
        msg+="WrMX: w:" + innerx + " h:" + innery + "\n";
        msg+=" FX: w:" + fixx + " h:" + fixy + "\n";
        msg+=" DX: w:" + delta_x + " h:" + delta_y + "\n";
        msg+=" scale:" +scale+"\n\nTrack: " +track;
//alert(document.getElementById("pixwin"));
        //alert(msg);

        it.width=delta_x;
        it.height=delta_y;
        it.style.display="inline";

//      alert(document.getElementById('mypixtable').innerHTML);

        document.getElementById('thisone').style.border='3px outset #888888';
        document.getElementById('thisone').focus();
        document.getElementById('hereform').czech.focus();
}


function inout(){
        innerx=(window.innerWidth)?window.innerWidth:document.body.clientWidth ;        innery=(window.innerHeight)?window.innerHeight:document.body.clientHeight;
        outerx=(window.outerWidth)?window.outerWidth:innerx+8;
        outery=(window.outerHeight)?window.outerHeight:innery+56;
        ecks=(window.screenX!=undefined)?window.screenX:window.screenLeft;
        why=(window.screenY!=undefined)? window.screenY:window.screenTop;
//alert(ecks +  " " + why + " wsy:" + window.screenY + " wst:" + window.screenTop);
}

function lertwin(text){
        var srcwidth, srcheight, doxwrite, winvars;
        doxwrite='<html><head><title>Pastable HTML</title> <SCRIPT language="JavaScript" SRC="' + baseURL + baseDIR + 'iwin.js"></SCRIPT><link href="/pix/pix.css" rel="stylesheet" media="screen"></head><body class=pastable><p>' + text +'</body></html>\n\n\n';
        winvars='resizable=1, toolbar=no, status=no, width=800, height=240 scrollbars=yes ';
        resultwin=window.open('','lertWin',winvars);
        resultwin.document.write(doxwrite);
        resultwin.document.close();  // fix for firefox never stops loading
        resultwin.focus();
}

function full_win(srcname){
        doxwrite='<html><head><script language="JavaScript" SRC="' +baseURL +baseDIR + 'iwin.js"></script><link href="/pix/pix.css" rel="stylesheet" media="screen"><title>text goes here</title></head><body  onload="fuxme(' + window.innerWidth + ", " + window.innerHeight + ');"><a style="text-decoration: none;"  href="javascript:cleanup();" title="click me to close me"><center><img style="border: 0; padding:0;" id=reit src="'+ srcname+'" ></a></center></body>\n</html>\n\n\n';
        winvars='resizable=1, toolbar=no, status=no, width=' +  100 + ', scrollbars=yes , height='+ 100;
        resultwin=window.open(blankfile,'newWin',winvars);
        resultwin.document.write(doxwrite);
        resultwin.document.close();  // fix for firefox never stops loading
        resultwin.focus();
}


function img_win(srcname, width, height){
        var x=1000;
        var y=600;
        var scrollbars_show="yes";
        if(width && height){
                if((width < window.screen.availWidth-fudge_x) && (height < window.screen.availHeight-fudge_y)){
                x=width;
                y=height;
                scrollbars_show="no";
                }
        }
        if(srcname.substring(0,4) != "http"){srcname=baseURL +baseDIR  + srcname;}
        var srcwidth, srcheight, doxwrite, winvars;
        doxwrite='<html><head><script language="JavaScript" SRC="' +baseURL +baseDIR + 'iwin.js"></script><link href="/pix/pix.css" rel="stylesheet" media="screen"><title>text goes here</title></head><body  onload="ol();"><a style="text-decoration: none;"  href="javascript:cleanup();" title="click me to close me"><center><img style="border: 0; padding:0;" id=it src="'+ srcname+'" ></a></center></body>\n</html>\n\n\n';
        winvars='resizable=1, toolbar=no, status=no, width=' + x + ', scrollbars=' + scrollbars_show + ', height='+ y;
        resultwin=window.open(blankfile,'newWin',winvars);
        resultwin.document.write(doxwrite);
        resultwin.document.close();  // fix for firefox never stops loading
        resultwin.focus();
}

function winfo(item){
        inout();
        var message="Window Stats\n\n";
        if(item.width){message+="Item w:" + item.width + " h:" + item.height+"\n";}
        message+="Screen w:" + window.screen.width + " h:" + window.screen.height + "\n";
        message+="Available w:" + window.screen.availWidth+ " h:" + window.screen.availHeight + "\n";
        message+="in Client w:" + innerx + " h:" + innery + "\n";
        message+="out Client w:" + outerx + " h:" + outery + "\n";
        message+="\n\nX:" + ecks + " Y:" + why;
        message+="\n\nfX:" + fudge_x + " fY:" + fudge_y;
        alert(message);
}

function cleanup(){
//      winfo(it);
        window.close();
}

function ol(){ // this is the function which actually resizes the loaded full-screen window
                // it has to load the picture first, though
        inout();
        var it=document.getElementById("it");
        if((it.width==0 || it.width==24 ) && (!width && !height)){  // firefox reports 24 sometimes
                setTimeout("ol()", 10);
                //alert("waiting on Safari "+ it.src);
                return; }  // wait for Safari to load image
        else{
                var height=it.height ;
                var width = it.width ;
        }
        lastfix=it.src;
        if(it.width<=0){
                width=x;
                height=y;
        } 
//else{ 
//              width=(it.width>window.screen.availWidth)?window.screen.availWidth:it.width;
//              height=(it.height>window.screen.availHeight)?window.screen.availHeight:it.height;
//      }
        if(height+why > window.screen.availHeight-fudge_y ||
           width+ecks > window.screen.availWidth-fudge_x ){
                window.moveTo(0,0);
        }
        if(height+fudge_y > window.screen.availHeight ||
           width+fudge_x > window.screen.availWidth){
                if(navigator.appVersion.toLowerCase().indexOf("win") != -1){
                   fudge_x+=22; // windoze scrollbar
                }
                //alert("h:"+height+" w:"+why+" sah:" +window.screen.availHeight);
                if(width+fudge_x < window.screen.availWidth){
                        window.resizeTo(width+fudge_x,window.screen.availHeight);
                }else if(height+fudge_y < window.screen.availHeight){
                        //alert("h:"+height+" y:"+fudge_y+" saw:" +window.screen.availWidth);
                        window.resizeTo(window.screen.availWidth,height+fudge_y);
                }else{
                        window.resizeTo(window.screen.availWidth,window.screen.availHeight);
                }
        }else{
                var newwidth=width+fudge_x;
                var newheight=height+fudge_y;
                if(newwidth<min_x){newwidth=min_x;}
                if(newheight<min_y){newheight=min_y;}
                //alert(document.body.clientHeight);
                //alert("nh:" +newheight + " nw:" + newwidth + " mx:" + min_x + " my:" + min_y + " fx:" + fudge_x + " fy:" + fudge_y);
                if(navigator.appVersion.toLowerCase().indexOf("msie") != -1){
                        window.moveTo(0,0);
                }
                window.resizeTo(newwidth, newheight);
//alert(newwidth + " "+ newheight + " " + width);
        }
        xtest=it.src;
        arx=xtest.split("/");
        document.title=arx[arx.length-1];
//      alert(document.title);
//      setTimeout('document.title="oops";alert("done");',5000);
        //nothing convinces Safari to display this, BTW
}


