#!/usr/bin/perl -wT

use strict;

my $http_cookie = $ENV{'HTTP_COOKIE'};
my $script_name = $ENV{'SCRIPT_NAME'};
my $i;
my $file = "galleries.txt";
my $buf;
my $address;
my @paths;
my @random_paths;
my @pictures;

print "Content-type: text/html\n\n";

print <<END_OF_TOP;
<html>
<head>
<title>
Image Gallery
</title>
</head>
<style type="text/css">
        body { font-family : "times";
        background : #000000;
        color : white; }
        A:link, A:visited { text-decoration : none }
        A:visited { color : #FFFFFF }
        A:link { color : #FFFFFF }
        A:hover { color : #0000FF;
	background :  ;}
        img { border-color: #222222}

</style>
<body>
<a href = "http://www.yikes.com/~pengo">main</a>.images<br><br>
<br><br>
<table bgcolor=#3377aa cellpadding=2 cellspacing=4 align=center>
 <tr>
END_OF_TOP

open(FH, $file);
read(FH, $buf, 1024);
close(FH);
@paths = split(/\n/,$buf);
#while (@paths)
#{
#  for $i (0 .. int(rand(@paths))-1)
#  {
#    push(@paths,shift(@paths));
#  }
#  push(@random_paths,pop(@paths));
#}  
$i = 0;
foreach (@paths)
{
  opendir (DH, $_);
  while(defined($address = readdir(DH)))
  {
    if($address =~ /(\.jpg|\.JPG)/)
    {
      push(@pictures,$address);
    }
  }
  if($i++ %4 == 0) {print " </tr>\n <tr>\n";}
  print"  <td height=150 width=125 align=center valign=bottom>\n  <a href = \"$_/\">";
  print"   <img border = \"3\" src = \"$_/thumbnails/$pictures[int(rand(@pictures))]\">\n";
  s/_/ /;
  print"   </a>\n<br>$_\n";
  print"  </td>\n";
  closedir (DH);
  while(@pictures){pop(@pictures);}
}
print" </tr>\n  <td height=20></td>\n </tr>\n</table>\n</body>\n</html>";

