--- Desktop/ajax_comments.js	2009-08-26 02:30:40.000000000 +0300
+++ /var/www/jamaluk/sites/all/modules/ajax_comments/ajax_comments.js	2010-03-09 14:23:22.000000000 +0200
@@ -11,91 +11,95 @@ var firsttime_init = true;
 Drupal.behaviors.ajax_comments = function(context) {
   $('#panels-comment-form').attr('id', 'comment-form');
   $('#comment-form:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').each(function() {
-    form = $(this);
-    // Prepare the form when the DOM is ready.
-    if ((Drupal.settings.rows_default == undefined) || (!Drupal.settings.rows_default)) {
+      form = $(this);
+      // Prepare the form when the DOM is ready.
+      if ((Drupal.settings.rows_default == undefined) || (!Drupal.settings.rows_default)) {
       Drupal.settings.rows_default = $('textarea', form).attr('rows');
-    }
-    $('textarea', form).attr('rows', Drupal.settings.rows_default);
-    if ((Drupal.settings.rows_in_reply == undefined) || (!Drupal.settings.rows_in_reply)) {
+      }
+      $('textarea', form).attr('rows', Drupal.settings.rows_default);
+      if ((Drupal.settings.rows_in_reply == undefined) || (!Drupal.settings.rows_in_reply)) {
       Drupal.settings.rows_in_reply = Drupal.settings.rows_default;
-    }
-    if (Drupal.settings.always_expand_main_form == undefined) {
-      Drupal.settings.always_expand_main_form = true;
-    }
-    if (Drupal.settings.blink_new == undefined) {
-      Drupal.settings.blink_new = true;
-    }
-
-    $('#edit-upload', form).bind('change', function(){
-      $('#ajax-comments-submit,#ajax-comments-preview', form).attr('disabled', 1);
-    });
-    
-    // It's not possible to use 'click' or 'submit' events for ahah sumits, so
-    // we should emulate it by up-down events. We need to check which elements
-    // are actually clicked pressed, to make everything work correct.
-    $('#ajax-comments-submit,#ajax-comments-preview', form).bind('mousedown keydown', function() { last_submit = $(this).attr('id'); });
-    $('#ajax-comments-submit,#ajax-comments-preview', form).bind('mouseup', function() {
-      if (last_submit == $(this).attr('id')) {
-        ajax_comments_show_progress(context);
-        ajax_comments_update_editors();
       }
-    });
-    $('#ajax-comments-submit,#ajax-comments-preview', form).bind('keyup', function(event) {
-      if (last_submit == $(this).attr('id') && event.keyCode == 13) {
-        ajax_comments_show_progress(context);
-        ajax_comments_update_editors();
+      if (Drupal.settings.always_expand_main_form == undefined) {
+      Drupal.settings.always_expand_main_form = true;
       }
-    });
-    
-    // Enable comments buttons back when attachement is uploaded.
-    $('#edit-attach', form).bind('mousedown keydown', function() {
-      if (last_submit == $(this).attr('id')) {
-        $('#ajax-comments-submit,#ajax-comments-preview', form).removeAttr('disabled');
+      if (Drupal.settings.blink_new == undefined) {
+      Drupal.settings.blink_new = true;
       }
-    });
 
-    // Initializing main form.
-    action = form.attr('action');
+      $('#edit-upload', form).bind('change', function(){
+        $('#ajax-comments-submit,#ajax-comments-preview', form).attr('disabled', 1);
+        });
 
-    // Creating title link.
-    form.parents(".box").find("h2:not(.ajax-comments-processed),h3:not(.ajax-comments-processed),h4:not(.ajax-comments-processed)").addClass('ajax-comments-processed').each(function(){
-      title = $(this).html();
-      $(this).html('<a href="'+action+'" id="comment-form-title">'+title+'</a>');
-      $(this).parents(".box").find(".content").attr('id','comment-form-content').removeClass("content");
-    });
+      // It's not possible to use 'click' or 'submit' events for ahah sumits, so
+      // we should emulate it by up-down events. We need to check which elements
+      // are actually clicked pressed, to make everything work correct.
+      $('#ajax-comments-submit,#ajax-comments-preview', form).bind('mousedown keydown', function() { last_submit = $(this).attr('id'); });
+      $('#ajax-comments-submit,#ajax-comments-preview', form).bind('mouseup', function() {
+          if (last_submit == $(this).attr('id')) {
+          ajax_comments_show_progress(context);
+          ajax_comments_update_editors();
+          }
+          });
+      $('#ajax-comments-submit,#ajax-comments-preview', form).bind('keyup', function(event) {
+          if (last_submit == $(this).attr('id') && event.keyCode == 13) {
+          ajax_comments_show_progress(context);
+          ajax_comments_update_editors();
+          }
+          });
 
-    // Expanding form if needed.
-    page_url = document.location.toString();
-    fragment = '';
-    if (page_url.match('#')) {
-      fragment = page_url.split('#')[1];
-    }
+      // Enable comments buttons back when attachement is uploaded.
+      $('#edit-attach', form).bind('mousedown keydown', function() {
+          if (last_submit == $(this).attr('id')) {
+          $('#ajax-comments-submit,#ajax-comments-preview', form).removeAttr('disabled');
+          }
+          });
 
-    if ((fragment == 'comment-form'  || Drupal.settings.always_expand_main_form) && firsttime_init) {
-      $('#comment-form-title', context).addClass('pressed');
-      $('#comment-form-content').attr('cid', 0);
-    }
-    else {
-      // Fast hide form.
-      $('#comment-form-content', context).hide();
-    }
-    
-    // Attaching event to title link.
-    $('#comment-form-title:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').click(ajax_comments_reply_click);
-    // Moving preview in a proper place.
-    $('#comment-form-content').parents('.box').before($('#comment-preview'));
-    if (!$('#comment-form-content').attr('cid')) {
-      $('#comment-form-content').attr('cid', -1);
-    }
-    
-    if(typeof(fix_control_size)!='undefined'){ fix_control_size(); }
+      // Initializing main form.
+      action = form.attr('action');
+
+      // Creating title link.
+      form.parents(".box").find("h2:not(.ajax-comments-processed),h3:not(.ajax-comments-processed),h4:not(.ajax-comments-processed)").addClass('ajax-comments-processed').each(function(){
+          title = $(this).html();
+          $(this).html('<a href="'+action+'" id="comment-form-title">'+title+'</a>');
+          $(this).parents(".box").find(".content").attr('id','comment-form-content').removeClass("content");
+          });
+
+      // Expanding form if needed.
+      page_url = document.location.toString();
+      fragment = '';
+      if (page_url.match('#')) {
+        fragment = page_url.split('#')[1];
+      }
+
+      if ((fragment == 'comment-form'  || Drupal.settings.always_expand_main_form) && firsttime_init) {
+        $('#comment-form-title', context).addClass('pressed');
+        $('#comment-form-content').attr('cid', 0);
+      }
+      else {
+        // Fast hide form.
+        $('#comment-form-content', context).hide();
+      }
+
+      // Attaching event to title link.
+      //$('#comment-form-title:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').click(ajax_comments_reply_click);
+      $('#comment-form-title').hide();
+      var cloned = $('.box').clone().remove();
+      cloned.prependTo('#comments');
+      $('#comments-add-comment:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').click(ajax_comments_reply_click);
+      // Moving preview in a proper place.
+      $('#comment-form-content').parents('.box').before($('#comment-preview'));
+      if (!$('#comment-form-content').attr('cid')) {
+        $('#comment-form-content').attr('cid', -1);
+      }
+
+      if(typeof(fix_control_size)!='undefined'){ fix_control_size(); }
   });
-  
+
   $('.comment_reply a:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').click(ajax_comments_reply_click);
   $('.quote a:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').each(function(){
-    href = $(this).attr('href');
-    if (ajax_comments_is_reply_to_node(href)) {
+      href = $(this).attr('href');
+      if (ajax_comments_is_reply_to_node(href)) {
       $(this).click(function(){
         $('#comment-form').attr('action', $(this).attr('href'));
         ajax_comments_reload_form(0);
@@ -103,35 +107,35 @@ Drupal.behaviors.ajax_comments = functio
         $('#comment-form-title', context).click();
         ajax_comments_scroll_to_comment_form();
         return false;
-      });
-    }
-    else {
+        });
+      }
+      else {
       $(this).click(ajax_comments_reply_click);
-    }
-  });
-  
+      }
+      });
+
   // We should only bind ajax deletion on links with tokens to avoid CSRF attacks.
   $('.comment_delete a:not(.ajax-comments-processed)', context).each(function (){
-    href = $(this).attr('href');
-    if (href.indexOf('token=') > -1) {
+      href = $(this).attr('href');
+      if (href.indexOf('token=') > -1) {
       $(this).addClass('ajax-comments-processed').click(ajax_comments_delete_click);
-    }
-  });
+      }
+      });
 
   // Add Ctrl key listener for deletion feature.
   $(window).keydown(function(e) {
-    if(e.keyCode == 17) {
+      if(e.keyCode == 17) {
       ctrl = true;
-    }
-  });
+      }
+      });
   $(window).keyup(function(e) {
-    ctrl = false;
-     // Add sending on Ctrl+Enter.
-    if ((e.ctrlKey) && ((e.keyCode == 0xA) || (e.keyCode == 0xD)) && !submitted) {
+      ctrl = false;
+      // Add sending on Ctrl+Enter.
+      if ((e.ctrlKey) && ((e.keyCode == 0xA) || (e.keyCode == 0xD)) && !submitted) {
       submitted = true;
       $('#ajax-comments-submit').click()
-    }
- });
+      }
+      });
 
 
   firsttime_init = false;
@@ -178,11 +182,11 @@ function ajax_comments_reply_click() {
     if (!$(this).is('.last-clicked')) {
       // Reload form if preview is required.
       if ((Drupal.settings.comment_preview_required && $('#ajax-comments-submit').length) ||
-        // Or if quoted comment.
-        action.match('quote=1')
-      ) {
+          // Or if quoted comment.
+          action.match('quote=1')
+         ) {
         $('#comment-form').attr('action', action)
-        ajax_comments_reload_form(link_cid);
+          ajax_comments_reload_form(link_cid);
       }
       else {
         ajax_comments_init_form(link_cid, rows);
@@ -190,7 +194,7 @@ function ajax_comments_reply_click() {
     }
     // ...and show the form after everything is done.
     ajax_comments_expand_form();
-    
+
     $('.pressed').removeClass('pressed');
     $(this).addClass('pressed');
     $('.last-clicked').removeClass('last-clicked');
@@ -223,36 +227,36 @@ function ajax_comments_delete_click() {
     if (action) {
       $(this).parents(commentbox).fadeTo(speed, 0.5);
       $.ajax({
-        type: "GET",
-        url: action,
-        success: function(result){
-          if (result == 'OK') {
-            ajax_comments_close_form();
-
-            // If comment form is expanded on this module, we should collapse it first.
-            if (comment.next().is('#comment-form-content')) {
-              thread = comment.next().next('.indented, div > .indented');
-            }
-            else {
-              thread = comment.next('.indented, div > .indented');
-            }
-            thread.animate({height:'hide', opacity:'hide'}, speed);
-            comment.animate({height:'hide', opacity:'hide'}, speed, function(){
-              thread.remove();
-              comment.remove();
-              if (!$(commentbox).length) {
-                $('#comment-controls').animate({height:'hide', opacity:'hide'}, speed, function(){ $(this).remove(); });
-              }
-            });
-          }
-          else {
-            alert('Sorry, token error.');
-          }
-        }
-      });
-    }
+type: "GET",
+url: action,
+success: function(result){
+if (result == 'OK') {
+ajax_comments_close_form();
+
+// If comment form is expanded on this module, we should collapse it first.
+if (comment.next().is('#comment-form-content')) {
+thread = comment.next().next('.indented, div > .indented');
+}
+else {
+thread = comment.next('.indented, div > .indented');
+}
+thread.animate({height:'hide', opacity:'hide'}, speed);
+comment.animate({height:'hide', opacity:'hide'}, speed, function(){
+  thread.remove();
+  comment.remove();
+  if (!$(commentbox).length) {
+  $('#comment-controls').animate({height:'hide', opacity:'hide'}, speed, function(){ $(this).remove(); });
   }
-  return false;
+  });
+}
+else {
+  alert('Sorry, token error.');
+}
+}
+});
+}
+}
+return false;
 }
 
 // ======================================================================
@@ -264,11 +268,11 @@ function ajax_comments_delete_click() {
  */
 function ajax_comments_expand_form(focus) {
   $('#comment-form-content').animate({height:'show'}, speed, function() {
-    if (focus) {
+      if (focus) {
       $('#comment-form textarea').focus();
-    }
-    if ($.browser.msie) this.style.removeAttribute('filter'); 
-  });
+      }
+      if ($.browser.msie) this.style.removeAttribute('filter'); 
+      });
 }
 
 /**
@@ -286,8 +290,8 @@ function ajax_comments_init_form(pid, ro
   // Set proper PID.
   $('#comment-form input[name=pid]').val(pid)
 
-  // Now we can attach previously removed editors.
-  ajax_comments_attach_editors();
+    // Now we can attach previously removed editors.
+    ajax_comments_attach_editors();
   submit = false;
 }
 
@@ -297,10 +301,10 @@ function ajax_comments_init_form(pid, ro
 function ajax_comments_close_form(reload) {
   pid = $('#comment-form-content').attr('cid');
   $('#comment-form-content').animate({height:'hide'}, speed, function(){
-    if (reload) {
+      if (reload) {
       ajax_comments_reload_form(pid);
-    }
-  });
+      }
+      });
   $('.pressed').removeClass('pressed');
   $('#comment-form-content').attr('cid', -1);
   ajax_comments_hide_progress();
@@ -316,7 +320,7 @@ function ajax_comments_reload_form(pid) 
   if (pid > 0) {
     action = action.replace(/([?])$/, '/' + pid + '?');
     action = action.replace(/#comment-form/, '');
-    
+
     rows = Drupal.settings.rows_in_reply;
   }
   else {
@@ -326,22 +330,22 @@ function ajax_comments_reload_form(pid) 
   ajax_comments_show_progress();
 
   $.ajax({
-    type: "GET",
-    url: action,
-    success: function(result) {
-      saved_class = $('#comment-form').attr('class');
-      $('#comment-form-content').html(result);
-      $('#comment-form').attr('class', saved_class);
-
-      $('#comment-form').addClass('fresh');
-
-      Drupal.attachBehaviors($('#comment-form-content form'));
-      ajax_comments_init_form(pid, rows);
-      ajax_comments_hide_progress();
+type: "GET",
+url: action,
+success: function(result) {
+saved_class = $('#comment-form').attr('class');
+$('#comment-form-content').html(result);
+$('#comment-form').attr('class', saved_class);
+
+$('#comment-form').addClass('fresh');
+
+Drupal.attachBehaviors($('#comment-form-content form'));
+ajax_comments_init_form(pid, rows);
+ajax_comments_hide_progress();
 
-      $('#comment-form').removeClass('fresh');
-    }
-  });
+$('#comment-form').removeClass('fresh');
+}
+});
 }
 
 /**
@@ -390,36 +394,36 @@ jQuery.fn.ajaxCommentsSubmitToggle = fun
 
   html = obj.html();
   if (html.indexOf('comment-new-success') > -1) {
-    
+
     // Empty any preview before output comment.
     $('#comment-preview').slideUp(speed, function(){ $(this).empty(); });
-    
+
     // Place new comment in proper place.
     ajax_comments_insert_new_comment(obj);
 
     // At last - showing it up.
     obj.animate({height:'show', opacity:'show'}, speed, function () {
-      if ($.browser.msie) {
+        if ($.browser.msie) {
         height = document.documentElement.offsetHeight ;
-      } else if (window.innerWidth && window.innerHeight) {
+        } else if (window.innerWidth && window.innerHeight) {
         height = window.innerHeight;
-      }
-      height = height / 2;
-      offset = obj.offset();
-      if ((offset.top > $('html').scrollTop() + height) || (offset.top < $('html').scrollTop() - 20)) {
+        }
+        height = height / 2;
+        offset = obj.offset();
+        if ((offset.top > $('html').scrollTop() + height) || (offset.top < $('html').scrollTop() - 20)) {
         $('html').animate({scrollTop: offset.top - height}, 'slow', function(){
           // Blink a little bit to user, so he know where's his comment.
           if (Drupal.settings.blink_new) {
-            obj.fadeTo('fast', 0.2).fadeTo('fast', 1).fadeTo('fast', 0.5).fadeTo('fast', 1).fadeTo('fast', 0.7).fadeTo('fast', 1, function() { if ($.browser.msie) this.style.removeAttribute('filter'); });
+          obj.fadeTo('fast', 0.2).fadeTo('fast', 1).fadeTo('fast', 0.5).fadeTo('fast', 1).fadeTo('fast', 0.7).fadeTo('fast', 1, function() { if ($.browser.msie) this.style.removeAttribute('filter'); });
           }
-        });
-      }
-      else {
+          });
+        }
+        else {
         if (Drupal.settings.blink_new) {
-          obj.fadeTo('fast', 0.2).fadeTo('fast', 1).fadeTo('fast', 0.5).fadeTo('fast', 1).fadeTo('fast', 0.7).fadeTo('fast', 1, function() { if ($.browser.msie) this.style.removeAttribute('filter'); });
+        obj.fadeTo('fast', 0.2).fadeTo('fast', 1).fadeTo('fast', 0.5).fadeTo('fast', 1).fadeTo('fast', 0.7).fadeTo('fast', 1, function() { if ($.browser.msie) this.style.removeAttribute('filter'); });
         }
-      }
-      if ($.browser.msie) this.style.removeAttribute('filter');
+        }
+        if ($.browser.msie) this.style.removeAttribute('filter');
     });
 
     // Re-attaching behaviors to new comment.
@@ -456,12 +460,12 @@ function ajax_comments_remove_editors() 
   ajax_comments_update_editors();
   if (typeof(Drupal.wysiwyg) != undefined) {
     $('#comment-form input.wysiwyg-processed:checked').each(function() {
-      var params = Drupal.wysiwyg.getParams(this);
-      Drupal.wysiwygDetach($(this), params);
-    });
+        var params = Drupal.wysiwyg.getParams(this);
+        Drupal.wysiwygDetach($(this), params);
+        });
     return;
   }
-  
+
   if (typeof(tinyMCE) != 'undefined') {
     if (tinyMCE.getInstanceById("edit-comment")) {
       tinyMCE.execCommand('mceRemoveControl', false, "edit-comment");
@@ -475,9 +479,9 @@ function ajax_comments_remove_editors() 
 function ajax_comments_attach_editors() {
   if (typeof(Drupal.wysiwyg) != undefined) {
     $('#comment-form input.wysiwyg-processed:checked').each(function() {
-      var params = Drupal.wysiwyg.getParams(this);
-      Drupal.wysiwygAttach($(this), params);
-    });
+        var params = Drupal.wysiwyg.getParams(this);
+        Drupal.wysiwygAttach($(this), params);
+        });
     return;
   }
 
@@ -494,7 +498,7 @@ function ajax_comments_update_editors() 
   if (typeof(tinyMCE) != 'undefined') {
     tinyMCE.triggerSave();
   }
-  
+
   // Update FCKeditor.
   if (typeof(doFCKeditorSave) != 'undefined') {
     doFCKeditorSave();
