=== added file 'sites/all/modules/drupalorg/blocks_and_nodes/pivots_block.js'
--- sites/all/modules/drupalorg/blocks_and_nodes/pivots_block.js	1970-01-01 00:00:00 +0000
+++ sites/all/modules/drupalorg/blocks_and_nodes/pivots_block.js	2011-07-13 15:58:41 +0000
@@ -0,0 +1,30 @@
+Drupal.behaviors.pivotsBlock = function(context) {
+  var data = $('.pivots-block-list', context).attr('id').split(':');
+  var pivot_id = data[0];
+  var ga_data = data[1];
+  _gaq.push(['_trackEvent', 'PivotsPageview_'+pivot_id, ga_data]);
+  
+  $('.pivots-block-item', context).click(function() {
+    var data = $(this, context).attr('id').split(':');
+    var pivot_id = data[0];
+    var ga_data = data[1];
+    _gaq.push(['_trackEvent', 'PivotsClick_'+pivot_id, ga_data]);
+  });
+  
+  $('#pivots-block-button', context).click(function() {
+    var pattern = /^http(s)?:\/\/drupal\.org\/project\/\w+$/;
+    var suggestion = $('#pivots-block-suggestion', context).val();
+    while (!suggestion.match(pattern)) {
+      suggestion = prompt('To prevent spamming, please suggest a related project using its URL starts with http://drupal.org/project/*. Thank you.');
+      if (!suggestion) break;
+    }
+    if (suggestion) {
+      alert('Thank you for suggesting a related project. All suggestions will be aggregated and updated to the results soon.');
+      var data = $(this, context).attr('name').split(':');
+      var pivot_id = data[0];
+      var source_nid = data[1];
+      _gaq.push(['_trackEvent', 'PivotsSuggest_'+pivot_id, source_nid+'_'+suggestion]);
+      $('#pivots-block-suggestion').val('');
+    }
+  });
+};

=== modified file 'sites/all/modules/drupalorg/blocks_and_nodes/pivots_block.module'
--- sites/all/modules/drupalorg/blocks_and_nodes/pivots_block.module	2011-05-31 05:03:33 +0000
+++ sites/all/modules/drupalorg/blocks_and_nodes/pivots_block.module	2011-07-13 15:47:45 +0000
@@ -16,52 +16,50 @@
  * Foundation.
  */
 
-define('PID_DOUBLE', 5008);       // double pivot algorithm ID that displays related projects in different algorithms.
-define('LIMIT_DOUBLE', 5);
-define('LIMIT_MAX', 100);         // maximum items to display in the block or on a page.
+define('PIVOT_ID', 6001);       // pivot algorithm ID that displays related projects in different algorithms.
+define('LIMIT_BLOCK', 5);       // number of "related projects" to display in the block.
+define('LIMIT_MAX', 100);       // maximum items to display in the block or on a page.
 
+/**
+ * Generates content for the "related projects" block.
+ */
 function pivots_block_output() {
   // Skip the Drupal core project.
   if (($node = project_get_project_from_menu()) && ($node->nid != DRUPALORG_CORE_NID)) {
-
-    //HACK: randomize algorithm rotation
-    $_pivots_block_pid_double = PID_DOUBLE;  // double pivot ID defaults to conversation pivots
-    switch (rand(0,1)) {
-      case 0:
-        $_pivots_block_pid_double = 5008; // conversation pivots
-        break;
-      case 1:
-        $_pivots_block_pid_double = 5009; // solr10
-        break;
-    }
-
-    $output = _pivots_block_content($node->nid, $_pivots_block_pid_double, t("Related projects"), LIMIT_DOUBLE);
-    //$output .= _pivots_block_suggestbox($node->nid, $_pivots_block_pid_double);
+    $output = _pivots_block_content($node->nid, PIVOT_ID, t("Related projects"), LIMIT_BLOCK);
+    $output .= _pivots_block_suggestbox($node->nid, PIVOT_ID);
     return $output;
   }
 }
 
+/**
+ * Generates the 5 "related projects"
+ */
 function _pivots_block_content($node_id, $pivot_id, $title, $limit) {
   $output = '';
-  $ga_event = "$node_id";
+  $ga_data = "$node_id";
   $items = _pivots_block_generate_items($node_id, $pivot_id, $limit);
   if (!empty($items)) {
     foreach ($items as $position => $item) {
       $items[$position] = l($item['title'], "node/{$item['nid']}", array( 'attributes' => array(
-              "onClick" => "javascript:_gaq.push(['_trackEvent', 'PivotsClick_${pivot_id}', '${node_id}_{$item['nid']}']);",
-              "rel"     => "nofollow"
+        'class' => 'pivots-block-item',
+        'id'    => "${pivot_id}:${node_id}_{$item['nid']}",
+        'rel'   => 'nofollow',
       )));
-      $ga_event .= "_{$item['nid']}";
+      $ga_data .= "_{$item['nid']}";
     }
-    //$output = theme('item_list', $items, $title);
-    $output = theme('item_list', $items); // hack: don't show title
+    $output = theme('item_list', $items, NULL, 'ul', array(
+      'class' => 'pivots-block-list',
+      'id'    => "${pivot_id}:${ga_data}",
+    ));
   }
-  drupal_add_js("$(document).ready(function() {
-    _gaq.push(['_trackEvent', 'PivotsPageview_{$pivot_id}', '{$ga_event}']);
-  });", 'inline', 'footer');
   return $output;
 }
 
+
+/**
+ * Retrieve "related projects" items from the pivots database, defined in $db_url['pivots'] in settings.php.
+ */
 function _pivots_block_generate_items($node_id, $pivot_id, $limit) {
   if ($limit <= 0) {
     $limit = LIMIT_MAX;
@@ -89,45 +87,32 @@
   return $items;
 }
 
-/*function _pivots_block_suggestbox($node_id, $pivot_id) {
+
+/**
+ * Generates the "suggest box" for new "related projects".
+ */
+function _pivots_block_suggestbox($node_id, $pivot_id) {
   $form = array();
   $form['suggestion'] = array (
-    '#type' => 'textfield',
-    //'#description' => t("Please suggest related projects. Multiple suggestions require multiple submission."),
-    '#size' => 20,
+    '#type'      => 'textfield',
+    '#size'      => 20,
     '#maxlength' => 128,
-    '#weight' => 0,
-    '#id' => 'pivots_block_suggestbox',
+    '#weight'    => 0,
+    '#id'        => 'pivots-block-suggestion',
   );
   $form['submit'] = array(
-    '#type' => 'button',
-    '#value' => t('Suggest project!'),
-    '#weight' => 1,
-    '#id' => 'pivots_block_suggestbutton'
+    '#type'      => 'button',
+    '#value'     => t('Suggest project!'),
+    '#weight'    => 1,
+    '#id'        => 'pivots-block-button',
+    '#name'      => "${pivot_id}:${node_id}",
   );
-
-  drupal_add_js("
-      $(document).ready(function() {
-        $('#pivots_block_suggestbutton').click(function() {
-          var pattern = /^http[:][/][/]drupal[.]org[/]project[/]\w+$/;
-          var suggestion = $('#pivots_block_suggestbox').val();
-          while (!suggestion.match(pattern)) {
-            suggestion = prompt('Please suggest a related project using URLs such as http://drupal.org/project/cck. Thank you.');
-            if (!suggestion) break;
-          }
-          if (suggestion) {
-            alert('Thank you for suggesting a related project. All suggestions will be aggregated and updated to the results soon.');
-            pageTracker._trackEvent('PivotsSuggest_${pivot_id}', '${node_id}_'+suggestion);
-          }
-        });
-      });
-    ", 'inline');
-
   return drupal_render_form('pivots_block_suggestbox', $form);
-}*/
+}
+
 
 /**
- * Implementation of hook_block()
+ * Implements hook_block().
  */
 function pivots_block_block($op = 'list', $delta = 0, $edit = array()) {
   switch ($op) {
@@ -147,3 +132,12 @@
       return $block;
   }
 }
+
+/**
+ * Implements hook_init().
+ */
+function pivots_block_init() {
+  if (($node = project_get_project_from_menu()) && ($node->nid != DRUPALORG_CORE_NID)) {
+    drupal_add_js(drupal_get_path('module', 'pivots_block') .'/pivots_block.js');
+  }
+}

