#!/usr/bin/perl

print "Content-type: text/html\n\n";
$curdir=`pwd`;
$image = $ENV{'QUERY_STRING'};
print "<html>\n<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
print "<title>$image</title>\n</head>\n";
print "<body>";

$last = "";
$next = "";
$gotit = 0;

opendir(DIR,"big/");

foreach $n (sort readdir DIR) {
	if ($n=~/jpe?g$/ ||
	    $n=~/JPE?G$/ ||
	    $n=~/gif$/ ||
	    $n=~/GIF$/ ||
	    $n=~/png$/ ||
	    $n=~/PNG$/) {
		if ($gotit) {
			$next = $n;
			last;
		}

		if ($n eq "$image") {
			$gotit = 1;
			next;
		}	
		
		$last = $n;
	}
}

closedir DIR;

print "<A HREF=\"index.cgi\">[Contents]</A>\n\n";

if ($last ne "") {
	print "<A HREF=\"view.cgi?$last\">[Previous]</A>\n\n";
}

if ($next ne "") {
	print "<A HREF=\"view.cgi?$next\">[Next]</A>\n\n";
}

print "<P><IMG SRC=\"big/$image\">\n\n";

if ( -e "$image.desc" &&
     open(FILE,"$image.desc")) {
	print "<P>";
	while (<FILE>) {
		print "$_\n";
	}
	
	close (FILE);
}

print "</BODY></HTML>\n";


