diff --git a/drupalchat.admin.inc b/drupalchat.admin.inc
index 6e84f87..0da485e 100755
--- a/drupalchat.admin.inc
+++ b/drupalchat.admin.inc
@@ -8,6 +8,7 @@
  * Callback for admin/settings/drupalchat.
  */
 function drupalchat_settings_form($form, &$form_state) {
+  $enable_file_attachment_option = FALSE;
   drupal_add_css('misc/farbtastic/farbtastic.css');
   drupal_add_js('misc/farbtastic/farbtastic.js');
   drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat.admin.js');
@@ -27,6 +28,13 @@ function drupalchat_settings_form($form, &$form_state) {
     drupal_set_message(t('For DrupalChat Long Polling to be effective, please set max_execution_time to above 30 in your server php.ini file.'), 'warning');
   }
 
+  if ((drupalchat_get_jquery_fileupload_path() &&
+    module_exists('jquery_update') &&
+    ((float)variable_get('jquery_update_jquery_version') > 1.6)) ||
+    variable_get('drupalchat_polling_method') == 3) {
+    $enable_file_attachment_option = TRUE;
+  }
+
   $form = array();
   /*$form['libraries'] = array(
     '#type' => 'fieldset',
@@ -199,9 +207,21 @@ function drupalchat_settings_form($form, &$form_state) {
   $form['drupalchat_pc']['drupalchat_enable_file_attachment'] = array(
     '#type' => 'select',
     '#title' => t('Enable File Attachment'),
-    '#description' => t('Select whether to allow user to share/upload file in chat.'),
+    '#description' => t('Select whether to allow user to share/upload file in chat. Download !plugin inside %libraries_path. Make sure %fileupload_js is available here %fileupload_js_full_path', array(
+      '!plugin' => '<a href="https://github.com/blueimp/jQuery-File-Upload/archive/9.11.2.zip">' . t('jQuery Fileupload') . '</a>',
+      '%libraries_path' => 'sites/all/libraries',
+      '%fileupload_js' => 'jquery.fileupload.js',
+      '%fileupload_js_full_path' => 'sites/all/libraries/jQuery-File-Upload/js/jquery.fileupload.js',
+    )),
     '#options' => array('1' => t('Yes'), '2' => t('No'),),
     '#default_value' => variable_get('drupalchat_enable_file_attachment', '1'),
+    '#disabled' => !$enable_file_attachment_option,
+  );
+  $form['drupalchat_pc']['drupalchat_allowed_file_extensions'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Allowed file extensions'),
+    '#description' => t('Allowed file extensions that can be sent as attachment.'),
+    '#default_value' => variable_get('drupalchat_allowed_file_extensions', 'jpg jpeg gif png'),
   );
   $form['drupalchat_pc']['drupalchat_allow_single_message_delete'] = array(
     '#type' => 'select',
diff --git a/drupalchat.install b/drupalchat.install
index 32361d3..19fdb26 100644
--- a/drupalchat.install
+++ b/drupalchat.install
@@ -74,6 +74,12 @@ function drupalchat_schema() {
         'not null' => TRUE,
         'unsigned' => TRUE,
       ),
+      'message_type' => array(
+        'description' => 'Message type',
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+      ),
     ),
     'indexes' => array(
       'uid1' => array('uid1'),
@@ -122,6 +128,25 @@ function drupalchat_schema() {
 	  'timestamp' => array('timestamp'),
     ),
   );
+  $schema['drupalchat_files'] = array(
+    'fields' => array(
+      'message_id' => array(
+        'type' => 'varchar',
+        'length' => 50,
+        'not null' => TRUE,
+        'description' => 'ID of chat message.',
+      ),
+      'fid' => array(
+        'description' => 'File ID.',
+        'type' => 'int',
+        'length' => 32,
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'fid' => array('fid'),
+    ),
+  );
 
   return $schema;
 }
@@ -168,3 +193,89 @@ function drupalchat_update_7001() {
       ));
   }
 }
+
+/**
+ * Add file attachment support to Drupalchat.
+ */
+function drupalchat_update_7100(&$sandbox = NULL) {
+  $success = FALSE;
+
+  try {
+    // Add new message type field.
+    if (!db_field_exists('drupalchat_msg', 'message_type')) {
+      db_add_field('drupalchat_msg', 'message_type', array(
+        'description' => 'Message type',
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+        'initial' => 'text',
+      ));
+    }
+
+    // Add new drupalchat_files table.
+    db_create_table('drupalchat_files', drupal_get_schema_unprocessed('drupalchat', 'drupalchat_files'));
+
+    $success = TRUE;
+  } catch (Exception $e) {}
+
+  if ($success) {
+    $message = t('Successfully added file attachement support');
+  }
+  else {
+    watchdog_exception('drupalchat', $e);
+    $message = t('Transaction failed');
+  }
+
+  return $message;
+}
+
+/**
+ * Add message type to all existing message entries.
+ */
+function drupalchat_update_7101(&$sandbox = NULL) {
+  $limit = 10;
+  $success = TRUE;
+
+  try {
+    if (!isset($sandbox['progress'])) {
+      $sandbox['progress'] = 0;
+      $sandbox['current_message_timestamp'] = 0;
+      $sandbox['max'] = db_select('drupalchat_msg', 'dm')
+        ->fields('dm')
+        ->countQuery()
+        ->execute()
+        ->fetchField();
+    }
+
+    $messages = db_select('drupalchat_msg', 'dm')
+      ->fields('dm')
+      ->condition('timestamp', $sandbox['current_message_timestamp'], '>')
+      ->range(0, $limit)
+      ->orderBy('timestamp', 'ASC')
+      ->execute();
+
+    foreach ($messages as $message) {
+      db_update('drupalchat_msg')
+        ->fields(array('message_type' => 'text'))
+        ->condition('timestamp', $message->timestamp)
+        ->execute();
+
+      $sandbox['progress']++;
+      $sandbox['current_message_timestamp'] = $message->timestamp;
+    }
+
+    $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+  } catch (Exception $e) {
+    $success = FALSE;
+  }
+
+  if ($success) {
+    $message = t('Successfully added type to all existing message entries');
+  }
+  else {
+    watchdog_exception('drupalchat', $e);
+    $message = t('Transaction failed');
+  }
+
+  return $message;
+}
diff --git a/drupalchat.module b/drupalchat.module
index f784c49..22fb33b 100755
--- a/drupalchat.module
+++ b/drupalchat.module
@@ -352,6 +352,11 @@ function drupalchat_menu() {
 		'access arguments' => array('access drupalchat'),
 		'type' => MENU_CALLBACK,
 	);
+  $items['drupalchat/sendfile'] = array(
+    'page callback' => 'drupalchat_sendfile',
+    'access arguments' => array('access drupalchat'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
@@ -647,12 +652,30 @@ function drupalchat_init() {
 	//drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/storage-lite.js');
     //drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/jquery.titlealert.min.js');
     if($polling_method != DRUPALCHAT_COMMERCIAL) {
-	  drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/jquery.titlealert.min.js');
-    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/ba-emotify.js');
-    drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/swfobject.js');
-	  drupal_add_css(drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/' . $theme . '.css');
-	  drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat-jstorage.js');
-	  drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat.js');
+      if (variable_get('drupalchat_enable_file_attachment') &&
+        module_exists('jquery_update') &&
+        (float)variable_get('jquery_update_jquery_version') > 1.6) {
+        drupal_add_js(drupalchat_get_jquery_fileupload_path() . '/js/vendor/jquery.ui.widget.js');
+        drupal_add_js(drupalchat_get_jquery_fileupload_path() . '/js/jquery.fileupload.js');
+        drupal_add_js(array(
+          'drupalchat' => array(
+            'enableFileAttachment' => TRUE,
+          )
+        ), 'setting');
+      }
+      else {
+        drupal_add_js(array(
+          'drupalchat' => array(
+            'enableFileAttachment' => FALSE,
+          )
+        ), 'setting');
+      }
+      drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/jquery.titlealert.min.js');
+      drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/ba-emotify.js');
+      drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/swfobject.js');
+      drupal_add_css(drupal_get_path('module', 'drupalchat') . '/themes/' . $theme . '/' . $theme . '.css');
+      drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat-jstorage.js');
+      drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat.js');
     }
 
  	if($polling_method == DRUPALCHAT_COMMERCIAL) {
@@ -729,7 +752,8 @@ function drupalchat_send() {
   		'uid1' => ($user->uid)?$user->uid:'0-'._drupalchat_get_sid(),
   		'uid2' => check_plain($_POST['drupalchat_uid2']),
   		'message' => $_POST['drupalchat_message'],
-  		'timestamp' => time(),
+      'timestamp' => time(),
+      'message_type' => 'text',
 	);
   drupal_write_record('drupalchat_msg', $message);
   foreach (module_implements('drupalchat_send') as $module) {
@@ -740,6 +764,50 @@ function drupalchat_send() {
 }
 
 /**
+ * Send attachments via ajax.
+ */
+function drupalchat_sendfile() {
+  global $user;
+  $directory =  'public://';
+  file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
+  $validators['file_validate_extensions'][0] = variable_get('drupalchat_allowed_file_extensions', 'jpg jpeg gif png');
+  $file = file_save_upload('drupalchat-file-attachment', $validators, $directory);
+
+  if ($file) {
+    file_usage_add($file, 'file', 'drupalChat', $user->uid);
+    $message_id = $_POST['drupalchat_message_id'] . '_' . REQUEST_TIME;
+
+    $message = (object) array(
+      'message_id' => $message_id,
+      'uid1' => ($user->uid) ? $user->uid : '0-' . _drupalchat_get_sid(),
+      'uid2' => check_plain($_POST['drupalchat_uid2']),
+      'message' => '',
+      'timestamp' => time(),
+      'message_type' => 'attachment',
+    );
+    $attachment = (object) array(
+      'message_id' => $message_id,
+      'fid' => $file->fid,
+    );
+
+    drupal_write_record('drupalchat_msg', $message);
+    drupal_write_record('drupalchat_files', $attachment);
+
+    drupal_json_output(array(
+      'response' => t('File successfully uploaded'),
+    ));
+
+    foreach (module_implements('drupalchat_send') as $module) {
+      $function = $module . '_drupalchat_send';
+      $function($message);
+    }
+  }
+  else {
+    drupal_json_output(drupal_get_messages());
+  }
+}
+
+/**
  * Alter status via ajax
  */
 function drupalchat_status() {
@@ -840,19 +908,20 @@ function drupalchat_poll() {
   }
   if (($message_count > 0) || ($polling_method == DRUPALCHAT_AJAX)) {
     if($user->uid > 0) {
-      $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp FROM {drupalchat_msg} m WHERE (m.uid2 IN (:uid2,\'c-0\') OR m.uid1 = :uid2) AND m.timestamp > :timestamp ORDER BY m.timestamp ASC', array(':uid2' => $user->uid, ':timestamp' => $last_timestamp));
+      $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp, m.message_type FROM {drupalchat_msg} m WHERE (m.uid2 IN (:uid2,\'c-0\') OR m.uid1 = :uid2) AND m.timestamp > :timestamp ORDER BY m.timestamp ASC', array(':uid2' => $user->uid, ':timestamp' => $last_timestamp));
     }
 	else {
-	  $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp FROM {drupalchat_msg} m WHERE (m.uid2 IN (:uid2,\'c-0\') OR m.uid1 = :uid2) AND m.timestamp > :timestamp ORDER BY m.timestamp ASC', array(':uid2' => '0-'._drupalchat_get_sid(), ':timestamp' => $last_timestamp));
+	  $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp, m.message_type FROM {drupalchat_msg} m WHERE (m.uid2 IN (:uid2,\'c-0\') OR m.uid1 = :uid2) AND m.timestamp > :timestamp ORDER BY m.timestamp ASC', array(':uid2' => '0-'._drupalchat_get_sid(), ':timestamp' => $last_timestamp));
 	}
     //while ($message = db_fetch_object($messages)) {
     // Drupal 7
     foreach ($messages as $message) {
-	  //$arr = explode("-", $message->uid1, 2);
+      $message_conversation = drupalchat_format_message_conversation($message);
+
 	  if(((!strpos($message->uid1,'-')) && ($message->uid1 != $user->uid)) || ((strpos($message->uid1,'-')) && ($message->uid1 != '0-'._drupalchat_get_sid()))) {
 	    if(!strpos($message->uid1,'-')) {
 	      $account = user_load($message->uid1);
-		  $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+		  $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
 		  if(variable_get('drupalchat_user_picture', 1) == 1) {
 			$temp_msg['p'] = drupalchat_return_pic_url_any_user($account);
 		  }
@@ -862,7 +931,7 @@ function drupalchat_poll() {
 	      $arr = explode("-", $message->uid1, 2);
 		  $sid = $arr[1];
 	      $name = db_query('SELECT name FROM {drupalchat_users} WHERE uid = :uid AND session = :sid', array(':uid' => '0', ':sid' => $sid))->fetchField();
-	      $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+	      $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
 		  if(variable_get('drupalchat_user_picture', 1) == 1) {
 			$temp_msg['p'] = drupalchat_return_pic_url_any_user(user_load('0'));
 		  }
@@ -872,7 +941,7 @@ function drupalchat_poll() {
 	  else {
 	    if(!strpos($message->uid2,'-')) {
 	      $account = user_load($message->uid2);
-		  $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+		  $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
 		  if(variable_get('drupalchat_user_picture', 1) == 1) {
 			$temp_msg['p'] = drupalchat_return_pic_url_any_user($account);
 		  }
@@ -882,7 +951,7 @@ function drupalchat_poll() {
 	      $arr = explode("-", $message->uid2, 2);
 		  $sid = $arr[1];
 	      $name = db_query('SELECT name FROM {drupalchat_users} WHERE uid = :uid AND session = :sid', array(':uid' => '0', ':sid' => $sid))->fetchField();
-	      $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+	      $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
 		  if(variable_get('drupalchat_user_picture', 1) == 1) {
 			$temp_msg['p'] = drupalchat_return_pic_url_any_user(user_load('0'));
 		  }
@@ -1362,12 +1431,12 @@ function drupalchat_return_pic_url($uid = null) {
     global $user;
 
 if(isset($uid)){
-$u =  user_load($uid);  
+$u =  user_load($uid);
 
 } else {
 $u = user_load($user->uid);
   }
-return drupalchat_return_pic_url_any_user($u);    
+return drupalchat_return_pic_url_any_user($u);
 }
 
 function drupalchat_return_pic_url_any_user($u) {
@@ -1560,18 +1629,20 @@ function drupalchat_get_thread_history() {
       }
 
       if($chat_id == 'c-0') {
-        $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp FROM {drupalchat_msg} m WHERE m.uid2 = \'c-0\' ORDER BY m.timestamp DESC LIMIT 30', array(':uid1' => $current_uid, ':uid2' => $chat_id))->fetchAll();
+        $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp, m.message_type FROM {drupalchat_msg} m WHERE m.uid2 = \'c-0\' ORDER BY m.timestamp DESC LIMIT 30', array(':uid1' => $current_uid, ':uid2' => $chat_id))->fetchAll();
       }
       else {
-        $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp FROM {drupalchat_msg} m WHERE (m.uid2 = :uid2 AND m.uid1 = :uid1) OR (m.uid2 = :uid1 AND m.uid1 = :uid2) ORDER BY m.timestamp DESC LIMIT 30', array(':uid1' => $current_uid, ':uid2' => $chat_id))->fetchAll();
+        $messages = db_query('SELECT m.message_id, m.uid1, m.uid2, m.message, m.timestamp, m.message_type FROM {drupalchat_msg} m WHERE (m.uid2 = :uid2 AND m.uid1 = :uid1) OR (m.uid2 = :uid1 AND m.uid1 = :uid2) ORDER BY m.timestamp DESC LIMIT 30', array(':uid1' => $current_uid, ':uid2' => $chat_id))->fetchAll();
       }
 
       foreach ($messages as $message) {
+        $message_conversation = drupalchat_format_message_conversation($message);
+
       //print_r($message);
         if((((!strpos($message->uid1,'-')) && ($message->uid1 != $user->uid)) || ((strpos($message->uid1,'-')) && ($message->uid1 != '0-'._drupalchat_get_sid()))) || ($message->uid2 == 'c-0')) {
           if(!strpos($message->uid1,'-')) {
             $account = user_load($message->uid1);
-          $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+          $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
           if(variable_get('drupalchat_user_picture', 1) == 1) {
           $temp_msg['p'] = drupalchat_return_pic_url_any_user($account);
           }
@@ -1581,7 +1652,7 @@ function drupalchat_get_thread_history() {
             $arr = explode("-", $message->uid1, 2);
           $sid = $arr[1];
             $name = db_query('SELECT name FROM {drupalchat_users} WHERE uid = :uid AND session = :sid', array(':uid' => '0', ':sid' => $sid))->fetchField();
-            $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+            $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
           if(variable_get('drupalchat_user_picture', 1) == 1) {
           $temp_msg['p'] = drupalchat_return_pic_url_any_user(user_load('0'));
           }
@@ -1591,7 +1662,7 @@ function drupalchat_get_thread_history() {
         else {
           if(!strpos($message->uid2,'-')) {
             $account = user_load($message->uid2);
-          $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+          $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => check_plain(format_username($account)), 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
           if(variable_get('drupalchat_user_picture', 1) == 1) {
           $temp_msg['p'] = drupalchat_return_pic_url_any_user($account);
           }
@@ -1601,7 +1672,7 @@ function drupalchat_get_thread_history() {
             $arr = explode("-", $message->uid2, 2);
           $sid = $arr[1];
             $name = db_query('SELECT name FROM {drupalchat_users} WHERE uid = :uid AND session = :sid', array(':uid' => '0', ':sid' => $sid))->fetchField();
-            $temp_msg = array('message' => check_plain($message->message), 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
+            $temp_msg = array('message' => $message_conversation, 'timestamp' => date("H:i", $message->timestamp), 'uid1' => $message->uid1, 'name' => $name, 'uid2' => $message->uid2, 'message_id' => check_plain($message->message_id),);
           if(variable_get('drupalchat_user_picture', 1) == 1) {
           $temp_msg['p'] = drupalchat_return_pic_url_any_user(user_load('0'));
           }
@@ -1614,3 +1685,96 @@ function drupalchat_get_thread_history() {
   }
   drupal_json_output($json);
 }
+
+/**
+ * Format message conversation as per the type of message.
+ *
+ * @param object $message
+ *   Message data.
+ *
+ * @return string
+ *   Formatted chat conversation.
+ */
+function drupalchat_format_message_conversation($message) {
+  // Check if message is a text conversation or file attachment.
+  if ($message->message_type == 'text') {
+    $message_conversation = check_plain($message->message);
+  }
+  else if ($message->message_type == 'attachment') {
+    $fid = db_select('drupalchat_files', 'df')
+      ->fields('df', array('fid'))
+      ->condition('message_id', $message->message_id)
+      ->execute()
+      ->fetchField();
+    $file = file_load($fid);
+    $icon = theme('file_icon', array(
+      'file' => $file,
+    ));
+    $message_conversation = l($icon . $file->filename, file_create_url($file->uri), array(
+      'attributes' => array(
+        'target' => '_blank',
+      ),
+      'html' => TRUE,
+    ));
+  }
+
+  return $message_conversation;
+}
+
+/**
+ * Implements hook_library().
+ */
+function drupalchat_library() {
+  $library_path = drupalchat_get_jquery_fileupload_path();
+
+  $libraries['jquery-fileupload'] = array(
+    'title' => 'jQuery Fileupload',
+    'website' => 'https://blueimp.github.io/jQuery-File-Upload',
+    'version' => '9.11.2',
+    'js' => array(
+      $library_path . '/js/jquery.fileupload.js' => array(
+        'group' => 'JS_LIBRARY',
+      ),
+      $library_path . '/js/vendor/jquery.ui.widget.js' => array(
+        'group' => 'JS_LIBRARY',
+      ),
+    ),
+  );
+
+  return $libraries;
+}
+
+/**
+ * Get the location of the jquery fileupload library.
+ *
+ * @return
+ *   The location of the library, or FALSE if the library isn't installed.
+ */
+function drupalchat_get_jquery_fileupload_path() {
+  if (function_exists('libraries_get_path')) {
+    return libraries_get_path('jQuery-File-Upload');
+  }
+
+  // The following logic is taken from libraries_get_libraries()
+  $searchdir = array();
+
+  // Similar to 'modules' and 'themes' directories inside an installation
+  // profile, installation profiles may want to place libraries into a
+  // 'libraries' directory.
+  $searchdir[] = 'profiles/' . drupal_get_profile() . '/libraries';
+
+  // Always search sites/all/libraries.
+  $searchdir[] = 'sites/all/libraries';
+
+  // Also search sites/<domain>/*.
+  $searchdir[] = conf_path() . '/libraries';
+
+  foreach ($searchdir as $dir) {
+    if (file_exists($dir . '/jQuery-File-Upload/js/jquery.fileupload.js') &&
+      file_exists($dir . '/jQuery-File-Upload/js/vendor/jquery.ui.widget.js')) {
+      return $dir . '/jQuery-File-Upload';
+    }
+  }
+
+  return FALSE;
+}
diff --git a/js/drupalchat.js b/js/drupalchat.js
index a74e8d6..e1e3d0d 100644
--- a/js/drupalchat.js
+++ b/js/drupalchat.js
@@ -7,8 +7,6 @@ var jQuery;
 if (window.jQuery === undefined || (Number(window.jQuery.fn.jquery.split('.').join(''))>180)) {
     var script_tag = document.createElement('script');
     script_tag.setAttribute("type","text/javascript");
-    script_tag.setAttribute("src",
-        "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
     if (script_tag.readyState) {
       script_tag.onreadystatechange = function () { // For old versions of IE
           if (this.readyState == 'complete' || this.readyState == 'loaded') {
@@ -27,7 +25,7 @@ if (window.jQuery === undefined || (Number(window.jQuery.fn.jquery.split('.').jo
 
 function drupalchatScriptLoadHandler() {
     jQuery = window.jQuery.noConflict(true);
-    drupalchatMain(); 
+    drupalchatMain();
 }
 
 function drupalchatMain() {
@@ -39,13 +37,13 @@ function drupalchatMain() {
     Drupal.drupalchat.sendMessages = function() {
   	jQuery.post(Drupal.settings.drupalchat.sendUrl, {
   	  drupalchat_message_id: drupalchat.send_current_message_id,
-     	  drupalchat_uid2: drupalchat.send_current_uid2, 
-     	  drupalchat_message: drupalchat.send_current_message 
+     	  drupalchat_uid2: drupalchat.send_current_uid2,
+     	  drupalchat_message: drupalchat.send_current_message
   	});
     };
 
     Drupal.drupalchat.parseHTML = function(text) {
-      var patt = /\b(http:\/\/|https:\/\/|ftp:\/\/|file:\/\/)?(www\.|ftp\.)?[A-Za-z0-9]+[-A-Z0-9@\/_$.]*(\.ac|\.ad|\.ae|\.aero|\.af|\.ag|\.ai|\.al|\.am|\.an|\.ao|\.aq|\.ar|\.arpa|\.as|\.asia|\.at|\.au|\.aw|\.ax|\.az|\.ba|\.bb|\.bd|\.be|\.bf|\.bg|\.bh|\.bi|\.biz|\.bj|\.bm|\.bn|\.bo|\.br|\.bs|\.bt|\.bv|\.bw|\.by|\.bz|\.ca|\.cat|\.cc|\.cd|\.cf|\.cg|\.ch|\.ci|\.ck|\.cl|\.cm|\.cn|\.co|\.com|\.coop|\.cr|\.cu|\.cv|\.cw|\.cx|\.cy|\.cz|\.de|\.dj|\.dk|\.dm|\.do|\.dz|\.ec|\.edu|\.ee|\.eg|\.er|\.es|\.et|\.eu|\.fi|\.fj|\.fk|\.fm|\.fo|\.fr|\.ga|\.gb|\.gd|\.ge|\.gf|\.gg|\.gh|\.gi|\.gl|\.gm|\.gn|\.gov|\.gp|\.gq|\.gr|\.gs|\.gt|\.gu|\.gw|\.gy|\.hk|\.hm|\.hn|\.hr|\.ht|\.hu|\.id|\.ie|\.il|\.im|\.in|\.info|\.int|\.io|\.iq|\.ir|\.is|\.it|\.je|\.jm|\.jo|\.jobs|\.jp|\.ke|\.kg|\.kh|\.ki|\.km|\.kn|\.kp|\.kr|\.kw|\.ky|\.kz|\.la|\.lb|\.lc|\.li|\.lk|\.lr|\.ls|\.lt|\.lu|\.lv|\.ly|\.ma|\.mc|\.md|\.me|\.mg|\.mh|\.mil|\.mk|\.ml|\.mm|\.mn|\.mo|\.mobi|\.mp|\.mq|\.mr|\.ms|\.mt|\.mu|\.museum|\.mv|\.mw|\.mx|\.my|\.mz|\.na|\.name|\.nc|\.ne|\.net|\.nf|\.ng|\.ni|\.nl|\.no|\.np|\.nr|\.nu|\.nz|\.om|\.org|\.pa|\.pe|\.pf|\.pg|\.ph|\.pk|\.pl|\.pm|\.pn|\.pr|\.pro|\.ps|\.pt|\.pw|\.py|\.qa|\.re|\.ro|\.rs|\.ru|\.rw|\.sa|\.sb|\.sc|\.sd|\.se|\.sg|\.sh|\.si|\.sj|\.sk|\.sl|\.sm|\.sn|\.so|\.sr|\.st|\.su|\.sv|\.sx|\.sy|\.sz|\.tc|\.td|\.tel|\.tf|\.tg|\.th|\.tj|\.tk|\.tl|\.tm|\.tn|\.to|\.tp|\.tr|\.travel|\.tt|\.tv|\.tw|\.tz|\.ua|\.ug|\.uk|\.us|\.uy|\.uz|\.va|\.vc|\.ve|\.vg|\.vi|\.vn|\.vu|\.wf|\.ws|\.xn|\.xxx|\.ye|\.yt|\.za|\.zm|\.zw)([-._~:\/?#\[\]@!$&'\(\)\*\+,;=][A-Za-z0-9\.\/\+&@#%=~_|]*)*\b/ig;
+      var patt = /^(http:\/\/|https:\/\/|ftp:\/\/|file:\/\/)?(www\.|ftp\.)?[A-Za-z0-9]+[-A-Z0-9@\/_$.]*(\.ac|\.ad|\.ae|\.aero|\.af|\.ag|\.ai|\.al|\.am|\.an|\.ao|\.aq|\.ar|\.arpa|\.as|\.asia|\.at|\.au|\.aw|\.ax|\.az|\.ba|\.bb|\.bd|\.be|\.bf|\.bg|\.bh|\.bi|\.biz|\.bj|\.bm|\.bn|\.bo|\.br|\.bs|\.bt|\.bv|\.bw|\.by|\.bz|\.ca|\.cat|\.cc|\.cd|\.cf|\.cg|\.ch|\.ci|\.ck|\.cl|\.cm|\.cn|\.co|\.com|\.coop|\.cr|\.cu|\.cv|\.cw|\.cx|\.cy|\.cz|\.de|\.dj|\.dk|\.dm|\.do|\.dz|\.ec|\.edu|\.ee|\.eg|\.er|\.es|\.et|\.eu|\.fi|\.fj|\.fk|\.fm|\.fo|\.fr|\.ga|\.gb|\.gd|\.ge|\.gf|\.gg|\.gh|\.gi|\.gl|\.gm|\.gn|\.gov|\.gp|\.gq|\.gr|\.gs|\.gt|\.gu|\.gw|\.gy|\.hk|\.hm|\.hn|\.hr|\.ht|\.hu|\.id|\.ie|\.il|\.im|\.in|\.info|\.int|\.io|\.iq|\.ir|\.is|\.it|\.je|\.jm|\.jo|\.jobs|\.jp|\.ke|\.kg|\.kh|\.ki|\.km|\.kn|\.kp|\.kr|\.kw|\.ky|\.kz|\.la|\.lb|\.lc|\.li|\.lk|\.lr|\.ls|\.lt|\.lu|\.lv|\.ly|\.ma|\.mc|\.md|\.me|\.mg|\.mh|\.mil|\.mk|\.ml|\.mm|\.mn|\.mo|\.mobi|\.mp|\.mq|\.mr|\.ms|\.mt|\.mu|\.museum|\.mv|\.mw|\.mx|\.my|\.mz|\.na|\.name|\.nc|\.ne|\.net|\.nf|\.ng|\.ni|\.nl|\.no|\.np|\.nr|\.nu|\.nz|\.om|\.org|\.pa|\.pe|\.pf|\.pg|\.ph|\.pk|\.pl|\.pm|\.pn|\.pr|\.pro|\.ps|\.pt|\.pw|\.py|\.qa|\.re|\.ro|\.rs|\.ru|\.rw|\.sa|\.sb|\.sc|\.sd|\.se|\.sg|\.sh|\.si|\.sj|\.sk|\.sl|\.sm|\.sn|\.so|\.sr|\.st|\.su|\.sv|\.sx|\.sy|\.sz|\.tc|\.td|\.tel|\.tf|\.tg|\.th|\.tj|\.tk|\.tl|\.tm|\.tn|\.to|\.tp|\.tr|\.travel|\.tt|\.tv|\.tw|\.tz|\.ua|\.ug|\.uk|\.us|\.uy|\.uz|\.va|\.vc|\.ve|\.vg|\.vi|\.vn|\.vu|\.wf|\.ws|\.xn|\.xxx|\.ye|\.yt|\.za|\.zm|\.zw)([-._~:\/?#\[\]@!$&'\(\)\*\+,;=][A-Za-z0-9\.\/\+&@#%=~_|]*)*\b/ig;
       var a = text.match(patt);
       var pos= 0,final_string = "",prefix = "";
       if (a)
@@ -71,7 +69,7 @@ function drupalchatMain() {
       }
       return text;
     };
-    
+
     Drupal.drupalchat.checkChatBoxInputKey = function(event, chatboxtextarea, chatboxtitle) {
       if(event.keyCode == 13 && event.shiftKey == 0)  {
   	  message = jQuery(chatboxtextarea).val();
@@ -110,7 +108,7 @@ function drupalchatMain() {
   		  if(Drupal.settings.drupalchat.iup == "1") {
   		    output = output + '<div class="chatboxuserpicture"><img height="20" width="20" src="'+Drupal.settings.drupalchat.up+'" /></div>';
   		  }
-  		  
+
   		  output = output + '<span class="chatboxtime">'+hours+':'+minutes+'</span><a href="'+Drupal.settings.basePath+'user/'+Drupal.settings.drupalchat.uid+'">'+Drupal.settings.drupalchat.username+'</a></div><p class=\''+drupalchat.send_current_message_id+'\'>'+message+'</p>';
             jQuery("#chatbox_"+chatboxtitle+" .chatboxcontent").append(output);
           }
@@ -128,13 +126,13 @@ function drupalchatMain() {
         adjustedHeight = Math.min(maxHeight, adjustedHeight);
       if (adjustedHeight > chatboxtextarea.clientHeight)
         jQuery(chatboxtextarea).css('height', adjustedHeight+8 + 'px');
-      } 
+      }
   	else {
         jQuery(chatboxtextarea).css('overflow', 'auto');
       }
       return true;
     };
-    
+
     Drupal.drupalchat.changeStatus = function(id, state) {
   	if(state == 1) {
   	  jQuery('#' + id + ' .subpanel_title > div').removeClass('status-0').addClass('status-1');
@@ -158,8 +156,8 @@ function drupalchatMain() {
   	attach_messages_in_queue: 0,
   	running: 0,
   	online_users: 0,
-  	/*smilies: { 
-      //smiley     image_url          title_text              alt_smilies           
+  	/*smilies: {
+      //smiley     image_url          title_text              alt_smilies
       ":)":    [ "1.gif",        "happy",                ":-)"                 ],
       ":(":    [ "2.gif",         "sad",                  ":-("                 ],
       ";)":    [ "3.gif",        "winking",              ";-)"                 ],
@@ -296,7 +294,7 @@ function drupalchatMain() {
         drupalchat.open_chat_uids[temp_open_chat_uids[e]] = temp_open_chat_uids[e];
       }
     }
-    
+
     if(Drupal.drupalchat.Cookie.read('drupalchat_current_open_chat_window_ids') !== null) {
       var temp_open_chat_window_uids = [];
       temp_open_chat_window_uids = Drupal.drupalchat.Cookie.read('drupalchat_current_open_chat_window_ids').split(",");
@@ -304,19 +302,19 @@ function drupalchatMain() {
         drupalchat.current_open_chat_window_ids[temp_open_chat_window_uids[e]] = temp_open_chat_window_uids[e];
       }
     }
-    
-  	
+
+
   	//Load smileys.
   	emotify.emoticons( Drupal.settings.drupalchat.smileyURL, drupalchat.smilies );
   	//Adjust panel height
   	jQuery.fn.adjustPanel = function(){
   	    jQuery(this).find("ul, .subpanel").css({ 'height' : 'auto'}); //Reset sub-panel and ul height
-  	
+
   	    var windowHeight = jQuery(window).height(); //Get the height of the browser viewport
   	    var panelsub = jQuery(this).find(".subpanel").height(); //Get the height of sub-panel
   	    var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of sub-panel)
   	    var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel
-  	
+
   	    if (panelsub > panelAdjust) {	 //If sub-panel is taller than max height...
   	        jQuery(this).find(".subpanel").css({ 'height' : panelAdjust}); //Adjust sub-panel to max height
   	        jQuery(this).find("ul").css({ 'height' : (panelAdjust - 48)}); ////Adjust subpanel ul to new size
@@ -325,20 +323,20 @@ function drupalchatMain() {
   	    	jQuery(this).find("ul").css({ 'height' : 'auto'}); //Set sub-panel ul to auto (default size)
   	    }
   	};
-  	
+
   	//Execute function on load
   	jQuery("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
-  	
+
   	//Each time the viewport is adjusted/resized, execute the function
   	jQuery(window).resize(function () {
   	    jQuery("#chatpanel").adjustPanel();
   	});
-  	
+
   	//Add sound effect SWF file to document
   	jQuery("<div style=\"width: 0px; height: 0px; overflow: hidden;\"><object id=\"drupalchatbeep\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"1\" height=\"1\"><param name=\"movie\" value=\"" + Drupal.settings.drupalchat.sound + "\"/><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"" + Drupal.settings.drupalchat.sound + "\" width=\"1\" height=\"1\"></object><!--<![endif]--></object></div>").appendTo(jQuery("body"));
   	swfobject.registerObject("drupalchatbeep", "9");
-  	
-  	//Click event on subpanels	
+
+  	//Click event on subpanels
   	jQuery("#mainpanel li a.subpanel_toggle, .chatbox a.chatboxhead").live('click', function() { //If clicked on the first link of #chatpanel...
   	    if(jQuery(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
   	        jQuery(this).next(".subpanel").hide(); //Hide active subpanel
@@ -353,7 +351,7 @@ function drupalchatMain() {
   			jQuery(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
   	        // Chat box functions
   	        var isTextarea = jQuery(this).next(".subpanel").children(".chatboxinput").children(".chatboxtextarea");
-  	        if (isTextarea.length > 0) { 
+  	        if (isTextarea.length > 0) {
   	        	isTextarea[0].focus();
   	        	jQuery(this).next(".subpanel").children(".chatboxcontent").scrollTop(jQuery(this).next(".subpanel").children(".chatboxcontent")[0].scrollHeight);
   	        }
@@ -361,7 +359,7 @@ function drupalchatMain() {
   		jQuery('#drupalchat-chat-options').hide();
   	    return false; //Prevent browser jump to link anchor
   	});
-  		
+
   	jQuery('.subpanel .subpanel_title').live('click', function() { //Click anywhere and...
   	    //jQuery(".subpanel").hide(); //hide subpanel
   		jQuery(this).parent().hide(); //hide subpanel
@@ -371,7 +369,7 @@ function drupalchatMain() {
       if(jQuery('#chatbox_'+id).is(':visible')) {
         updateLocalChatWindowList(jQuery(this).parent().parent().attr('id').split('_')[1], 'min');
       }
-  	});	
+  	});
   	jQuery('#drupalchat .subpanel .subpanel_title span.options').live('click', function() { //Click anywhere and...
   		var offset = jQuery(this).offset();
   		offset.top = offset.top + 20;
@@ -400,7 +398,7 @@ function drupalchatMain() {
   	jQuery('body').live('click', function() {
   	  jQuery('#drupalchat-chat-options').hide();
   	});
-  	
+
   	jQuery('.subpanel ul').click(function(e) {
   //	    e.stopPropagation(); //Prevents the subpanel ul from closing on click
   	});
@@ -408,8 +406,8 @@ function drupalchatMain() {
   	jQuery("#chatpanel .subpanel li:not(.link) a").live('click', function(e) {
         chatWith(jQuery(this).attr("class"), jQuery(this).text());
   			return false;
-  	});	
-  	
+  	});
+
   	jQuery(".chatbox .subpanel_title span:not(.min)").live('click', function (e) {
       closeChatBox(jQuery(this).attr('class'));
   	});
@@ -422,7 +420,7 @@ function drupalchatMain() {
               jQuery(".chat_options .chat_loading").removeClass('chat_loading').addClass('status-1').html(Drupal.settings.drupalchat.goOnline);
               jQuery("#chatpanel .icon").attr("src", Drupal.settings.drupalchat.images + "chat-2.png");
   	}
-  		
+
   	jQuery(".chat_options .status-1").live('click', function() {
               jQuery(".chat_options .status-1").removeClass('status-1').addClass('chat_loading');
               jQuery.post(Drupal.settings.drupalchat.statusUrl, {status: "1"}, function(data){
@@ -436,16 +434,16 @@ function drupalchatMain() {
                   jQuery(".chat_options .chat_loading").removeClass('chat_loading').addClass('status-1').html(Drupal.settings.drupalchat.goOnline);
                   jQuery("#chatpanel .icon").attr("src", Drupal.settings.drupalchat.images + "chat-2.png");
               });
-  	});	
-  	
+  	});
+
   	jQuery(".chat_options .options").live('click', function() {
               alert('Under Construction');
   	});
-    
-  	// Add short delay before first poll call. This avoids Chrome loading-icon bug. 
+
+  	// Add short delay before first poll call. This avoids Chrome loading-icon bug.
     setTimeout(function () {
       chatPoll();
-    }, 500); 
+    }, 500);
     jQuery('#drupalchat .subpanel .chatboxcontent').live('mouseenter', function() {
       jQuery(this).css("overflow-y","auto");
   	//document.body.style.overflow='hidden';
@@ -454,7 +452,7 @@ function drupalchatMain() {
       jQuery(this).css("overflow-y","hidden");
   	//document.body.style.overflow='auto';
     });
-    
+
     //Get thread history
     getThreadHistory();
   });
@@ -465,12 +463,12 @@ function drupalchatMain() {
       jQuery("#chatbox_"+chatboxtitle+" a:first").click(); //Toggle the subpanel to make active
       jQuery("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
       updateLocalChatWindowList(chatboxtitle, 'open');
-      
+
   }
 
 
   function createChatBox(chatboxtitle, chatboxname, chatboxblink) {
-    
+
       if (jQuery("#chatbox_"+chatboxtitle).length > 0) {
           if (jQuery("#chatbox_"+chatboxtitle).css('display') == 'none') {
               jQuery("#chatbox_"+chatboxtitle).css('display', 'block');
@@ -483,9 +481,16 @@ function drupalchatMain() {
         updateLocalChatWindowList(chatboxtitle, 'min');
       }
 
+      if (Drupal.settings.drupalchat.enableFileAttachment) {
+          var fileUpload = '<input type="file" class="chatboxfileupload" name="files[drupalchat-file-attachment]" />';
+      }
+      else {
+          var fileUpload = '';
+      }
+
       jQuery(" <li />" ).attr("id","chatbox_"+chatboxtitle)
       .addClass("chatbox")
-      .html('<a href="#" class="chatboxhead"><span class="subpanel_title_text">'+chatboxname+'</span></a><div class="subpanel"><div class="subpanel_title"><span class="'+chatboxtitle+'" title="Close">x</span><span title = "Minimize" class="min">_</span><div class="status-1"></div>'+chatboxname+'</div><div class="chatboxcontent"></div><div class="drupalchat_userOffline">'+chatboxname+' is currently offline.</div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="return Drupal.drupalchat.checkChatBoxInputKey(event,this,\''+chatboxtitle+'\');"></textarea></div></div>')
+      .html('<a href="#" class="chatboxhead"><span class="subpanel_title_text">'+chatboxname+'</span></a><div class="subpanel"><div class="subpanel_title"><span class="'+chatboxtitle+'" title="Close">x</span><span title = "Minimize" class="min">_</span><div class="status-1"></div>'+chatboxname+'</div><div class="chatboxcontent"></div><div class="drupalchat_userOffline">'+chatboxname+' is currently offline.</div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="return Drupal.drupalchat.checkChatBoxInputKey(event,this,\''+chatboxtitle+'\');"></textarea>' + fileUpload +'</div></div>')
       .prependTo(jQuery( "#mainpanel" ));
 
       if (chatboxblink == 1) {
@@ -505,9 +510,38 @@ function drupalchatMain() {
               updateLocalChatWindowList(chatboxtitle, 'open');
           }
       });
+      if (Drupal.settings.drupalchat.enableFileAttachment) {
+          attachFileAction("#chatbox_"+chatboxtitle + ' .chatboxfileupload', chatboxtitle);
+      }
       jQuery("#chatbox_"+chatboxtitle).show();
   }
 
+  /**
+   * Upload file to the server and send it as attachment to the user.
+   */
+  function attachFileAction(el, chatboxtitle) {
+      var id = '#chatbox_' + chatboxtitle;
+      var m =  'm_' + Drupal.settings.drupalchat.uid + '_' + chatboxtitle;
+
+      jQuery(el).fileupload({
+          dataType: 'json',
+          url: 'drupalchat/sendfile',
+          formData:[{name: 'drupalchat_message_id', value: m}, {name: 'drupalchat_uid2', value: chatboxtitle}],
+          done: function(e, data) {
+            if (data.result.error) {
+              alert(data.result.error[0]);
+            }
+            else {
+              console.log(data.result.response);
+            }
+          },
+          fail: function(e, data) {
+            alert('Error occurred');
+          },
+      }).prop('disabled', !jQuery.support.fileInput)
+          .parent().addClass(jQuery.support.fileInput ? undefined : 'disabled');
+  }
+
   function chatPoll() {
       if(Drupal.settings.drupalchat.polling_method == '0') {
   	  setTimeout(function() {
@@ -552,7 +586,7 @@ function drupalchatMain() {
   		      }
   			  catch(e) {
   			  }
-  			}			
+  			}
   		}
   		jQuery.each(drupalchat_messages.messages, function(index, value) {
   		    var drupalselfmessage = false;
@@ -565,7 +599,7 @@ function drupalchatMain() {
   			}
               else {
   			  drupalchatroom = false;
-              }			
+              }
   			chatboxtitle = (drupalchatroom || drupalselfmessage)?value.uid2:value.uid1;
   			if (jQuery("#chatbox_"+chatboxtitle).length <= 0) {
   				createChatBox(chatboxtitle, drupalchatroom?"Public Chatroom":value.name, 1);
@@ -583,11 +617,11 @@ function drupalchatMain() {
   				jQuery("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
   			}
               if(value.uid1 == Drupal.settings.drupalchat.uid) {
-                value.name = Drupal.settings.drupalchat.username;  
+                value.name = Drupal.settings.drupalchat.username;
               }
   			if(jQuery("."+value.message_id)[0]){
   			  return;
-              }			  
+              }
   			value.message = value.message.replace(/{{drupalchat_newline}}/g,"<br />");
   			value.message = Drupal.drupalchat.parseHTML(value.message);
         if(Drupal.settings.drupalchat.allowSmileys === "1") {
@@ -606,14 +640,14 @@ function drupalchatMain() {
   				if (minutes < 10) {
   					minutes = "0" + minutes;
   				}
-          
+
           var formattedCurrentTime = hours+':'+minutes;
-          
+
           if((typeof(history) === 'boolean') && history) {
             formattedCurrentTime = value.timestamp;
           }
-          
-          var output = '<div class="chatboxusername">';				
+
+          var output = '<div class="chatboxusername">';
   				if(Drupal.settings.drupalchat.iup == "1") {
   				  output = output + '<div class="chatboxuserpicture"><img height="20" width="20" src="'+value.p+'" /></div>';
   				}
@@ -621,12 +655,12 @@ function drupalchatMain() {
   				jQuery("#chatbox_"+chatboxtitle+" .chatboxcontent").append(output);
   			}
   			jQuery("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop(jQuery("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
-  			
+
               if(typeof(jQuery.titleAlert)==="function") {
                 jQuery.titleAlert(Drupal.settings.drupalchat.newMessage, {requireBlur:true, stopOnFocus:true, interval:800});
               }
   		});
-  		
+
   	  jQuery('#chatpanel .subpanel ul').empty();
   	  jQuery('li[id^="chatbox_"]').each(function(){
   	    Drupal.drupalchat.changeStatus(this.id,0);
@@ -652,14 +686,14 @@ function drupalchatMain() {
           }
         });
         jQuery('#chatpanel .subpanel ul li:last-child').addClass('last');
-  	  
+
         /*if (jQuery('#chatpanel .subpanel ul li').length <= 0) {
           jQuery('#chatpanel .subpanel ul').append(Drupal.settings.drupalchat.noUsers);
         }*/
-        
+
         //Update Timestamp.
         drupalchat.last_timestamp = drupalchat_messages.last_timestamp;
-      }        
+      }
   	}
   	//if (Drupal.settings.drupalchat.polling_method != '0') {
   		chatPoll();
@@ -670,7 +704,7 @@ function drupalchatMain() {
     updateLocalChatWindowList(chatboxtitle, 'close');
   	jQuery('#chatbox_'+chatboxtitle).css('display','none');
   }
-  
+
   function updateLocalChatWindowList(chatboxtitle, state) {
     if(state === 'min') {
       drupalchat.open_chat_uids[chatboxtitle] = chatboxtitle;
@@ -694,7 +728,7 @@ function drupalchatMain() {
     else {
       Drupal.drupalchat.Cookie.delete('drupalchat_open_chat_uids');
     }
-    
+
     var temp_open_chat_window_uids = [];
     for(var e in drupalchat.current_open_chat_window_ids) {
       temp_open_chat_window_uids.push(drupalchat.current_open_chat_window_ids[e]);
@@ -706,13 +740,13 @@ function drupalchatMain() {
       Drupal.drupalchat.Cookie.delete('drupalchat_current_open_chat_window_ids');
     }
   }
-  
+
   function getThreadHistory() {
     var temp_open_chat_uids = [];
     for(var e in drupalchat.open_chat_uids) {
       temp_open_chat_uids.push(drupalchat.open_chat_uids[e]);
     }
-    
+
     jQuery.post(Drupal.settings.drupalchat.threadHistoryUrl, { drupalchat_open_chat_uids: temp_open_chat_uids.join(",") }, function(data) {
       var temp_open_ids = {};
       for(var i in drupalchat.current_open_chat_window_ids) {
@@ -771,8 +805,8 @@ function drupalchatMain() {
   Drupal.drupalchat.Cookie.delete = function (name) {
     Drupal.drupalchat.Cookie.create(name,"",-1);
   };
-  
-  
+
+
   //})(jQuery);
 
 }
