#!/usr/bin/perl

use strict;

opendir (DIR, $ARGV[0]) or
  exit "Can't open given directory $ARGV[0]: !$\n";
my (@thefiles) = grep /.*\.jpg$/, readdir DIR;
closedir DIR;

my (@files) = sort (@thefiles);

my (@fname2);
my ($prev) = "00-00"; my ($next) = "";
my ($file); my (@fname) = ();
my ($i, $j); $i = -1, $j = 0;
for $file (@files) {
  next if $file =~ /^INDEX/;
  $i++; $j = $i+1;
  $next = $files[$j+1];
  @fname = split (/\./, $file);
  @fname2 = split (/\./, $next);
  $next = $fname2[0];
  open (FILE, ">" . $ARGV[0] . "/show/" . $fname[0] . ".shtml") 
    or exit "Can't write to " . $ARGV[0] . "/show/" . $fname[0] . ".shtml : $!\n";

  print FILE "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n";
  print FILE "<html>\n";
  print FILE "<head>\n";
  print FILE "<title>Empty</title>\n";
  print FILE "</head>\n";
  print FILE "\n";
  print FILE "<body bgcolor=\"#6D6D6D\">\n";
  print FILE "\n";
  print FILE "<center><font size=\"-2\">\n";
  print FILE "<A HREF=\"" . $prev . ".shtml\">" if $prev ne "00-00";
  print FILE "Prev";
  print FILE "</A>\n" if $prev ne "00-00";
  print FILE " - ";
  print FILE "<A HREF=\"" . $next . ".shtml\">" if $next ne "";
  print FILE "Next";
  print FILE "</A>\n" if $next ne "";
  print FILE "</font></center><BR>\n";
  print FILE "<center><A TARGET=\"_new\" HREF=\"..\/" . $fname[0] . ".jpg\"><img src=\"../mediums/" . $fname[0] . ".jpg\" alt=\"\" border=\"0\" HSPACE=4 VSPACE=4></A></center>\n";
  print FILE "<FONT SIZE=\"-1\"><CENTER><\!--\#include virtual=\"../txt/" . $fname[0] . ".txt\" --><\/CENTER><\/FONT>\n";
  print FILE "<BR>\n";
  print FILE "<center><font size=\"-2\">\n";
  print FILE "<A HREF=\"" . $prev . ".shtml\">" if $prev ne "00-00";
  print FILE "Prev";
  print FILE "</A>\n" if $prev ne "00-00";
  print FILE " - ";
  print FILE "<A HREF=\"" . $next . ".shtml\">" if $next ne "";
  print FILE "Next";
  print FILE "</A>\n" if $next ne "";
  print FILE "</center>\n";
  print FILE "</body>\n";
  print FILE "</html>\n";
  close FILE;
  $prev = $fname[0];
}
