diff -urpN Scaricati/fbssc/fbssc.ahah.js /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.ahah.js
--- Scaricati/fbssc/fbssc.ahah.js	1970-01-01 01:00:00.000000000 +0100
+++ /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.ahah.js	2010-10-27 21:58:39.937621214 +0200
@@ -0,0 +1,68 @@
+// $Id$
+(function($) {
+
+if (Drupal.jsEnabled) {
+  $(document).ready(function() {
+    // Wait for facebook_status to load
+    var override = setInterval(function () {
+      if (Drupal.behaviors.facebookStatus != undefined) {
+        clearInterval(override);
+        // Override facebook_status AHAH success function so that 
+        // settings are updated prior to calling Drupal.attachBehaviors()
+        Drupal.fbssc.override = {
+          ahahSuccess : Drupal.ahah.prototype.success
+        };
+        
+        Drupal.ahah.prototype.success = function (response, status) {
+          if(status) {
+            // Merge in new and changed settings, if any.
+            if (response.settings) {
+              $.extend(true, Drupal.settings, response.settings);
+            } 
+                        
+            // Call the overriden AHAH success event in this context
+            Drupal.fbssc.override.ahahSuccess.apply(this, arguments);
+          }
+        };
+        
+        // If something in AHAH success event will use ajax to reload 
+        // the page, Drupal.settings and behaviors must be updated
+        $().ajaxComplete(function(event, request, settings){
+          var url = settings.url.substr(0, settings.url.lastIndexOf('?'));
+
+          if(url.indexOf(window.location.pathname) >= 0) {
+            var response = request.responseText.replace(/[\n\r\t]/g, "");
+            var head = response.match(/<head>(.*)<\/head>/);
+            var scripts = head[0].match(/<script(?![^>]*src=)[^>]*>.*?<\/script>/igm);
+            for (i=0; scripts != null && i < scripts.length; i++) {
+              var script = $(scripts[i]).html();
+              // Drupal settings are updated in a CDATA structure, just
+              // remove enclosing tags
+              if(script.indexOf("<![CDATA[//>") > 0) {
+                script = script.replace("<!--//--><![CDATA[//><!--", "");
+                script = script.replace("//--><!]]>", "");
+                $.globalEval(script);
+              }
+            }
+
+            // Attach behaviors defined by new settings
+            var loaded = {};
+            var refreshIDs = Drupal.settings.facebook_status.refreshIDs;
+            $.each(refreshIDs, function(i, val) {
+              if (val && val != undefined) {
+                if ($.trim(val) != '' && loaded[val] !== true) {
+                  var element = $(val);
+                  Drupal.attachBehaviors(element);
+                }
+                loaded[val] = true;
+              }
+            });
+          }
+        });
+        
+      }
+    }, 100);
+  });
+}
+
+})(jQuery);
\ No newline at end of file
diff -urpN Scaricati/fbssc/fbssc.css /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.css
--- Scaricati/fbssc/fbssc.css	2010-03-19 04:09:52.000000000 +0100
+++ /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.css	2010-10-25 18:22:46.224116008 +0200
@@ -4,14 +4,18 @@
   padding: 0.75em;
 }
 
+.fbssc_form {
+  display: none;
+}
+
 .fbssc_comment {
   border-bottom: 1px solid #E0E0E0;
   margin: 0.5em 0;
   padding: 0.5em 0.25em 0.75em;
+  text-align: left;
 }
 
 .fbssc .first {
-  margin: 0 0 0.5em;
   padding: 0.25em 0.25em 0.75em;
 }
 
@@ -73,6 +77,7 @@
   display: block;
   font-size: 90%;
   padding-bottom: 0.5em;
+  text-align: left;
 }
 
 /* The "Show all comments" link when it expands instead of redirecting. */
diff -urpN Scaricati/fbssc/fbssc.js /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.js
--- Scaricati/fbssc/fbssc.js	2010-03-19 03:52:25.000000000 +0100
+++ /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.js	2010-10-27 13:53:54.033173313 +0200
@@ -1,18 +1,93 @@
 // $Id$
-Drupal.behaviors.fbssc = function (context) {
-  $('.fbssc_show_comment_form').one('click', function() {
+
+// Initialize fbssc object 
+Drupal.fbssc = {};
+
+/**
+ * On click event to show comment form
+ * @param element 
+ *   The button
+ * @return
+ */
+Drupal.fbssc.labelClickEvent = function (element) {
+  var commentForm = $('div#'+ element.id).parent().find('.fbssc_form');
+  $('.fbssc_form').each(function() {
     $(this).hide();
-    $('#'+ this.id +' + div').show();
+  });
+  commentForm.show();
+};
+
+/**
+ * Invoked when modalframe closes to refresh comment form
+ * @param response
+ *   The modalframe response
+ */
+Drupal.fbssc.refreshCommentForm = function (response) {
+	
+	if(typeof(response.args) == "undefined") {
+		return;
+	}
+	
+  var sid = response.args.sid;
+  var refreshId = '#' + $('#fbssc_replace_' + sid +' input.form-submit').attr('id');
+  var buildId = $(refreshId).parents('form').find('input[name=form_build_id]').val();
+  var token = $(refreshId).parents('form').find('input[name=form_token]').val();
+  // Fake a comment submission to retrieve updated form state
+  $.ajax({
+    type: 'POST',
+    url: Drupal.settings.basePath + 'fbssc/js/refresh',
+    data: { 'form_build_id': buildId, 'form_token' : token, 'form_id' : 'fbssc_box', 'op' : '' },
+    success: function(response, status) {
+     if(status) {
+       // Attach updated comments and behaviors
+       response = Drupal.parseJson(response);
+       var new_content = $('<div></div>').html(response.data);
+       $('#fbssc_replace_' + sid).html(new_content);
+       Drupal.attachBehaviors(new_content);
+     }
+    }
+  });
+};
+
+Drupal.behaviors.fbssc = function (context) {
+	// Show/Hide comment form links
+	$('.fbssc_show_comment_form').click( function() {
+		Drupal.fbssc.labelClickEvent(this);
     return false;
   });
-  $('.fbssc_show_comment_form_inner').one('click', function() {
-    $(this).hide();
-    $('#'+ this.id +' + div').show();
+  $('.fbssc_show_comment_form_inner').click( function() {
+  	Drupal.fbssc.labelClickEvent(this);
     return false;
   });
-  $('a.fbssc_show_comments').one('click', function() {
-    $(this).hide();
-    $('#'+ this.id +' ~ div.fbssc_hide').show();
+  $('a.fbssc_show_comments').click( function() {
+    if(typeof ($(this).attr('oldText')) != "undefined" &&
+       $(this).attr('oldText') != '') {
+      $(this).html($(this).attr('oldText'));
+      $(this).attr('oldText', '');
+    } else {
+      $(this).attr('oldText', $(this).html());
+      $(this).html(Drupal.t('Hide'));
+    }
+    $('#'+ this.id +' ~ div.fbssc_hide').toggle();
+    return false;
+  });
+  // Modal frame integration for comment edit and delete links
+  $('.fbssc .fbssc_edit_delete a:not(.modalframe-fbssc-processed)').addClass('modalframe-fbssc-processed').click(function() {
+    var element = this;
+
+    // Build modal frame options.
+    var modalOptions = {
+      url: $(element).attr('href'),
+      autoFit: true,
+      onSubmit: Drupal.fbssc.refreshCommentForm,
+      width: 700,
+      height: 250
+    };
+
+    // Open the modal frame dialog.
+    Drupal.modalFrame.open(modalOptions);
+
+    // Prevent default action of the link click event.
     return false;
   });
-}
\ No newline at end of file
+};
\ No newline at end of file
diff -urpN Scaricati/fbssc/fbssc.module /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.module
--- Scaricati/fbssc/fbssc.module	2010-06-05 17:49:30.000000000 +0200
+++ /var/www/html/drupal6test/sites/all/modules/fbssc/fbssc.module	2010-10-27 22:01:08.176619328 +0200
@@ -12,7 +12,6 @@
  *       + userpoints
  *       + devel generate
  *       + appbar
- *       + popups api
  *       + sms framework
  *       + views bulk operations
  *   - Document API and add README.txt.
@@ -144,7 +143,8 @@ function theme_fbssc_item($comment, $cla
   array_unshift($classes, 'fbssc_comment');
   $classes = implode(' ', $classes);
   $output = '<div class="'. $classes .'">';
-  $output .= '<div class="fbssc_author">'. theme('username', user_load(array('uid' => $comment->uid))) .'</div>';
+  $owner = user_load(array('uid' => $comment->uid));
+  $output .= '<div class="fbssc_author"><span>'. theme('user_picture', $owner).theme('username', $owner) .'</span></div>';
   $comment_text = _facebook_status_run_filter($comment->comment);
   $comment_text = nl2br($comment_text);
   $output .= '<div class="fbssc_text">'. $comment_text .'</div>';
@@ -167,6 +167,7 @@ function theme_fbssc_item($comment, $cla
       l(t('Delete'), 'statuses/comment/'. $comment->cid .'/delete', array('query' => array('destination' => $q)))
       .'</span>';
   }
+  $output .= '<div class="clear-block"></div>';
   $output .= '</div></div>';
   //Invokes hook_fbssc_render_alter(&$output, $comment).
   drupal_alter('fbssc_render', $output, $comment);
@@ -200,7 +201,7 @@ function theme_fbssc_items($comments, $d
   drupal_add_js($path .'/fbssc.js');
   $output = '<div class="fbssc">';
   if ($count > 3 && $delay_load) {
-    $options = array('attributes' => array('class' => 'fbssc_show_comments_link fbssc_show_comments', 'id' => 'fbssc_toggle_'. $comments[0]->sid));
+    $options = array('attributes' => array('class' => 'fbssc_show_comments_link fbssc_show_comments', 'id' => 'fbssc_comment_toggle_'. $comments[0]->sid));
     if ($count > 9) {
       $options['attributes']['class'] = 'fbssc_show_comments_link';
     }
@@ -253,19 +254,30 @@ function theme_fbssc_items($comments, $d
  * @return
  *   Themed HTML for the status form.
  */
-function theme_fbssc_form_display($sid, $delay_load_form = TRUE, $delay_load_comments = TRUE) {
-  if (fbssc_can_post(facebook_status_load($sid))) {
-    $path = drupal_get_path('module', 'fbssc');
-    drupal_add_js($path .'/fbssc.js');
-    $output = '';
-    if ($delay_load_form && !fbssc_count_comments($sid)) {
-      $output = '<div class="fbssc_show_comment_form" id="fbssc_toggle_'. $sid .'">'.
-        l(t('Comment'), 'statuses/'. $sid, array('attributes' => array('class' => 'fbssc_show_comment_form_link')))
-        .'</div>';
-        return $output .'<div class="fbssc_hide fbssc_form">'. drupal_get_form('fbssc_box', $sid, $delay_load_comments) .'</div>';
-    }
-    return '<div class="fbssc_form">'. drupal_get_form('fbssc_box', $sid, $delay_load_comments) .'</div>';
+function theme_fbssc_form_display($sid, $delay_load_form = TRUE, $delay_load_comments = TRUE, $form = NULL) {
+  global $user;
+  static $output = array();
+
+  // Do not render comments on AHAH status submit, because passed in $sid
+  // always refer to the latest status even when theme() is called for the
+  // other statuses. Actually, render will be correctly handled on page
+  // update triggered by AHAH success event, so at this time it is not
+  // necessary in any case
+  if(arg(0) == 'facebook_status' && arg(1) == 'js') {
+    return;
   }
+
+  // Cache is needed to avoid multiple form generation in a single page request
+  if (empty($output[$sid]) || $form != NULL) {
+		if (fbssc_can_post(facebook_status_load($sid)) || user_access('view all status comments', $user)) {
+	    if($form) {
+	    	$output[$sid] .= drupal_render($form);
+	    } else {
+	      $output[$sid] .= drupal_get_form('fbssc_box', $sid, $delay_load_comments);
+	    }
+	  }
+  }
+  return $output[$sid];
 }
 
 //==============
@@ -478,6 +490,25 @@ function _fbssc_get_thread_author($sid) 
   return db_result(db_query("SELECT uid FROM {facebook_status} WHERE sid = %d", $sid));
 }
 
+/**
+ * Append a submit handler to every submission element of a form
+ *
+ * @param $submit
+ *   The name of the submit handler function
+ * @param $form
+ *   A Form API array form or, recursively, any of its subelements
+ */
+function _append_submit( $submit, &$form ) {
+  foreach ($form as $field => $element) {
+    if ($field != '#submit' && $field != '#validate' && is_array($element)) {
+      $form[$field] = _append_submit($submit, &$element);
+    } else if ($field == '#submit')  {
+    	$form['#submit'][] = $submit;
+    }
+  }
+  return $form;
+}
+
 //===============
 //FORM FUNCTIONS.
 //===============
@@ -498,6 +529,14 @@ function _fbssc_get_thread_author($sid) 
 function fbssc_box($form_state, $sid, $delay_load = TRUE) {
   $path = drupal_get_path('module', 'fbssc');
   drupal_add_css($path .'/fbssc.css');
+  drupal_add_js($path .'/fbssc.js');
+  drupal_add_js($path .'/fbssc.ahah.js');
+
+  if(module_exists('modalframe')) {
+    // Send the Modal Frame javascript for child windows to the page.
+    modalframe_parent_js();
+  }
+
   $form = array();
   if (!isset($form_state['fbssc']['q'])) {
     $form['#qu'] = $_GET['q'];
@@ -506,32 +545,45 @@ function fbssc_box($form_state, $sid, $d
     $form['#qu'] = $form_state['fbssc']['q'];
   }
   $comments = fbssc_get_comments($sid);
-  $form['before'] = array('#value' => '<div id="fbssc_replace_'. $sid .'">');
-  $form['comments'] = array('#value' => theme('fbssc_items', $comments, $delay_load, $form['#qu']));
-  if (count($comments)) {
-    $form['start-hide'] = array('#value' => '<div class="fbssc_show_comment_form_inner" id="fbssc_inner_toggle_'. $sid .'">'.
-      l(t('Comment'), 'statuses/'. $sid, array('attributes' => array('class' => 'fbssc_show_comment_inner_form_link')))
-      .'</div><div class="fbssc_hide fbssc_replace_inner_'. $sid .'">');
-  }
-  $form['status-comment'] = array(
-    '#type' => 'textarea',
-    '#rows' => 1,
-    '#required' => TRUE,
-  );
-  $form['save'] = array(
-    '#type' => 'submit',
-    '#value' => t('Comment'),
-    '#ahah' => array(
-      'path' => 'fbssc/js/refresh',
-      'wrapper' => 'fbssc_replace_'. $sid,
-      'effect' => 'fade',
-      'method' => 'replace',
-    ),
+  $form['replace-start'] = array(
+    '#value' => '<div id="fbssc_replace_'. $sid .'" class="fbssc_replace">'
   );
-  if (count($comments)) {
-    $form['end-hide'] = array('#value' => '</div>');
+  if (user_access('post status comment', $GLOBALS['user'])) {
+  	$form['comments'] = array(
+	    '#value' => theme('fbssc_items', $comments, $delay_load, $form['#qu']),
+	  );
+	  $form['start-hide'] = array(
+      '#value' => '<div class="fbssc_show_comment_form" id="fbssc_toggle_'. $sid .'">'.
+        l(t('Add new comment'), 'statuses/'. $sid, array('attributes' => array('class' => 'fbssc_show_comment_form_link')))
+        .'</div>'
+    );
+  	$form['status-comment'] = array(
+	    '#type' => 'textarea',
+	    '#rows' => 1,
+	    '#prefix' => '<div class="fbssc_form">'
+	  );
+	  $form['save'] = array(
+	    '#id' => 'save-'.$sid,
+	    '#type' => 'submit',
+	    '#value' => t('Comment'),
+	    '#ahah' => array(
+	      'path' => 'fbssc/js/refresh',
+	      'wrapper' => 'fbssc_replace_'.$sid,
+	      'effect' => 'fade',
+	      'method' => 'replace',
+	    ),
+	    '#suffix' => '</div>'
+	  );
+  } else {
+  	// Only show comment list
+  	$form['comments'] = array(
+      '#value' => theme('fbssc_items', $comments, $delay_load, $form['#qu']),
+    );
   }
-  $form['after'] = array('#value' => '</div>');
+  $form['replace-end'] = array(
+    '#value' => '</div>'
+  );
+
   $form['#sid'] = $sid;
   if ($form_state['fbssc']['sid']) {
     $form['#sid'] = $form_state['fbssc']['sid'];
@@ -545,7 +597,9 @@ function fbssc_box($form_state, $sid, $d
 function fbssc_box_submit($form, &$form_state) {
   $form_state['fbssc']['q'] = $form['#qu'];
   $form_state['fbssc']['sid'] = $form['#sid'];
-  fbssc_save_comment($form['#sid'], $form_state['values']['status-comment']);
+  if(!empty($form_state['values']['status-comment'])) {
+    fbssc_save_comment($form['#sid'], $form_state['values']['status-comment']);
+  }
   $form_state['rebuild'] = TRUE;
 }
 
@@ -566,18 +620,65 @@ function fbssc_save_js() {
       'Someone tried to access the JavaScript processing page for Facebook-style Statuses Comments directly.', array(), WATCHDOG_DEBUG);
     return;
   }
+
+  $sid = $form['#sid'];
+  $comments = fbssc_get_comments($sid);
+
   $form_id = array_shift($args);
   drupal_process_form($form_id, $form, $form_state);
   $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
-  //Get HTML for the replacement form. Only these elements will be AHAH-refreshed.
+  // Get HTML for the replacement form. Only these elements will be AHAH-refreshed.
   $new_form['comments']       = $form['comments'];
+  $new_form['start-hide']     = $form['start-hide'];
   $new_form['status-comment'] = $form['status-comment'];
   $new_form['save']           = $form['save'];
-  $output = theme('status_messages') . drupal_render($new_form);
-  //Return the results.
+
+  $output = theme('status_messages');
+
+  $output .= theme('fbssc_form_display', $sid, TRUE, TRUE, $new_form);
+  // Return the results.
   drupal_json(array('status' => TRUE, 'data' => $output));
 }
 
+/**
+ * Implementation of hook_form alter().
+ */
+function fbssc_form_alter(&$form, $form_state, $form_id) {
+  $modalframe = module_exists('modalframe');
+	switch ($form_id) {
+    case 'fbssc_edit' :
+    case 'fbssc_delete' :
+      if($modalframe) {
+        // Send the Modal Frame javascript for child windows to the page.
+        modalframe_child_js();
+        // Append modalframe submit handler to every form submission element
+        _append_submit('fbssc_modalframe_submit', $form);
+      }
+      break;
+    case 'facebook_status_box' :
+      break;
+  }
+}
+
+/**
+ * Submit handler for comment update and deletion in a modal frame
+ */
+function fbssc_modalframe_submit($form, &$form_state) {
+	 switch ($form_state['values']['form_id']) {
+    case 'fbssc_edit' :
+    case 'fbssc_delete' :
+			// Tell the parent window to close the modal frame dialog
+			if ($form_state['values']['op'] != t('Cancel')) {
+		    modalframe_close_dialog(array(
+		      'args' => array('sid' => $form['#parameters'][2]->sid),
+		    ));
+		  } else {
+		  	 modalframe_close_dialog();
+		  }
+		  break;
+	 }
+}
+
 //=============
 //INTEGRATIONS.
 //=============
@@ -596,7 +697,7 @@ function fbssc_facebook_status_render_co
   return array(
     'comments' => array(
       'type' => (arg(0) == 'statuses' && is_numeric(arg(1)) && !arg(2)) ? 'markup' : 'value',
-      'value' => theme('fbssc_form_display', $status->sid, FALSE, FALSE),
+      'value' => theme('fbssc_form_display', $status->sid, TRUE, TRUE),
       'weight' => 50,
     ),
   );
