#!/usr/local/bin/python

if __name__ == "__main__":
	
	import glob
	import os.path

	thumb_dir = "thumb/"
	pics_dir  = "pics/"
	html      = ""
	picture_files = []

	html_title = "Anime Expo 2002 Photo Preview"
	cols = 4

	# The the filenames of the JPG files
	dir_files = glob.glob(pics_dir + "*")
	for pathname in dir_files:
		picture_files.append(os.path.basename(pathname))

	# Start HTML
	html = """<html>
<head>
<title>%(html_title)s</title>
</head>

<body bgcolor="#ffffff">
<h3 align="center">%(html_title)s</h3>
<table border="1" cellspacing="0" cellpadding="5" align="center">
""" % vars()

	html += "<tr>\n"
	col_count = 0
	picture_files.sort()
	for picture in picture_files:

		html += "\t<td>"
		html += '<a href="' + pics_dir + picture + '">' + \
			'<img src="' + thumb_dir + picture + '" border="0">'
		html += "</td>\n"

		if col_count >= cols - 1:
			html += "</tr>\n<tr>\n"
			col_count = 0
		else:
			col_count += 1

	html += "</tr>"

	# End HTML
	html += """
</table>
</body>
</html>
"""
	print "Content-Type: text/html\nContent-Length:", len(html) + 1, "\n"
	print html

	
