Index: jquery_update.module
===================================================================
--- jquery_update.module	(revision 1)
+++ jquery_update.module	(working copy)
@@ -6,7 +6,18 @@
  * Updates Drupal to use the latest version of jQuery.
  */
 
+//defines a constant to be used as the default version to load when using the Google AJAX Libraries API  
+define('GAL_API_VERSION_DEFAULT', '1.2.6'); 
+define('GAL_API_UI_VERSION_DEFAULT', '1.6'); 
+
 /**
+ * Implementation of hook_perm().
+ */
+function jquery_update_perm() {
+  return array('administer jQuery update');
+}
+
+/**
  * The path to the jQuery files that need to be replaced.
  */
 define('JQUERY_UPDATE_REPLACE_PATH', drupal_get_path('module', 'jquery_update') .'/replace');
@@ -53,16 +64,33 @@
 function jquery_update_preprocess_page(&$variables) {
   // Only do this for pages that have JavaScript on them.
   if (!empty($variables['scripts'])) {
+    $use_google = variable_get('use_google', 0) == 1;
+    $use_google_ui = variable_get('use_google_ui', 0) == 1;
 
     // Perform the logic if either jQuery Update's jquery.js is newer than core's.
-    if (variable_get('jquery_update_replace', TRUE)) {
+    if (variable_get('jquery_update_replace', TRUE) || $use_google || $use_google_ui) {
       // Get an array of all the JavaScript files loaded by Drupal on this page.
       $scripts = drupal_add_js();
-
-      // Replace jquery.js first.
-      $new_jquery = array(jquery_update_jquery_path() => $scripts['core']['misc/jquery.js']);
-      $scripts['core'] = array_merge($new_jquery, $scripts['core']);
+      $google_load = '';
+      $google_js = '';
+      
+      if ($use_google) {
+        $google_load = 'google.load("jquery", "'.variable_get('jquery_version', GAL_API_VERSION_DEFAULT).'");';
+      } else {
+        // Replace jquery.js first.
+        $new_jquery = array(jquery_update_jquery_path() => $scripts['core']['misc/jquery.js']);
+        $scripts['core'] = array_merge($new_jquery, $scripts['core']);
+      }
       unset($scripts['core']['misc/jquery.js']);
+      
+      if ($use_google_ui) {
+        $google_load .= 'google.load("jqueryui", "'.variable_get('jquery_ui_version', GAL_API_UI_VERSION_DEFAULT).'");';
+      }
+      
+      if ($google_load) {
+        $google_js = "<script type=\"text/javascript\" src=\"http://www.google.com/jsapi\"></script>\n";
+        $google_js .= drupal_get_js('inline', array('inline'=>array(array('code'=>$google_load, 'defer'=>false))));
+      }
 
       // Loop through each of the required replacements.
       foreach (jquery_update_get_replacements() as $type => $replacements) {
@@ -77,7 +105,7 @@
         }
       }
 
-      $variables['scripts'] = drupal_get_js('header', $scripts);
+      $variables['scripts'] = $google_js . drupal_get_js('header', $scripts);
     }
   }
 }
@@ -92,17 +120,22 @@
  */
 function jquery_update_get_version($jquery_path = NULL) {
   $version = 0;
-  $pattern = '# * jQuery JavaScript Library v([0-9\.a-z]+)#';
 
-  // No file is passed in so default to the file included with this module.
-  if (is_null($jquery_path)) {
-    $jquery_path = jquery_update_jquery_path();
-  }
+  if (variable_get('use_google', 0) == 1) {
+    $version = variable_get('jquery_version', GAL_API_VERSION_DEFAULT);
+  } else {
+    $pattern = '# * jQuery JavaScript Library v([0-9\.a-z]+)#';
 
-  // Return the version provided by jQuery Update.
-  $jquery = file_get_contents($jquery_path);
-  if (preg_match($pattern, $jquery, $matches)) {
-    $version = $matches[1];
+    // No file is passed in so default to the file included with this module.
+    if (is_null($jquery_path)) {
+      $jquery_path = jquery_update_jquery_path();
+    }
+  
+    // Return the version provided by jQuery Update.
+    $jquery = file_get_contents($jquery_path);
+    if (preg_match($pattern, $jquery, $matches)) {
+      $version = $matches[1];
+    }
   }
 
   return $version;
@@ -153,6 +186,43 @@
     '#default_value' => variable_get('jquery_update_compression_type', 'min'),
   );
 
+  $form['google_api'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Google AJAX Libraries API',
+    '#description' => t('By default, jQuery Update serves a local copy of the updated jquery.js file; however, it can optionally use the <a href="google_ajax">Google AJAX Libraries API</a> instead.', array('@google_ajax' => 'http://code.google.com/apis/ajaxlibs/')),
+  );
+  $form['google_api']['use_google'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use the Google AJAX Libraries API to load jQuery.'),
+    '#default_value' => variable_get('use_google', 0),
+  );
+  
+  //field should ideally be disabled by default until $use_google is checked (but that requires issue #227966 to be fixed)
+  $form['google_api']['jquery_version'] = array(
+    '#type' => 'select',
+    '#title' => t('jQuery Version'),
+    '#default_value' => variable_get('jquery_version', GAL_API_VERSION_DEFAULT),
+    '#description' => t('Specify the version of jQuery to load. See the Google AJAX Libraries API Developer\'s Guide for <a href="@supported-versions">supported versions</a>.', array('@supported-versions' => 'http://code.google.com/apis/ajaxlibs/documentation/#jquery')),
+    '#options' => array('1.2.3'=>'1.2.3', '1.2.6'=>'1.2.6', '1.3.0'=>'1.3.0', '1.3.1'=>'1.3.1', '1.3.2'=>'1.3.2'),
+    '#required' => TRUE,
+  );
+  
+  $form['google_api']['use_google_ui'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use the Google AJAX Libraries API to load jQuery UI.'),
+    '#default_value' => variable_get('use_google', 0),
+  );
+  
+  //field should ideally be disabled by default until $use_google is checked (but that requires issue #227966 to be fixed)
+  $form['google_api']['jquery_ui_version'] = array(
+    '#type' => 'select',
+    '#title' => t('jQuery UI Version'),
+    '#default_value' => variable_get('jquery_ui_version', GAL_API_UI_VERSION_DEFAULT),
+    '#description' => t('Specify the version of jQuery to load. See the Google AJAX Libraries API Developer\'s Guide for <a href="@supported-versions">supported versions</a>.', array('@supported-versions' => 'http://code.google.com/apis/ajaxlibs/documentation/#jqueryUI')),
+    '#options' => array('1.5.2'=>'1.5.2', '1.5.3'=>'1.5.3', '1.6'=>'1.6', '1.7.0'=>'1.7.0', '1.7.1'=>'1.7.1', '1.7.2'=>'1.7.2'),
+    '#required' => TRUE,
+  );
+
   return system_settings_form($form);
 }
 
