<?php

// this works with a direcotry full of images where...
// - all images are the same size (duh)
// - 'numImages' evenly divides into 'imageWidth'
// - images are numbered starting at 1
// for best results in QTVR mode, photograph the subject as it spins counter-clockwise
// or something you're walking around clockwise (to your left) as you're shooting

$sliceWidthRaw=($imageWidth/$numImages);
$sliceWidthParts=explode(".",$sliceWidthRaw);
$sliceWidth=$sliceWidthParts[0]; // I'm sure some rounding function would work better.
// this rounds down a bit--a 160px-wide image cut into 8 pieces ends at 155
// the better thing would be to ship the raw values and trim them when it's rectangle-drawing time
// OTOH, the flaw is tiny enough that no one will notice.
// Opera doesn't like image maps with decimals.
$step=($sliceWidth-1);

// A couple notes on my coding style...

// Q: Why do I use " instead of '?
//
// A: because I'd rather say "img src='whatever'"
// than "img src=\"whatever\""
// Plus things like '\n' don't work inside of single quotes.
// It's valid HTML 4 transitional
// not sure about HTML 4 strict, and it's
// definitely not valid XHTML.

// Q: why do I (usually) say 
// print "blah blah ".$whatever." etc etc etc"
// instead of
// print "blah blah $whatever etc etc etc"
// ?
//
// A: so it shows up in my syntax highlighter
// Also, it makes it easier to replace a $var
// with a mysql_result($whatever,0,0)

// Q: why do I say
// $a='1'
// instead of 
// $a=1
// ?
//
// A: so it shows up in my syntax highlighter

// All code composed with BBEdit & TextWrangler on Mac OS X.
// Saved with UNIX linebreaks.

// world's cheapest preloader
// cheesy, but hey... it works better than other JS preloaders I've seen.
// anyone who doesn't like it, feel free to use another.
for ($i=1;$i<=$numImages;$i++) {
    print 
"<span style='position: absolute; left: 2px; top: 2px; z-index: 5;'>";
    print 
"<img src='".$baseDir."/".$imageDir."/".$thumbDir."/".$i.".".$imageType."' width='1' height='1' border='0' alt=''>";
    print 
"</span>\n";
}

print 
"<table border='1' cellpadding='5' cellspacing='0'>\n";
print 
"<tr>\n";
print 
"<td valign='top' align='center'>\n";

print 
"<img src='".$baseDir."/".$imageDir."/".$thumbDir."/1.".$imageType."' width='".$imageWidth."' height='".$imageHeight."' usemap='#".$imageDir."' border='0' name='".$imageDir."' alt=''>\n";
print 
"<map name='".$imageDir."'>\n";

for (
$i=1;$i<=$numImages;$i++) {
    
$left=($i*$sliceWidth-$sliceWidth);
    
$right=($left+$step);
    
// I know the rest of this code is all like ``img src='whatever'`` but I don't know
    // how to do the next line except with proper double-quotes (")
    // I suppose I should do the rest of the page with escaped double-quotes (\")
    // but I hate those. Makes the code too messy. (See above.)
    // Thank god for HTML 4.01 Transitional--this validates! http://validator.w3.org/
    // took out onClick=\"return false\" to make it so that clicking takes you to that image
    
print "<area shape=\"rect\" COORDS=\"$left,0,$right,$imageHeight\" href=\"$baseDir/$imageDir/$i.$imageType\" onmouseover=\"$imageDir.src='$baseDir/$imageDir/$thumbDir/$i.$imageType';\" alt=\"\">\n";
}
print 
"</map>\n";

print 
"</td>\n";
print 
"</tr>\n";
print 
"<tr>\n";
print 
"<td valign='top' align='center'>\n";
print 
$imageDir;
print 
"</td>\n";
print 
"</tr>\n";
print 
"</table>\n";

?>

</body>
</html>