#!/usr/bin/perl -w

use strict;

chdir "/home/itsme/prj/sites/foksuk/archive";

my @files= glob("*.gif");

my $nrpages= int($#files/6);

print "nrpages=$nrpages  #f= $#files\n";

for (my $page=0 ; $page<=$nrpages; $page++) {

    my $indexfile= "idx$page.html";

    open FH, ">", "$indexfile" or die "can't write $indexfile\n";

    print FH "<html><head><title>foksuk page</title></head><body>";

    for (my $j=0 ; $j<=$nrpages ; $j++) {

        print FH qq(&nbsp;) x 3  unless ($j==0);

        if ($j!=$page) {
            print FH qq(<A HREF="idx$j.html">$j</A>);
        }
        else {
            print FH "$j";
        }
    }
    print FH "<BR><BR>";

    print FH "<DIV align=left>";
    if ($page>0) {
        print FH qq(<A HREF="idx).($page-1).qq(.html">prev</A>);
    }
    else {
        print FH "prev";
    }
    print FH "</DIV>";


    print FH "<DIV align=right>";
    if ($page<$nrpages) {
        print FH qq(<A HREF="idx).($page+1).qq(.html">next</A>);
    }
    else {
        print FH "next";
    }
    print FH "</DIV>";
    print FH "<BR><BR>";

    for (my $i=0 ; $i<6 ; $i++) {
        print FH qq(<IMG src="$files[$page*6+$i]" alt="$files[$page*6+$i]">) if ($files[$page*6+$i]);
    }

    print FH "</body></html>";

    close FH;
}
