// Autosized window
function popImgSize(img){
  pimg= new Image();
  pimg.src=(img);
  imgCtrl(img);
}
function imgCtrl(img){
  if((pimg.width!=0) && (pimg.height!=0))
    viewImg(img);
  else{
    funzione="imgCtrl('"+img+"')";
    intervallo = setTimeout(funzione,20);
  }
}
function viewImg(img){
  w = pimg.width+20;
  h = pimg.height+20;
  imgStr = "width="+w+",height="+h;
  imgWin = window.open(img,"",imgStr);
}

// menus

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



// *** OPTIONAL CODE FROM HERE DOWN ***

// These two lines handle the window resize bug in NS4. See <body onResize="...">.
// I recommend you leave this here as otherwise when you resize NS4's width menus are hidden.

var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');


// This is a quick snippet that captures all clicks on the document and hides the menus
// every time you click. Use if you want.
/*
if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;

function clickHandle(evt)
{
 if (isNS4) document.routeEvent(evt);
 hideAllBut(0);
}
*/

function swapImage(imageName, path) {
	document.images[imageName].src = path;
}

//================================================

var popwin = 1;
function popUp(page, width, height) {
	popwin = popwin+1;
	popwin.toString();
	newWindow = window.open(page, popwin, "toolbar=no,menubar=no,width="+width+",height="+height+",status=no,scrollbars=yes,alwaysRaised=yes,resizable=yes");
}
// Set size bio popup window
function popBio(url) {
	popUp(url,540,400);
}

//===================================================

//this function returns parameters from the URL
function getParam(theArgName) {
	sArgs = location.search.slice(1).split('&');
    r = '';
    for (var i = 0; i < sArgs.length; i++) {
        if (sArgs[i].slice(0,sArgs[i].indexOf('=')) == theArgName) {
            r = sArgs[i].slice(sArgs[i].indexOf('=')+1);
            break;
        }
    }
    return (r.length > 0 ? unescape(r).split(',') : '')
}

//===================================================

//this function prints the thumbnails if no particular image has been selected yet
function printThumbnails() {
	document.write("<table width='75%' align='center' cellpadding='5'><tr>")
	for(i=0;i<pics.length;i++) {
		document.write("<td align='center'><a href='"+fileName+"?img="+i+"'><img src='"+pics[i]+"' height='100' border='1'></a></td>");
		if ((i + 1) % columns == 0) {
			document.write("</tr><tr>");
		}
	}
	var extraCells = pics.length % columns;
	for(i=0;i<extraCells;i++) {
		document.write("<td>&nbsp;</td>")
	}
	document.write("</tr></table>");
}

//===================================================

//this function prints the large image that has been selected, as well links back to the index, and to the next and last image
function printImage(img) {
	document.write("<center>");
	document.write("<img src='"+pics[img]+"' border='2' height='600'>");
	document.write("<br><br><a href='"+fileName+"'>Go Back To The Index</a><center>");
	
	var next = img - 1 + 2; 
	var prev = img - 1;
	var printprev = "yes";
	var printnext = "yes";
	if (next == pics.length) printnext = "no";
	if (prev < 0) printprev = "no";
	document.write("<table width='75%' align='center'><tr>");
	if (printprev == "yes") document.write("<td align='left'><a href='"+fileName+"?img="+prev+"'>Previous Image</a></td>");
	if (printnext == "yes") document.write("<td align='right'><a href='"+fileName+"?img="+next+"'>Next Image</a></td>");
	document.write("</tr></table>");
}
