#!/usr/bin/perl -w

use strict;

my $columns = 4;
my $title = "Dave's Crazy FLCL Avatar Gallery!";

my $validformats = "jpg|jpeg|gif|png";

print "Content-type: text/html\n\n";
print qq#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
	<title>$title</title>
</head>
<body>
<table border="1px" cellpadding="20px" cellspacing="5px">
#;

opendir(IMAGES, ".") or die;
my $filenum = 0;
print qq#<tr align="center">\n#;
for my $file (sort grep { $_ =~ /(?:$validformats)$/ } readdir(IMAGES)) {
	$filenum++;
	if ((($filenum - 1) % $columns == 0) & $filenum > 1) {
		print qq#</tr>\n<tr align="center">\n#;
	}
	print qq#	<td><img src="$file" alt="Image$filenum" /><br />$file</td>\n#;
}

print qq#</tr>
</table>
<p><a href="http://validator.w3.org/check/referer">Check XHTML</a></p>
</body>
</html>#;
