  var G_baseref = "http://johncipollina.com/cgi-bin/gallery.cgi";
  var G_galleryRH = 200;   // pixels reserved for gallery document template above and below image
  var G_galleryRW = 52;
  var G_galleryMinWidth = 620;
  var G_defaultRH = 16;    // spacing around image
  var G_defaultRW = 16;
  var G_thisRH = 16;
  var G_thisRW = 16;
  var G_viewSize = 80;    // default window size is 80% of available

// *************************************************************
function GetWinOpts(picHeight,picWidth,minWidth,size,fittosize) {
  var iLeft = 2;
  var iTop = 2;
  var aname = navigator.appName;
  var aplat = navigator.platform;
  var iH = window.screen.availHeight - 32;
  var iW = window.screen.availWidth - 8;
  var i = 0;
  var pH = picHeight;
  var pW = picWidth;
  var info = new Array(7);

  iH = iH - (2 * iTop);
  iW = iW- (2 * iLeft);

  if ( (size > 0) && (size < 100) ) {
    iH = (iH / 100) * size;
    iW = (iW / 100) * size;
  }

  // IE (Mac and Win) - seems to need a height adjust from maximum
  // IE/Win shows vert scrollbars
  if (aname.search("Internet Explorer") != -1) {
    if (aplat.search("Win32") != -1)  {
      G_thisRH = G_thisRH + 16;
      G_thisRW = G_thisRW + 26;
    }
	else {
      G_thisRH = G_thisRH + 48;
	  G_thisRW = G_thisRW - 6;
	}
  }

// auto mode, create the smallest window that will accomodate the given image size
// and resize image if necessary to fit
  if (fittosize > 0) {
    if ( (pH > 0) && (pW > 0) ) {
	  if ( (pH + G_thisRH) > iH ) {
		pW = ((iH - G_thisRH) / pH) * pW;
	    pH = iH - G_thisRH;
	  }
	  if ( (pW + G_thisRW) > iW ) {
		pH = ((iW - G_thisRW) / pW) * pH;
	    pW = iW - G_thisRW;
	  }

      iH = pH + G_thisRH;
      iW = pW + G_thisRW;
	}
  }

  if (iW < minWidth) { iW = minWidth; }
  iH = Math.round(iH);
  iW = Math.round(iW);
  pH = Math.round(pH);
  pW = Math.round(pW);
  info[0] = "Height="+iH+",Width="+iW+",screenX="+iLeft+",screenY="+iTop+",scrollbars=yes,resizable=yes";
  info[1] = iH;
  info[2] = iW;
  info[3] = iLeft;
  info[4] = iTop;
  info[5] = pH;
  info[6] = pW;
  return info;
}

// *************************************************************
function StartGallery(name,size) {
  var target = G_baseref + "?gallery=" + name + "&imgno=1&winsize="+G_viewSize;
  var info;
  var i = 0;
  var newWin;

  G_thisRH = G_defaultRH;
  G_thisRW = G_defaultRW;
  info = GetWinOpts(0,0,G_galleryMinWidth,size,0);

  newWin = window.open("","",info[0]);
  newWin.document.write("<HTML><HEAD><TITLE>Loading...</TITLE></HEAD>");
  newWin.document.write("<BODY bgcolor='#000000'><font size='6' color='silver'>Gallery now loading ...</font>");
  newWin.document.write("</BODY></HTML>");
  newWin.document.close;
  newWin.moveTo(info[4],info[3]);  // IE does not always honor screenX,screenY
  newWin.resizeTo(info[2],info[1]);

  i = info[1] - G_galleryRH;
  target += "&maxheight="+ i;
  i = info[2] - G_galleryRW;
  target += "&maxwidth="+ i;
  newWin.location = target;
}

// *************************************************************
function GetGallery(func) {
  var target = G_baseref + "?gallery=" + document.theform.gallery.value;
  var ino = Number(document.theform.imgno.value);
  var icnt = Number(document.theform.imgcnt.value);
  var info;
  var i;

  if (func == 'resize') {
    if ( (document.theform.winsize.value > 39) && (document.theform.winsize.value <= 100) ) {
      info = GetWinOpts(0,0,G_galleryMinWidth,document.theform.winsize.value,0);
      target += "&winsize="+ document.theform.winsize.value;
	  i = info[1] - G_galleryRH;
      target += "&maxheight="+ i;
      i = info[2] - G_galleryRW;
      target += "&maxwidth="+ i;
	  target += "&imgno=" + ino;
      window.resizeTo(info[2],info[1]);

      window.location = target;
      return false;
	}
	else {
	  document.theform.winsize.value = G_viewSize;
	  alert("Window size must be between 40 amd 100");
	  return false;
	}
  }

  if (func == 'prev') {
    if (ino > 1) { ino--; }
	else {
	  alert("This is the first image in the gallery");
	  return false;
 	}
  }
  else {
    if (ino < icnt) { ino++; }
	else {
	  alert("This is the last image in the gallery");
	  return false;
    }
  }

  target += "&winsize="+ document.theform.winsize.value;
  target += "&imgno=" + ino + "&maxheight=" + document.theform.maxheight.value +
          "&maxwidth=" + document.theform.maxwidth.value;
  window.location = target;
  return false;
}


// *************************************************************
function doFull(fname,picHeight,picWidth) {
  var info;
  var newWin;

  info = GetWinOpts(picHeight,picWidth,0,G_viewSize,1);
  newWin = window.open("","",info[0]);
  newWin.document.write("<HTML><HEAD><TITLE>Full View</TITLE></HEAD>");
  newWin.document.write("<BODY bgcolor='#000000'>");
  newWin.document.write("<img src='"+fname+"' border='0' ");
  newWin.document.write("height='"+info[5]+"' width='"+info[6]+"'></BODY></HTML>");
  newWin.document.close;
  return false;
}
