#!/usr/bin/perl

use Getopt::Std;
use File::Basename;
use Cwd;

$index = "index.html";
$dir = getcwd;
my($filename, $directories, $suffix) = fileparse($dir);
$title    = "Gallery\n";
my $tnperrow=4;   # thumbnails per row
open (PAGE, ">$index") || die "Problem: Can't write\n";
    
# create the index page
print PAGE qq*
<html><head><title>$title</title></head>
<body bgcolor=white><h1>$title</h1>
<table cellspacing=10>
*;

my @sets = (<*>);
my @pics = ();
foreach $set (@sets) {
if (chdir $set) 
  {
    print "subdirectory '$set'\n" ;
    ############################
my $counter=0;
chdir  "tn/";
my @tns = (<*>);
my $_ =  shift(@tns);

print PAGE "<tr valign=bottom>" if (!($counter++%$tnperrow));
  print PAGE "<td>";

  @stat = stat $_;
  print PAGE qq*<center>
    
    <a href="$set/index.html"><img src="$set/tn/$_" </a><br>
    
        <small><b>$set</b><br>*.
    
    qq*</small>

    \n*;
    
  print " ... done\n";
  
    
    ############################
    chdir $dir;
  }
}

print PAGE qq*
  </table><hr>

  </body></html>
*;

close PAGE;

