Index: smf/SSI.php
===================================================================
--- smf/SSI.php	(revision 1031)
+++ smf/SSI.php	(working copy)
@@ -244,6 +244,21 @@
 	echo '<a href="', $scripturl, '?action=logout;sesc=', $sc, '">', $txt[108], '</a>';
 }
 
+function ssi_displayPaging($count_comm, $begin_comm, $max_comm, $display)
+{
+    if($count_comm > $max_comm) {
+        echo '<b>Mergi la pagina:</b> ';
+        for ($i = 1; $i <= $count_comm; $i += $max_comm) {
+            if ($i != $begin_comm) {
+                echo '<a href="javascript:stay()" onclick="RemoteBox_Comments('. $i .', '. $max_comm .', true, \''. $display .'\');">
+                    ['. (int)(($i + $max_comm - 1) / $max_comm) . ']</a> ';
+            } else {
+                echo '<b>[' . (int)(($i + $max_comm - 1)/ $max_comm) . ']</b> ';
+            }
+        }
+    }
+}
+
 // Display an entire SMF topic as a comment thread.
 function ssi_commentThread($topicID, $display, $begin_comm, $max_comm = 10, $output_method = 'echo')
 {
@@ -325,8 +340,9 @@
     echo '
         <div class="comments">';
 
+    $remotebox_display = ($display == 'show' ? 'hide' : 'show');
     echo '
-        <a href="javascript:stay()" onclick="RemoteBox_Display = (RemoteBox_Display == \'show\' ? \'hide\' : \'show\'); RemoteBox_Load();"><h3>&#187; ';
+        <a href="javascript:stay()" onclick="RemoteBox_Comments('. $begin_comm .', '. $max_comm .', false, \''. $remotebox_display .'\');"><h3>&#187; ';
 
     if (0 == $count_comm){
         echo 'Niciun comentariu inca...';
@@ -342,17 +358,8 @@
 
     if($display == 'show') {
 
-        // Pagination
-        if($count_comm > $max_comm) {
-            echo '<b>Mergi la pagina:</b> ';
-            for ($i = 1; $i <= $count_comm; $i += $max_comm) {
-                if ($i != $begin_comm) {
-                    echo '<a href="javascript:stay()" onclick="RemoteBox_BeginComm=' . $i . ';RemoteBox_Load();">[' . (int)(($i + $max_comm - 1) / $max_comm) . ']</a> ';
-                } else {
-                    echo '<b>[' . (int)(($i + $max_comm - 1)/ $max_comm) . ']</b> ';
-                }
-            }
-        }
+        // Front paging display
+        ssi_displayPaging($count_comm, $begin_comm, $max_comm, $display);
 
         foreach ($posts as $post)
             echo '
@@ -368,6 +375,10 @@
                         ', $post['preview'], '
                     </div>
                 </div>';
+
+        // Back paging display
+        echo '<br>';
+        ssi_displayPaging($count_comm, $begin_comm, $max_comm, $display);
     }
 
     $new_post_url = $scripturl.'?action=post;topic='.$topicID;
Index: smf/ia_comments.php
===================================================================
--- smf/ia_comments.php	(revision 1031)
+++ smf/ia_comments.php	(working copy)
@@ -6,7 +6,7 @@
 
 $topic_id = getattr($_GET, 'topic_id');
 $display = getattr($_GET, 'display', 'hide');
-$begin_comm = (int)getattr($_GET, 'begin_comm', '0');
+$begin_comm = (int)getattr($_GET, 'begin_comm', '1');
 $max_comm = getattr($_GET, 'max_comm');
 
 if (!$topic_id) {
Index: www/macros/macro_remotebox.php
===================================================================
--- www/macros/macro_remotebox.php	(revision 1031)
+++ www/macros/macro_remotebox.php	(working copy)
@@ -8,9 +8,7 @@
 //
 // NOTE: This macro requires special user permissions since it poses quite
 // a few security concerns.
-function macro_remotebox($args, $bypass_security = false) {
-    $url = getattr($args, 'url');
-
+function macro_remotebox($url, $bypass_security = false) {
     if (!$bypass_security && !identity_can('macro-remotebox')) {
         return macro_permission_error();
     }
@@ -22,13 +20,7 @@
     $buffer = '';
     $buffer .= '<div id="remotebox">remote content</div>';
     $buffer .= '<script type="text/javascript">RemoteBox_Url="';
-    $buffer .= html_escape($args['url']);
-    if (array_key_exists('display', $args)) {
-        $buffer .= '";RemoteBox_Display="' . html_escape($args['display']);
-    }
-    if (array_key_exists('max_comm', $args)) {
-        $buffer .= '";RemoteBox_MaxComm="' . html_escape((int)$args['max_comm']);
-    }
+    $buffer .= html_escape($url);
     $buffer .= '";</script>';
 
     return $buffer;
Index: www/macros/macro_smfcomments.php
===================================================================
--- www/macros/macro_smfcomments.php	(revision 1031)
+++ www/macros/macro_smfcomments.php	(working copy)
@@ -14,6 +14,8 @@
 //      SmfComments( topic_id="400" display="show" )
 //      SmfComments( topic_id="400" display="hide" max_comm="5")
 function macro_smfcomments($args) {
+    $comments = '<div id="comentarii">';
+
     $topic_id = getattr($args, 'topic_id');
     $display = getattr($args, 'display');
     $max_comm = getattr($args, 'max_comm');
@@ -30,19 +32,21 @@
         return macro_error('Wrong value for argument `display`');
     }
 
-    $args = array(
-        'url' => IA_SMF_URL.'/ia_comments.php?topic_id='.$topic_id,
-        'display' => $display
-    );
     if(!is_null($max_comm)) {
-        if(is_whole_number($max_comm)) {
-            $args['max_comm'] = $max_comm;
-        } else {
+        if(!is_whole_number($max_comm)) {
             return macro_error('Wrong value for argument `max_comm`');
         }
     }
 
-    return macro_remotebox($args, true);
+    $url = IA_SMF_URL . '/ia_comments.php?topic_id=' . $topic_id . '&display=' . $display;
+    if (!is_null($max_comm)) {
+        $url .= '&max_comm=' . $max_comm;
+    }
+
+    $comments .= macro_remotebox($url, true);
+    $comments .= '</div>';
+
+    return $comments;
 }
 
 ?>
Index: www/macros/macro_smftopic.php
===================================================================
--- www/macros/macro_smftopic.php	(revision 1031)
+++ www/macros/macro_smftopic.php	(working copy)
@@ -22,10 +22,9 @@
         return macro_error('Invalid `count` argument');
     }
 
-    $args = array(
-        'url' => IA_SMF_URL.'/ia_recentposts.php?topic_id='.$topic_id.'&count='.$count
-    );
-    return macro_remotebox($args, true);
+    $url = IA_SMF_URL.'/ia_recentposts.php?topic_id='.$topic_id.'&count='.$count;
+
+    return macro_remotebox($url, true);
 }
 
 ?>
Index: www/macros/macro_smftopics.php
===================================================================
--- www/macros/macro_smftopics.php	(revision 1031)
+++ www/macros/macro_smftopics.php	(working copy)
@@ -24,10 +24,9 @@
         return macro_error('Invalid `count` argument');
     }
 
-    $args = array(
-        'url' => IA_SMF_URL.'/ia_recenttopics.php?board_id='.$board_id.'&count='.$count
-    );
-    return macro_remotebox($args, true);
+    $url = IA_SMF_URL.'/ia_recenttopics.php?board_id='.$board_id.'&count='.$count;
+    
+    return macro_remotebox($url, true);
 }
 
 ?>
Index: www/static/js/remotebox.js
===================================================================
--- www/static/js/remotebox.js	(revision 1031)
+++ www/static/js/remotebox.js	(working copy)
@@ -4,11 +4,8 @@
  */
 
 var RemoteBox_Url = '';
-var RemoteBox_Display = 'hide';
-var RemoteBox_BeginComm = 1;
-var RemoteBox_MaxComm = 10;
 
-function RemoteBox_Load() {
+function RemoteBox_Load(remotebox_function) {
     var container = $('remotebox');
     if (!container || !RemoteBox_Url) {
         // no remotebox in this page
@@ -18,9 +15,7 @@
     // visual clue to indicate that remotebox is loading
     container.innerHTML = '<div class="loading"> <img src="/static/images/indicator.gif" />Se incarca ...</div>';
 
-    var d = doSimpleXMLHttpRequest(RemoteBox_Url + "&display=" + RemoteBox_Display +
-            "&begin_comm=" + RemoteBox_BeginComm +
-            "&max_comm=" + RemoteBox_MaxComm);
+    var d = doSimpleXMLHttpRequest(RemoteBox_Url);
 
     var ready = function(data) {
         if (data) {
@@ -33,7 +28,27 @@
     }
 
     d.addCallbacks(ready, error);
+    d.addCallbacks(remotebox_function, null);
 }
 
+function RemoteBox_Comments(begin_comm, max_comm, focus_on_comments, display) {
+    var RemoteBox_Base_Url = RemoteBox_Url;
+
+    RemoteBox_Url = RemoteBox_Url + "&display=" + display +
+            "&begin_comm=" + begin_comm +
+            "&max_comm=" + max_comm;
+    if (focus_on_comments == true) {
+        var remotebox_function = function() {
+            // set the anchor to the "comentarii" element
+            window.location.hash = "comentarii";
+        }
+        RemoteBox_Load(remotebox_function);
+    } else {
+        RemoteBox_Load(null);
+    }
+
+    RemoteBox_Url = RemoteBox_Base_Url;
+}
+
 connect(window, 'onload', RemoteBox_Load);
 
Index: www/views/blog_view.php
===================================================================
--- www/views/blog_view.php	(revision 1031)
+++ www/views/blog_view.php	(working copy)
@@ -34,12 +34,11 @@
 echo 'Creat la '.html_escape($first_textblock['creation_timestamp']).' de '.format_user_link($first_textblock["user_name"], $first_textblock["user_fullname"]);
 echo '</div>';
 // blog comments
-echo '<div id="comentarii">';
 if (getattr($view, 'forum_topic')) {
     echo macro_smfcomments(array('topic_id' => $view['forum_topic'], 'display' => 'show'));
 }
-echo '</div></div>';
 echo '</div>';
+echo '</div>';
 
 // site footer
 include('footer.php');
Index: www/views/textblock_view.php
===================================================================
--- www/views/textblock_view.php	(revision 1031)
+++ www/views/textblock_view.php	(working copy)
@@ -19,12 +19,10 @@
 echo '</div>';
 
 // page comments
-echo '<div id="comentarii">';
 if (getattr($view, 'forum_topic')) {
     require_once(IA_ROOT_DIR.'www/macros/macro_smfcomments.php');
     echo macro_smfcomments(array('topic_id' => $view['forum_topic'], 'display' => 'hide'));
 }
-echo '</div>';
 
 // site footer
 include('footer.php');
