}
    }
    for ($i = 0, $max = count($FILES); $i < $max; $i++) {
        $FILE = $FILES[$i];
        if (isset($time)) {
            if ($filter === 2) {
                if (filemtime("scans/thumb/{$FILE}") < $time) {
                    continue;
                }
            } else {
                if ($filter === 1) {
                    if (filemtime("scans/thumb/{$FILE}") > $time) {
                        continue;
                    }
                } else {
                    if ($filter === 3) {
                        if (!(filemtime("scans/thumb/{$FILE}") > $time[1] && filemtime("scans/thumb/{$FILE}") < $time[0])) {
                            continue;
                        }
                    }
                }
            }
        }
        $FILE = substr($FILE, 7, -3);
        $FILE = substr(exe("cd 'scans/file'; ls " . shell("Scan{$FILE}") . '*', true), 5, -1);
        //Should only have one file listed
        $IMAGE = $FILES[$i];
        echo '<div class="box" id="' . html($FILE) . '">' . '<h2 ondblclick="toggleFile(this);" class="excluded">' . html($FILE) . '</h2><p><span>' . genIconLinks(null, "Scan_{$FILE}", false) . '</span><br/>' . '<a class="tool" target="_blank" href="scans/file/Scan_' . url($FILE) . '" style="width:100%;"><img src="scans/thumb/' . url($IMAGE) . '" alt="' . html($FILE) . '" style="width:100%"/><span class="tip">View raw file</span></a>' . '</p></div>';
    }
    echo '</div><script type="text/javascript">' . 'if(typeof document.body.style.MozColumnGap=="string")' . 'getID("scans").className="columns";' . 'else ' . 'enableColumns("scans",null,' . (isset($_COOKIE["columns"]) ? 'true' : 'false') . ');</script>';
}
foreach ($set as $id => $opt) {
    echo '<a href="javascript:void(0);" onclick="config({';
    $str = '';
    foreach ($opt as $key => $val) {
        $key = html(js($key));
        $str .= "'{$key}':" . (is_numeric($val) ? $val : "'" . html(js($val)) . "'") . ",";
    }
    echo "{$str}'set_save':this[TC]});" . '">' . html($id) . '</a>';
    $i++;
    if ($i < $max) {
        echo " | ";
    }
}
?>
</p>
</div>
</form>

</div>

<!-- Preview Pane -->
<div id="preview" class="box-wide">
<div id="preview_links">
<h2>Preview Pane</h2>
<p><?php 
echo genIconLinks((object) array('download' => 0, 'zip' => 0, 'pdf' => 0, 'print' => 0, 'del' => 0, 'edit' => 0, 'view' => 0, 'upload' => 0, 'email' => 0), null, false);
?>
</p></div><!-- there are no line breaks on the next line to make the javascript ever so slightly faster -->
<div id="preview_img"><p><img src="res/images/blank.gif" title="Preview" alt="Preview"/><img alt="Scanning" src="res/images/blank.gif" title="Scanning" style="z-index:-1;"/></p></div>
</div>
<p class="center i"><input type="button" value="Update" onclick="setRegion(ias);"/> <input type="button" onclick="clearRegion(ias,true)" value="Clear"/><br/>
<small>Crop is applied before rotate</small></p>
</div>

<div class="side_box">
<h2>
Save Image
</h2>
<p class="center"><input type="submit" value="Save Changes" name="action"/> <input type="reset" value="Reset Options" onclick="clearRegion(ias,false)"/></p>
</div>
</form>
</div>

<!-- Preview Pane -->
<div id="preview" class="box-wide">
<div id="preview_links">
<h2><?php 
echo html($file);
?>
</h2>
<p>
<?php 
echo genIconLinks((object) array('edit' => 0), "Scan_{$file}", false);
?>
</p></div><!-- There are no line breaks on the next line to make the javascript ever so slightly faster -->
<div id="preview_img"><p><img alt="Preview" src="scans/thumb/Preview_<?php 
echo url(substr($file, 0, strrpos($file, '.')));
?>
.jpg" title="Preview"/><img style="z-index:-1;" src="res/images/blank.gif" title="Processing" alt=""/></p></div>
</div>
function Update_Links($l, $p)
{
    # Change the Preview Pane image links via JavaScript
    echo '<script type="text/javascript">' . 'getID("preview_links").innerHTML="<h2>' . html($l) . '</h2><p>' . js(genIconLinks($p == "Edit" ? (object) array('edit' => 'disable') : null, $l, false)) . '</p>";</script>';
}