#!/usr/local/bin/perl

use strict;

use CGI qw( :standard );

use vars qw ( $pic %captions );

my $basepath 	= "/home/salim/www/pix/transit";
my $urlpath	= "./";
my $prefix	= "DSCF";
my $ext		= ".JPG";	

my $default_caption = "No Photo Information Available";

my $q = new CGI;

#
# main
#

buildCaptions();

print $q->header(),
	$q->start_html(	-title => 'transit photos',
			-author => 'Me, consarnit',
			), "\n",
	"\n";

if (defined($q->param('p'))) {
	$pic = $q->param('p');
	showPic($q, $pic);
}
else {
	print $q->h3("Photographs of Bay Area transit");
	makeMenu();
}
exit(0);

#
# subrs
#
sub showPic {

	my $q = shift;
	my $pic = shift;

	my $img = $prefix . $pic . $ext;
	my $caption = $captions{$pic} || $default_caption;
	
	#
	# File under: I am such a moron.
	#
	my ($p, $nextpic, $prevpic);
	($p = $pic) =~ s/^0{2,3}//;
	$nextpic = ++$pic; 
	$prevpic = --$p;
	
	# special cases
	# really should be a recursive fn call
	# duh. moron.
	if ($pic =~ 13 || $pic =~ 48) {
                ++$nextpic;
        }
	if ($pic =~ 15 || $pic =~ 50) {
		--$prevpic;
	}

	$prevpic = "00" . $prevpic;
	if (length($prevpic) == 3) {
		$prevpic = "0" . $prevpic;
	}

	my ($next, $prev);
	if (defined($captions{$nextpic})) {
		$next = qq(<A HREF="./?p=$nextpic">Next &gt; &gt; </A>);
	} else {
		$next = qq();
	}
	if (defined($captions{$prevpic})) {
		$prev = qq(<A HREF="./?p=$prevpic">&lt; &lt; Previous</A>);
	} else {
		#prev = qq();
	}

	print qq(<DIV ALIGN="CENTER">);
	print $q->h3($caption);
	print qq(<TABLE BORDER=0 CELLSPACING=3 CELLPADDING=5>
		<TR><TD COLSPAN=3><IMG SRC="$img" ALT="$caption" BORDER=0></TD></TR>);
	print qq(<TR><TD>$prev</TD><TD><B>$caption</B></TD><TD>$next</TD></TR>);
	print qq(</TABLE>);
	print qq(<A HREF="/pix/transit/accessibility/">Return to the table of contents</A>);
	print qq(</DIV>);
	

} # showPic

sub makeMenu {
	print "<TABLE BORDER=0 CELLSPACING=3 CELLPADDING=5>";
	foreach my $pic (sort keys %captions) {
		#my $url = $prefix . $pic . $ext;
		#my $url = "./index.cgi?p=$pic";
		my $url = "./?p=$pic";
		print qq(<TR>
			<TD><A HREF="$url">$captions{$pic}</A></TD>
			</TR>);
	}
} # makeMenu

sub buildCaptions {

	while (<DATA>) {
		my ($pic, $caption) = split('\t');
		$captions{$pic} = $caption;
	}	
} # buildCaptions
#
# end
#

#
# data
# id	caption
__END__
0001	Duboce Park MUNI Station. Handicapped Ramp (Outbound).
0002	Duboce Park MUNI Station. Handicapped Ramp (Inbound).
0003	Intersection of Duboce and Church, westerly view. Mint Building is in the background.
0004	Intersection of Duboce and Church. Duboce Bikeway.
0005	Duboce Bikeway.
0006	New MUNI construction, Duboce Bikeway. Handicapped Ramp (Outbound).
0007	New MUNI construction, Duboce Bikeway. Handicapped Ramp (Inbound).
0008	New MUNI construction, Duboce Bikeway. Handicapped Ramp (Outbound).
0009	New MUNI construction, Duboce Bikeway. Handicapped Ramp (Outbound).
0010	Intersection of Duboce and Church, easterly view.
0011	MUNI Accessible Services Program Notice Board, June 9th (train service).
0012	MUNI Accessible Services Program Notice Board, June 9th (Elevator service).
0013	New MUNI construction, Duboce Bikeway. Handicapped Ramp (Inbound).
0015	Bicycle path markers on the Duboce Bikeway, at Market Street.
0016	BART Plaza, NE corner 16th St x Mission (16th Street Station).
0017	BART Plaza, SW corner 16th St x Mission (16th Street Station).
0018	BART Elevator, 16th Street Station, Street Level. (tight)
0019	BART Elevator, 16th Street Station, Street Level. (wide)
0020	BART Elevator, 16th Street Station, Street Level. (buttons)
0021	BART Elevator, 16th Street Station. Notice describing elevator overhaul project.
0022	BART Elevator, 16th Street Station. Interior controls.
0023	BART Elevator, 16th Street Station. Interior sign describing current elevator service problems.
0024	BART Elevator, 16th Street Station. Interior controls.
0025	BART Elevator, 16th Street Station. Station Level. Yes, it really does exit into a concrete box.
0026	BART Elevator, 16th Street Station. Station Level. (wide)
0027	BART Elevator, 16th Street Station. Station Level. (buttons) 
0028	BART Elevator, 16th Street Station. Station Level. (tight)
0029	BART Elevator, West Oakland Station. Station Level. The man waited for five minutes for the elevator to arrive.
0030	BART Station, West Oakland. TDD sign (in rafters). (tight)
0031	BART Station, West Oakland. TDD sign (in rafters). (wide)
0032	BART Station, West Oakland (panorama 1). You can see that, for the entire length of the platform, there are no emergency telephones.
0033	BART Station, West Oakland (panorama 2).
0034	BART Station, West Oakland (panorama 3).
0035	BART Station, West Oakland (panorama 4).
0036	BART Station, West Oakland (panorama 5).
0037	BART train carriage, interior.
0038	BART train carriage, interior.
0039	AC Transit diesel bus, boarding entrance.
0040	AC Transit diesel bus, front.
0041	AC Transit diesel bus, side.
0042	MUNI Elevator, Embarcadero Station. Station Level.
0043	MUNI Elevator, Embarcadero Station. Station Level.
0044	MUNI Station, Embarcadero. Emergency call phone?
0045	MUNI Station, Embarcadero. Emergency call phone?
0046	MUNI Station, Embarcadero. Emergency call phone.
0047	MUNI Station, Embarcadero. Emergency call phone.
0049	MUNI Station, Embarcadero. System map, Braille.
0050	MUNI Station, Embarcadero. System map, Braille.
0051	MUNI Station, Embarcadero. System service changes notice.
0052	MUNI train carriage, interior.
0053	MUNI train carriage, interior.
0054	MUNI train carriage, exterior.

