From fba50c3f7aaeb5fb19c7d51a799c1d4bdb238361 Mon Sep 17 00:00:00 2001
From: tms <tmslft@gmail.com>
Date: Sun, 3 Mar 2013 00:43:08 -0500
Subject: [PATCH] Position the selected post more reliably below the header

---
 app/assets/javascripts/discourse/views/topic_view.js | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic_view.js
index dd2f9ca85..25007f466 100644
--- a/app/assets/javascripts/discourse/views/topic_view.js
+++ b/app/assets/javascripts/discourse/views/topic_view.js
@@ -494,14 +494,22 @@ window.Discourse.TopicView.reopenClass({
   // Scroll to a given post, if in the DOM. Returns whether it was in the DOM or not.
   scrollTo: function(topicId, postNumber, callback) {
     // Make sure we're looking at the topic we want to scroll to
-    var existing;
+    var existing, header, title, expectedOffset;
     if (parseInt(topicId, 10) !== parseInt($('#topic').data('topic-id'), 10)) return false;
     existing = $("#post_" + postNumber);
     if (existing.length) {
       if (postNumber === 1) {
         $('html, body').scrollTop(0);
       } else {
-        $('html, body').scrollTop(existing.offset().top - 55);
+        header = $('header');
+        title = $('#topic-title');
+        expectedOffset = title.height() - header.find('.contents').height();
+        
+        if (expectedOffset < 0) {
+            expectedOffset = 0;
+        }
+        
+        $('html, body').scrollTop(existing.offset().top - (header.outerHeight(true) + expectedOffset));
       }
       return true;
     }