function randpict (root, filter) {
  // select a random picture according to filter criteria
  filterVar = ""; filterVal = "";
  countryFilter = ""; yearFilter = ""; categoryFilter = ""; searchFilter = "";
  if (filter.length > 0) {
    mid = filter.indexOf("=");
    filterVar = filter.substring(1, mid); // between the initial '?' and '='
    filterVal = filter.substr(mid+1);     // after '='
  }
  do {
    i = parseInt(Math.random()*(pics.length-1));
    pictext = pics[i][0];
    for (j=1; j<=7; j++)
      pictext += " " + pics[i][j];
  } while (
    pics[i][0].match('joa')
    || pics[i][1].match('joa')
    || pics[i][2].match('joa')
    || (filterVar == "country"  && pics[i][4] != filterVal) 
    || (filterVar == "year"     && pics[i][5] != filterVal) 
    || (filterVar == "category" && pics[i][6] != filterVal) 
    || (filterVar == "search" && pictext.toLowerCase().indexOf(filterVal.toLowerCase()) == -1)
    );
  //if (filter.length > 0) filter = filter + "&pictures=on";

  imgfile = pics[i][1] + ".jpg";
  alttext = imgfile;
  for (j=2; j<pics[i].length-1; j++)
    alttext += ", " + pics[i][j];

  var ad = ads[parseInt(Math.random()*ads.length)];

  // display picture
  with (document) {
    writeln("<div style='float:right; text-align:left; width: 250px; font-size: 70%; margin: 5px;'>");
    write("<div class='picbox'>");
    write("<a href='" + root + "photos/?size=large&pic=" + pics[i][1] + "' onmouseover='popup(true)' onmouseout='popup(false)'>");
    write("<img border='0' src='" + root + "thumbs/" + imgfile + "' alt='" + alttext + "'>");
    writeln("</a><br />");
    writeln(pics[i][2].substr(0,1).toUpperCase() + pics[i][2].substr(1) + "<br />");
    writeln(pics[i][3] + ", " + pics[i][4] + ", " + pics[i][5] + "<br />");
    if (filter == "")
        writeln("<a href='http://gregvogl.net/photos/'");
    else
        writeln("<a href='http://gregvogl.net/photos/" + filter + "'");
    write("title='View photos of Africa, family and friends.'>More&nbsp;Photos");
    if (filter != "") write (" of " + filterVal);
    writeln("</a>");
    writeln("</div>");
    write("<div class='picbox' style='margin-top: 1em;'>");
    writeln("<div style='color: #999; font-style: italic; margin-bottom: 1em; white-space: nowrap;'>Do-Good Advertisement: " + ad[0] + "</div>");
    if (ad[3])
      write("<a href='" + ad[3] + "' style='line-height: 1.5em; text-decoration: none; background: none;'>");
    write("<img border='0' src='/do-good/" + ad[2] + "' width='128' height='128' alt='' /></a>");
    write("<br />");
    write(ad[1].replace(/\. /g, '.<br />'));
    if (ad[3])
      write("<br /><a href='" + ad[3] + "' style='line-height: 1.8em;'>Learn More</a>");
    writeln("</div>");
    writeln("</div>");
	write("<span id='picpopup' style='display: none; position: absolute; top: 0; left: 0; z-index: 100'>");
    write("<img border='0' src='" + root + "photos/" + imgfile + "' alt='" + alttext + "'>");
    writeln("</span>");
  }
/*
with (document.body.style) {
  minHeight = window.outerHeight;
  backgroundImage = "url('" + root + "photos/" + imgfile + "')";
  backgroundPosition = "bottom right";
  backgroundRepeat = "no-repeat";
}
with (document.body.style) {
  backgroundImage = "url('" + root + "photos/" + imgfile + "')";
  backgroundPosition = "120px 52px";
  backgroundRepeat = "no-repeat";
}
with (document.getElementById('body').style) {
  opacity = 0.9;
  MozOpacity = 0.9;
  KhtmlOpacity = 0.9;
  filter = "alpha(opacity=90)";
}
*/
}
function popup(show) {
	document.getElementById('picpopup').style.display = show ? 'inline' : 'none';
}

