#!/bin/sh

MINPAGE=4
MAXPAGE=253

data0='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>Things Seen in Japan (pages '
data1=')</title>
<link rel="start" href="index.html" />'
data2='</head>

<body>
<div style="text-align: center;"><table style="margin-left: auto; margin-right: auto;" border="0" cellspacing="3" cellpadding="0"><tr>'
datalast='</tr></table></div>
</body>
</html>'

page=$MINPAGE
while test $page -le $MAXPAGE; do
    for size in s m l; do
	(
	    echo -n "$data0"
	    echo -n "$page-$[page+1]"
	    echo "$data1"
	    if test $page -gt $MINPAGE; then
		printf '<link rel="prev" href="%03d-%03d%s.html" />\n' $[page-2] $[page-1] $size
		printf '<link rel="prev" href="%03d.jpg" />\n' $[page-2]
		printf '<link rel="prev" href="%03d.jpg" />\n' $[page-1]
	    fi
	    if test $[page+1] -lt $MAXPAGE; then
		printf '<link rel="next" href="%03d-%03d%s.html" />\n' $[page+2] $[page+3] $size
		printf '<link rel="next" href="%03d.jpg" />\n' $[page+2]
		printf '<link rel="next" href="%03d.jpg" />\n' $[page+3]
	    fi
	    if test $size != s; then
		printf '<link rel="alternate" href="%03d-%03ds.html" />\n' $page $[page+1]
	    fi
	    if test $size != m; then
		printf '<link rel="alternate" href="%03d-%03dm.html" />\n' $page $[page+1]
	    fi
	    if test $size != l; then
		printf '<link rel="alternate" href="%03d-%03dl.html" />\n' $page $[page+1]
	    fi
	    echo "$data2"
	    if test $page = $MINPAGE; then
		echo "<td><tt>&nbsp;&nbsp;</tt></td>"
	    else
		printf '<td><a href="%03d-%03d%s.html"><tt>&lt;-</tt></a></td>' $[page-2] $[page-1] $size
	    fi
	    if test $size = s; then
		width=350
		height=550
	    elif test $size = l; then
		width=700
		height=1100
	    else
		width=525
		height=825
	    fi
	    printf '<td><img src="%03d.jpg" width="%d" height="%d">' $page $width $height
	    printf '<td><img src="%03d.jpg" width="%d" height="%d">' $[page+1] $width $height
	    if test $[page+1] -ge $MAXPAGE; then
		echo "<td><tt>&nbsp;&nbsp;</tt></td>"
	    else
		printf '<td><a href="%03d-%03d%s.html"><tt>-&gt;</tt></a></td>' $[page+2] $[page+3] $size
	    fi
	    echo "</table>"
	    echo -n "<p>"
	    if test $page -le $MINPAGE; then
		echo -n "<s>Back</s>"
	    else
		printf '<a href="%03d-%03d%s.html">Back</a>' $[page-2] $[page-1] $size
	    fi
	    echo -n ' | <a href="index.html">Cover</a> | '
	    if test $[page+1] -ge $MAXPAGE; then
		echo "<s>Next</s>"
	    else
		printf '<a href="%03d-%03d%s.html">Next</a>\n' $[page+2] $[page+3] $size
	    fi
	    echo -n "<br>Image size: "
	    if test $size != s; then printf '<a href="%03d-%03ds.html">' $page $[page+1]; fi
	    echo -n "Small (100dpi)"
	    if test $size != s; then echo -n '</a>'; fi
	    echo -n " | "
	    if test $size != m; then printf '<a href="%03d-%03dm.html">' $page $[page+1]; fi
	    echo -n "Medium (150dpi)"
	    if test $size != m; then echo -n '</a>'; fi
	    echo -n " | "
	    if test $size != l; then printf '<a href="%03d-%03dl.html">' $page $[page+1]; fi
	    echo -n "Large (200dpi)"
	    if test $size != l; then echo -n '</a>'; fi
	    echo "</p>"
	    echo "$datalast"
	) > `printf %03d-%03d%s.html $page $[page+1] $size`
    done
    page=$[page+2]
done
