Index: misc/tableheader.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tableheader.js,v
retrieving revision 1.28
diff -u -9 -p -r1.28 tableheader.js
--- misc/tableheader.js	27 Oct 2009 04:12:39 -0000	1.28
+++ misc/tableheader.js	27 Oct 2009 18:22:19 -0000
@@ -35,19 +35,19 @@ Drupal.behaviors.tableHeader = {
       tracker(headerClone);
       // We hid the header to avoid it showing up erroneously on page load;
       // we need to unhide it now so that it will show up when expected.
       $(headerClone).children('thead').show();
 
       $(table).addClass('sticky-table');
     });
 
     // Define the anchor holding var.
-    var prevAnchor = '';
+    var prevAnchor = location.hash;
 
     // Track positioning and visibility.
     function tracker(e) {
       // Reset top position of sticky table headers to the current top offset.
       var topOffset = Drupal.settings.tableHeaderOffset ? eval(Drupal.settings.tableHeaderOffset + '()') : 0;
       $('.sticky-header').css('top', topOffset + 'px');
       // Save positioning data.
       var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
       if (e.viewHeight != viewHeight) {
@@ -72,37 +72,39 @@ Drupal.behaviors.tableHeader = {
       var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
       var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition;
       var visState = (vOffset > 0 && vOffset < e.vLength) ? 'visible' : 'hidden';
       $(e).css({ left: -hScroll + e.hPosition + 'px', visibility: visState });
 
       // Check the previous anchor to see if we need to scroll to make room for the header.
       // Get the height of the header table and scroll up that amount.
       if (prevAnchor != location.hash) {
         if (location.hash != '') {
-          var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
-          $('body, html').scrollTop(scrollLocation);
+           $(location.hash, e.table).each(function() {
+            var scrollLocation = $(this).offset().top - $(e).height() - topOffset;
+            $('body, html').scrollTop(scrollLocation);
+          });
         }
-        prevAnchor = location.hash;
       }
     }
 
     // Only attach to scrollbars once, even if Drupal.attachBehaviors is called
     //  multiple times.
     $('body').once(function () {
       $(window).scroll(Drupal.tableHeaderDoScroll);
       $(document.documentElement).scroll(Drupal.tableHeaderDoScroll);
     });
 
     // Track scrolling.
     Drupal.tableHeaderOnScroll = function () {
       $(headers).each(function () {
         tracker(this);
       });
+      prevAnchor = location.hash;
     };
 
     // Track resizing.
     var time = null;
     var resize = function () {
       // Ensure minimum time between adjustments.
       if (time) {
         return;
       }
