--- radioactivity_node.install.original	Sun Nov 02 19:52:43 2008
+++ radioactivity_node.install	Fri Jun 11 15:17:41 2010
@@ -71,6 +71,7 @@
 function radioactivity_node_uninstall() {
   drupal_uninstall_schema('radioactivity_node');
   variable_del('radioactivity_node_click_duration');
+  variable_del('radioactivity_node_mode');
   if (db_table_exists('radioactivity')) {
     db_query("DELETE FROM {radioactivity} WHERE class='node'");
   }
--- radioactivity_node-admin-ui.inc.original	Sun Nov 02 19:52:43 2008
+++ radioactivity_node-admin-ui.inc	Fri Jun 11 15:35:34 2010
@@ -14,6 +14,15 @@
           '#required' => TRUE,
           '#default_value' => _radioactivity_node_get_click_duration());
 
+  $form['radioactivity_node_mode'] = array(
+    '#type' => 'radios',
+    '#title' => t('Mode'),
+    '#default_value' => variable_get('radioactivity_node_mode', 'normal'),
+    '#options' => array('normal' => t('Normal'), 'ajax' => t('AJAX')),
+    '#description' => t('AJAX works for staticaly cached pages. You have to enable "Radioactivity Node: AJAX update" block. '.
+                        'Note: Every time you change this setting the cached pages need to be regenerated.')
+  );
+
   return system_settings_form($form);
 }
 
--- radioactivity_node.module.original	Fri Jul 31 17:19:21 2009
+++ radioactivity_node.module	Fri Jun 11 15:45:59 2010
@@ -58,6 +58,11 @@
           'weight'  => 10,
           'type'    => MENU_LOCAL_TASK,
           'file'    => 'radioactivity_node-admin-ui.inc');
+  $items['radioactivity_node.php'] = array(
+    'page callback' => 'radioactivity_node_ajax_callback',
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('access content')
+  );
   return $items;
 }
 
@@ -174,4 +179,105 @@
   return array('handlers' =>
                array('radioactivity_node_views_handler_sort_left_or_inner' =>
                      array('parent' => 'views_handler_sort')));
+}
+
+/**
+ * Implementation of hook_block().
+ *
+ * @see boost_block()
+ */
+function radioactivity_node_block($op = 'list', $delta = 0, $edit = array()) {
+  global $user;
+
+  switch ($op) {
+    case 'list':
+      return array(
+        0 => array(
+          'info'   => t('Radioactivity Node: AJAX update'),
+          'cache'  => BLOCK_NO_CACHE,
+        ),
+      );
+
+    case 'view':
+      switch ($delta) {
+        case 0:
+          if (!( strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE
+              || variable_get('site_offline', 0)
+              || ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD')
+              || $_SERVER['SERVER_SOFTWARE'] === 'PHP CLI'
+              || isset($_GET['nocache'])
+              || !empty($user->uid)
+              || variable_get('radioactivity_node_mode', '') != 'ajax'
+              )) {
+            $block = array();
+            $block['subject'] = '';
+            $block['content'] = '<div id="node-radioactivity-update"></div>' . radioactivity_node_ajax_code();
+            return $block;
+          }
+          break;
+      }
+  }
+}
+
+/**
+ * AJAX Menu Callback.
+ */
+function radioactivity_node_ajax_callback() {
+  if (!isset($_GET['nid'])) {
+    return drupal_not_found();
+  }
+  $nid = isset($_GET['nid']) ? $_GET['nid'] : NULL;
+
+  if (!isset($_GET['js'])) {
+    header('Content-type: image/gif');
+    header('Expires: Sun, 19 Nov 1978 05:00:00 GMT');
+    header('Cache-Control: no-cache');
+    header('Cache-Control: must-revalidate');
+    header('Content-Length: 0');
+    header('Connection: close');
+  }
+
+  // node_load() check? radioactivity_node_user_node_view($nid) won't check
+  // if it's a real NID...
+  if (is_numeric($nid) && $nid) {
+    radioactivity_node_user_node_view($nid);
+  }
+}
+
+/**
+ * Generate js/html for radioactivity counter.
+ *
+ * NOTE HTML code could be added to the $buffer directly. Would prevent 2x
+ * counts on first view. Would be hard to do though.
+ *
+ * @see boost_stats_generate()
+ */
+function radioactivity_node_ajax_code() {
+  global $base_path;
+
+  // is node & node count enabled.
+  if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
+    $nid = arg(1);
+  }
+  else {
+    $nid = 'NULL';
+  }
+
+  $page_js = array(
+    'radioactivity_node' => array(
+      'nid' => $nid
+    )
+  );
+  $site_js = <<<ETO
+$.get(Drupal.settings.basePath + "radioactivity_node.php", {nocache: "1", js: "1", nid: Drupal.settings.radioactivity_node.nid}, function(response) {});
+ETO;
+
+  // page specific variables
+  drupal_add_js($page_js, 'setting', 'header');
+  // site-wide code
+  drupal_add_js($site_js, 'inline', 'footer');
+  // no script code
+  $page_ns = '<noscript><div style="display:inline;"><img src="' . $base_path . 'radioactivity_node.php' . '?nocache=1' . '&amp;nid='. $nid .'" alt="" /></div></noscript>';
+
+  return $page_ns;
 }
