#!/usr/bin/perl

require "/usr/local/httpd/cgi-bin/cgi-lib.pl";
use Image::Size 'html_imgsize';
use Image::Size 'imgsize';

$TOPIMGDIR = "/usr/local/httpd/htmldocs/virtual/marshfield/slideshows";

&ReadParse;
$dir = $in{"dir"};

$IMGDIR = "$TOPIMGDIR/$dir";
$TXTFILE = "$IMGDIR/description.txt";
$FOOTER = "$IMGDIR/footer.txt";

$description = "Slideshow";
if(-f $TXTFILE) {
	open TXTFILE;
	$description = <TXTFILE>;
	$date = <TXTFILE>;
}
if(-f $FOOTER) {
	open FOOTER;
	$footer = <FOOTER>;
}

print "dir: $IMGDIR\n";

&checkdir;

print qq~Content-type: text/html\n\n~;

print qq (

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>$description</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../slideshows/styles.css">
<link type="text/css" rel="stylesheet" href="../floatbox/floatbox.css">
<script type="text/javascript" src="../floatbox/floatbox.js"></script>
<style type="text/css">

</style>
</head>
<body>

);

if(-f $TXTFILE) {
print qq(

<div class="content rounded dark">
<p class="description">$description</p>
<p class="datex">$date</p>
</div>

);
}

print qq(

<div class="content rounded dark">
<table cellpadding="5" cellspacing="0" border="0">
<tr>

);

$counter = 0;
foreach $file (@allfiles) {
	if(index($file,"jpg") < 0) {
		next;
	}
	$image = "$IMGDIR/$file";
	($width, $height) = imgsize($image);
	print qq~<td><a href="../slideshows/$dir/enlarged/$file" class="floatbox" rev="group:used;caption2:`$description`"><img src="../slideshows/$dir/$file" width="$width" height="$height" border="0" class="rounded"></a></td>~;
	print "\n";
	if(++$counter > 4) {
		print "</tr>\n<tr>\n";
	$counter = 0;
	}
}


print qq(
</tr></table>
</div>
);

if (-f $FOOTER) {

print qq(
<div class="content rounded dark">
<p class="footer">$footer</p>
</div>
);

}

print qq(
</body>
</html>
);

sub checkdir {
	opendir THISDIR, $IMGDIR or die "Problem opening $DATADIR: $!";
	@allfiles =readdir THISDIR;
	closedir THISDIR;
	@allfiles = sort(@allfiles);
}
