#!/usr/local/bin/perl

use CGI qw(header param start_html end_html);
use CGI qw/:standard :html3 :netscape/;
use POSIX;


$n = param('n');
open(LIST, '<images/list.txt');
@list = <LIST>;
close(LIST);

open(INCL, '<bodyincludes.html');
@incl = <INCL>;
close(INCL);

print header;

print q|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Baltic Way 2005: Photo Gallery</title>
<link rel="stylesheet" type="text/css" href="bwstyle.css">
<style type="text/css">
div.menu li.phot a {color: rgb(200,40,0);}
a.photo {color: white;}
a.photo img {margin: 10px;}
</style>
</head>
<body>
<div class="page">|;

print join('', @incl);
print q|<div class="main">
<h1>Photo Gallery</h1>|;

if(($n > 0)&&($n <= $#list + 1)){
@line = split(/\|/, $list[$n-1]);
print q|<table align="center"><tr><td align="left" width="180">|;
print &prev_pict($n);
print q|</td><td align="center" width="180"><a href="photos.cgi?n=0">Back to gallery</a></td><td align="right" width="180">|;
print &next_pict($n);
print q|</td></tr></table><p align="center">|;
print q|<img width="| . $line[1] . q|" alt="Photo" src="images/| . $line[0] . q|.jpg">|;
print q|<br>| . $line[2] . q|</p>|;
}
else {
print q|<p>Here are some photos from Baltic Way 2005. If you want to contribute, send your photos to 
hansr<img width="11" height="12" border="0" alt="at" src="/epost/snabela.gif">&#109;&#97;&#116;&#104;&#46;&#115;&#117;&#46;&#115;&#101;.</p>|;
for($j = 1; $j <= $#list + 1; $j++){
print &photo($j);
}
}

print q|</div></div></body></html>|;

sub photo{
@line = split(/\|/, $list[$_[0] - 1]);
return q|<a class="photo" href="photos.cgi?n=| . $_[0] . q|"><img alt="Photo" src="images/| . $line[0] . q|s.jpg"></a>|;
}

sub next_pict{
$i = $_[0] + 1;
if($_[0] <= $#list){
return q|<a href="photos.cgi?n=| . "$i" . q|">Next &gt;</a>|;
}
else {
return q|&nbsp;|;
}
}

sub prev_pict{
$i = $_[0] - 1;
if($_[0] > 1){
return q|<a href="photos.cgi?n=| . "$i" . q|">&lt; Previous</a>|;
}
else {
return q|&nbsp;|;
}
}
