DONEFILES=0
THEDIR=$1

if [ x$THEDIR != x ]
then

echo Using $THEDIR...
cd $THEDIR

#rm -rf .thumbs index.html .small
if [ ! -d .thumbs ]; then mkdir .thumbs; fi
if [ ! -d .small ]; then mkdir .small; fi

echo "<html><head><title>Index for directory $THEDIR</title><LINK rel="stylesheet" href="/~daniel/homepagecss.php"> </head>" > index.html
if [ -e .background.jpg ]; then
	echo "<body background=.background.jpg>" >> index.html
else
	echo "<body>" >> index.html
fi


echo "<h1>Index for directory $THEDIR</h1>" >> index.html
if [ -e comments.html ]; then cat comments.html >> index.html; fi
if [ -e contents.html ]; then cat contents.html >> index.html; fi
echo "<p>" >> index.html
echo "<table width=100%>" >> index.html
COUNT=0
for i in `ls *.jpg *.JPG`
do
	COUNT=`expr $COUNT + 1`
	if [ ! -e .thumbs/$i -o $i -nt .thumbs/$i ]
	then
		echo -n "Making thumbnail "
		djpeg $i | pnmscale -ysize 64 | cjpeg -quality 60 > .thumbs/$i
	fi
	if [ ! -e .small/$i -o $i -nt .small/$i ]
	then
		echo -n "and smaller pic "
		djpeg $i | pnmscale 0.5 | cjpeg -quality 75 > .small/$i
	fi
	if [ `expr $COUNT % 4 ` = 1 ]
	then
		echo "<tr>" >> index.html
	fi
	echo "<td width=25%><center><small><a href=.small/$i><img src=.thumbs/$i><br>Small</a> - <a href=$i>Large</a></small>" >> index.html
	COMMENTFILE=`echo $i | cut -f 1 -d.`.txt
	if [ -e $COMMENTFILE ]
	then
		echo "<br>" >> index.html
		cat $COMMENTFILE >> index.html
	fi
	echo "</center></td>" >> index.html
	DONEFILES=1
done

echo "</table>" >> index.html
echo "</body></html>" >> index.html

echo "<a href=$THEDIR>$THEDIR</a><br>" >> ../index.html
fi

DIRLIST=`ls -d */`
if [ x"$DIRLIST" != x ]
then
#if [ x$DONEFILES = x0 ]
#then
	#rm index.html
#fi
for i in $DIRLIST
do
	echo "Entering $i..."
	~daniel/public_html/hols/mkholdir.sh $i
done
fi
