diff --git a/web/folder_template.html b/web/folder_template.html
index 7cb6f94986e534f604881db457acad1cabcd3862..ffda0d3ecdf7b301e84c0d4f2bbe956874f2cb1e 100644
--- a/web/folder_template.html
+++ b/web/folder_template.html
@@ -5,8 +5,8 @@
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <title>Quack - ${SRC_FOLDER}</title>
     <link rel="stylesheet" type="text/css" href="${UP}quack.css" />
-    <script src="${UP}quack_folder.js"></script>
     <script src="${UP}sorttable.js"></script>
+    <script src="${UP}quack_folder.js"></script>
 </head>
 
 <body class="folder">
diff --git a/web/quack_folder.js b/web/quack_folder.js
index 0600e41cc9708dda6aca116e60c796c00e961fbe..f229733eacabd73ed6d733b62f20114affdab39c 100644
--- a/web/quack_folder.js
+++ b/web/quack_folder.js
@@ -10,7 +10,7 @@ function toggleBlownThumbs() {
         content[i].style.display = state;
     }
 }
-function toggleHistograms() {    
+function toggleHistograms() {  
     if (document.getElementById('toggle_histograms').checked) {
         thumb_state = 'none';
         hist_state = 'block';
@@ -29,7 +29,19 @@ function toggleHistograms() {
     }
 }
 
-function setupThumbOverlays() {
+function thclick() {
+    // Consider a timeout if there is a race condition with the table sort
+    // TODO: Order the image divs like the table links are ordered
+}
+
+var oldOnload = window.onload;
+function initialSetup() {
+    if (oldOnload != null) {
+        console.log('Calling previous onLoad');
+        oldOnload();
+    }
+    // Thumb overlays
+    console.log('Adding thumb overlays');
     var content = document.getElementsByClassName('thumblink');
     for (var i = 0 ; i < content.length ; i++) {
         var href = content[i].href;
@@ -42,5 +54,16 @@ function setupThumbOverlays() {
         span.style.background = "url(" + base + ".black.thumb.png) 100% 100%, url(" + base + ".white.thumb.png) 100% 100%";
         document.title = span.style.background;
     }
+
+    console.log('Attaching hooks for table sort');
+    var tables = document.getElementsByClassName('sortable');
+    for (var i = 0 ; i < tables.length ; i++) {
+        var stable = tables[i];
+        var theads = stable.getElementsByTagName('th');
+        for (var h = 0 ; h < theads.length ; h++) {
+            thead = theads[h];
+            thead.onclick = thclick;
+        }
+    }
 }
-window.onload=setupThumbOverlays;
+window.onload = initialSetup;