#!/bin/sh

echo > "$1"
#echo '<table cellpadding="0" cellspacing="0" border="0" align="left" bgcolor="#ffffff">' >> "$1"
echo '<table cellpadding="0" cellspacing="10" border="0" align="left">' >> "$1"

ver=`find . -type d -name '?.?-??' | sed -e 's/-.*//' -e 's/.*\(.\..\)/\1/' | sort -ru`
for i in $ver; do
    if [ "$i" = "2.x" ]; then
        echo '<tr><td colspan=2>' "<h3>Version $i (gtk1)</h3>" '</tr></td>' >> "$1"
    else
        echo '<tr><td colspan=2>' "<h3>Version $i</h3>" '</tr></td>' >> "$1"
    fi
    #echo "$i: " $i*
    br="x"
    for dir in $i*; do
        shot=shots/`ls -1 $dir/shot.*`
        thumb=shots/`ls -1 $dir/thumb.*`
        text=$dir/text.html
        #echo -e "$shot\n$thumb\n$text"
        if [ "$br" = "x" ]; then
            echo "<tr valign=\"top\">" >> "$1"
        fi
        echo  "<td width=\"33%\"> <a href=\"$shot\"> \
           <img src=\"$thumb\" style=\"border: 1px solid ;\"> </a> <br>\
          `cat $text 2>/dev/null` </td>" >> "$1"
        br="x$br"
        if [ "$br" = "xxxx" ]; then
              br="x"
              echo "</tr>" >> "$1"
        fi
    done
    echo '<tr><td colspan=2>' "<br>" '</tr></td>' >> "$1"
done


echo "</table>" >> "$1"
