var numPicsUp=0;
function showAPic(S,W,H,Bg){
var b=32,g=20,pC=6;

var wN=(0<=(i=S.lastIndexOf('/')))?S.substring(i+1,S.length-1):S;
wN=(0<=(i=wN.indexOf('.')))?wN.substring(0,i):wN;

var pm='scrollbars=1,';
pm += 'resizeable=1,';
pm += 'width='+(W+2*b)+',';
pm += 'height='+(H+2*b)+',';
pm += 'screenX='+g*(numPicsUp%pC)+',';
pm += 'screenY='+g*(Math.floor(numPicsUp++/pC)%pC);

var Pg='<html>\n<head>\n';
Pg += '<link rel="SHORTCUT ICON" href="http://math.ucr.edu/ftm/images/bajaIcon.ico">\n';
Pg += '<title>Click the image to close</title>\n';
Pg += '<script>\n';
Pg += 'function init() {\n';
Pg += ' W=opener.W;H=opener.H;\n';
Pg += ' window.onresize=fitPic;\n';
Pg += '}\n';
Pg += 'function fitPic() {\n';
Pg += ' var f=Math.min((innerWidth-'+2*b+')/'+W+',(innerHeight-'+2*b+')/'+H+');\n';
Pg += ' var fw=Math.ceil(f*'+W+');\n';
Pg += ' var fh=Math.ceil(f*'+H+');\n';
Pg += ' with(window.document.images[0]){width=fw;height=fh;}\n';
Pg += '}\n';
Pg += '</script>\n';
Pg += '</head>\n';
Pg += '<body'+((Bg!=null)?' bgcolor="#'+Bg+'"':'');
Pg += ' onLoad="init()"';
Pg += '>\n';
Pg += '<table width="100%" height="100%" cellspacing="0" cellpadding="0">\n';
Pg += ' <tr><td align="center" valign="middle">\n';
Pg += ' <table border="0" cellspacing="0" cellpadding="0">\n';
Pg += '  <tr><td bgcolor="#BBBBBB" align="center" valign="middle">\n';
Pg += '  <a href="javascript:void(0);" onClick="self.close();">\n';
Pg += '  <img src="'+S+'"';
Pg += ' alt="Click the image to close"';
Pg += ' border="0"';
Pg += ' width="'+W+'"';
Pg += ' height="'+H+'"';
Pg += '>\n  </a>\n  </td></tr>\n </table>\n</td></tr>\n</table>\n</body>\n</html>';

win=window.open("",wN,pm);

with(win.document){open();write(Pg);close();}

return false;
}

