diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 3fc155a..38b5eee 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,9 @@
+2011-11 dozymoe
+Removed support for jq and jqp contrib, not available in D7.
+Added dependence on libraries contrib.
+Convert CCK field widget implementation to D7 core field.
+Added package description.
+
 2010-05 dman
 Total rewrite - added real CCK field support so it does what it promises.
 Module now provides a CCK text field widget that uses freebase suggest.
diff --git a/README.txt b/README.txt
index 5f9542f..e545544 100644
--- a/README.txt
+++ b/README.txt
@@ -1,172 +1,87 @@
 
 === JQuery Freebase ===
 
-Original Author 2008 : Thomas Bonte <www.thomasbonte.net>
-Updated to do something in 2010 by : Dan Morrison (dman) <dan@coders.co.nz>
++   Original Author 2008 : Thomas Bonte <http://www.thomasbonte.net>
++   Updated to do something in 2010 by : Dan Morrison (dman) <dan@coders.co.nz>
++   Ported from Drupal 6 in 2011 : Fahri Reza <http://drupal.org/user/824484>
 
-Description
-===========
 
-Adds the Freebase Suggest JQuery plugin functionality to your Drupal website.
+## Description ##
 
-Adds autocomplete suggestions to CCK textfields based on topic sets 
-from the Freebase database.
++   Provides Drupal integration with Freebase Suggest javascript library.
++   Adds autocomplete suggestions to Drupal's Text Field, which based on topic sets
+    from the Freebase database.
 
-Requirements
-============
 
-[jquery_update.module](http://drupal.org/project/jquery_update)
+## Requirements ##
 
-jquery.freebase.suggest library files from 
-[Freebase Suggest project](http://www.freebase.com/docs/suggest)
+Freebase Suggest javascript library files from 
+[Freebase Suggest project](http://www.freebase.com/docs/suggest).
 
-Optional modules
-----------------
 
-For quick UI improvements:
-[Content Creation Kit](http://drupal.org/project/cck)
+## Installation ##
 
-For developers only
-[jQ](http://drupal.org/project/jq)
-[jQuery Plugin Handler](http://drupal.org/project/jqp)
+1.  Install 'jquery_freebase' module directory in to your Drupal 
+    sites/all/modules directory as usual.
 
-
-Installation
-============
-
-1.  Copy the 'jquery_freebase' module directory in to your Drupal 
-    sites/all/modules directory as usual
-
-2.  Check the 
+2.  Check the
     [freebase suggest project page](http://www.freebase.com/docs/suggest)
     for the latest versions of the freebase suggest library files.
-    At the time of writing, the version is 1.2.1, so:
-    Download 
-      http://freebaselibs.com/static/suggest/1.2.1/suggest.min.css
-      http://freebaselibs.com/static/suggest/1.2.1/suggest.min.js
-    to the Drupal 'sites/all/libraries' directory into a new folder called 
-    'freebase_suggest'.
-    (Make a 'libraries' folder if it doesn't exist)
-    
-    ~
-      mkdir sites/all/libraries/freebase_suggest
-      cd sites/all/libraries/freebase_suggest
-      wget  http://freebaselibs.com/static/suggest/1.2.1/suggest.min.css
-      wget http://freebaselibs.com/static/suggest/1.2.1/suggest.min.js    
-    ~
-    
-3.  Save them so they are available as 
-      sites/all/libraries/freebase_suggest/suggest.min.js
-      sites/all/libraries/freebase_suggest/suggest.min.css
+    At the time of writing, the version is 1.3.
     
+    Download:
+    +   <http://freebaselibs.com/static/suggest/1.3/suggest.min.css>
+    +   <http://freebaselibs.com/static/suggest/1.3/suggest.min.js>
+
+    Save them so they are available as: 
+    +   sites/all/libraries/freebase_suggest/suggest.min.js
+    +   sites/all/libraries/freebase_suggest/suggest.min.css
+
     Placing the files in this folder will make them compatible with 
-    [Libraries API](http://drupal.org/project/libraries) and the Drupal7
-    [hook_library](http://api.drupal.org/api/function/hook_library/7)
-   
-4.  If the freebase libs require a higher jquery version than your Drupal
-    is currently using, you may need to install
-    a version of 
-    [jQuery Update](http://drupal.org/project/jquery_update)
-    Current version of suggest (1.2.1) uses jquery (1.3.2) so an install
-    of jQuery Update 6.x-2.x was needed.
-
-5.  Enable jquery_freebase under admin/build/modules
-
-6.  If you CHECK YOUR SITE STATUS REPORT at /admin/reports/status
+    [Libraries API](http://drupal.org/project/libraries)
+    and the Drupal 7
+    [hook_library](http://api.drupal.org/api/function/hook_library/7).
+
+3.  Enable jquery_freebase under admin/build/modules.
+
+4.  If you CHECK YOUR SITE STATUS REPORT at /admin/reports/status
     it will confirm if the libraries are loaded properly.
-    Important: Confirm that jquery is at version 1.3.2 or higher.
-
-Usage
-=====
-
-To see this feature in action, visit the content type - manage fields.
-When adding a new [text] field (or modifying existing ones) there will be
-a new widget option "Text Field with autocomplete suggestions".
-Select that for the field.
-
-When adding such a text field to a content type, you can then add parameters
-to be used by the freebase suggest API. This is used to limit the TYPE
-of suggestion that is returned. For details, see 
-[the freebase API documentation](http://www.freebase.com/docs/suggest)
-
-Autocomplete Arguments of
-{type:'/people/person'}
-would return only suggestions of type 'person'. Include the {} braces.
-
-Once configured, editing that field on the content edit form should provide
-Freebase suggestions, prompts and topic summaries when the text field is 
-focused.
-
-Optional
-========
-
-As well as the CCK field support, 
-This module exposes the 'freebase suggest' library files as plugins 
-through jq.module (deprecated) and jqp.module 
-[jQ](http://drupal.org/project/jq)
-[jQuery Plugin Handler](http://drupal.org/project/jqp)
-
-Use of these libraries requires some code of your own to make use of it.
-Where you place the code will depend on the use-case, but in your own
-form-building (FAPI) or form_alter() function of your own module would
-be a good start.
-
-JQ Usage
---------
-
-jq.module is a jquery library handler. 
-This module makes its libraries accessible through its handler.
-Optionally download that module and see its docs.
-
-Example code: (suggest version 1.2.1)
-<pre>
-jq_add('freebase_suggest');
-drupal_add_js(
-  "$(document).ready(function() {
-     $('#edit-artist').suggest( {type:'/music/artist'} );
-     $('#edit-track').suggest( {type:'/music/track'} );
-   });
-  ",
-  'inline'
-);
-</pre>
-
-JQP Usage
----------
-
-jq.module is another, more modern jquery library handler
-This module makes its libraries accessible through its handler.
-Optionally download that module and see its docs.
-http://drupal.org/project/jq
-
-Example code: (suggest version 1.2.1)
-<pre>
-drupal_add_library('freebase_suggest');
-drupal_add_js(
-  "$(document).ready(function() {
-     $('#edit-artist').suggest( {type:'/music/artist'} );
-     $('#edit-track').suggest( {type:'/music/track'} );
-   });
-  ",
-  'inline'
-);
-</pre>
-
-
-Troubleshooting
-=======
-If you get 'Searching' but no result, or the browser error
-"Uncaught TypeError: Object function ... has no method 'isArray'"
-This means you do not have the correct version of jquery. 
-Check that Jquery Update is correctly installed!
-You NEED jquery_update-6.x-2.x not jquery_update-6.x-1.x
-This means we get jquery.js 1.3.2
-
-Support
-=======
-
-Official Drupal project page
-http://drupal.org/project/jquery_freebase
-
-File a bug or support request at 
-http://drupal.org/project/issues/jquery_freebase
\ No newline at end of file
+
+
+## Usage ##
+
+To see this feature in action:
+
+1.  Visit the content type - manage fields.
+    For example /admin/structure/types/manage/article/fields in Drupal 7.
+
+2.  When adding a new __Text__ Field (or modifying existing ones) there will be:
+
+3.  __Autocomplete text widget (from freebase)__ Widget. This is the widget provided
+    by this module.
+
+4.  When adding such a text field to a content type, you can then add parameters
+    to be used by the freebase suggest API. This is used to limit the TYPE
+    of suggestion that is returned. For details, see 
+    [the freebase API documentation](http://www.freebase.com/docs/suggest).
+
+    Autocomplete arguments of {type:'/people/person'} would return only suggestions
+    of type 'person'.
+    __Include the {} braces__.
+
+5.  Once configured, editing that field on the content edit form should provide
+    Freebase suggestions, prompts and topic summaries when the text field is 
+    focused.
+
+
+## Troubleshooting ##
+
+Um.. :S
+
+## Support ##
+
++   Official Drupal project page
+    <http://drupal.org/project/jquery_freebase>
+
++   File a bug or support request at 
+    <http://drupal.org/project/issues/jquery_freebase>
diff --git a/jquery_freebase.info b/jquery_freebase.info
index 55bb297..8badc2d 100644
--- a/jquery_freebase.info
+++ b/jquery_freebase.info
@@ -1,6 +1,6 @@
 name = jQuery Freebase
 description = Enables the Freebase jQuery plugin that provides autocomplete suggestions for text fields
+package = Freebase
+core = 7.x
 
-dependencies[] = jquery_update
-
-core = 6.x
\ No newline at end of file
+dependencies[] = libraries
diff --git a/jquery_freebase.install b/jquery_freebase.install
new file mode 100644
index 0000000..c1b0f70
--- /dev/null
+++ b/jquery_freebase.install
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the jquery_freebase module.
+ */
+
+/**
+ * Implements hook_requirements().
+ */
+function jquery_freebase_requirements($phase) {
+  $requirements = array();
+  $t = get_t();
+
+  if ($phase == 'runtime') {
+    // Check library availability.
+    if (($library = libraries_detect('freebase_suggest')) && !empty($library['installed'])) {
+      $path = $library['library path'];
+      $version = $library['version'];
+
+      $requirements['freebase_suggest'] = array(
+        'title' => $t('Freebase Suggest javascript library'),
+        'value' => $t(
+          '@version (<em>@path</em>)',
+          array('@path' => $path, '@version' => $version)
+        ),
+      );
+    }
+    else {
+      $requirements['freebase_suggest'] = array(
+        'title' => $t('Freebase Suggest javascript library'),
+        'value' => $t('Missing files'),
+        'severity' => REQUIREMENT_ERROR,
+        'description' => $t(
+          'See the README.txt file that comes with jquery_freebase module package, or <a href="@help_url">help</a> for install instructions.',
+          array('@help_url' => url('admin/help/jquery_freebase')
+          )
+        ),
+      );
+    }
+  }
+
+  return $requirements;
+}
diff --git a/jquery_freebase.js b/jquery_freebase.js
new file mode 100644
index 0000000..8d5088e
--- /dev/null
+++ b/jquery_freebase.js
@@ -0,0 +1,13 @@
+Drupal.behaviors.jquery_freebase = {
+  attach: function (context, settings) {
+    var $ = jQuery;
+    var jf = Drupal.settings.jquery_freebase;
+
+    if (jf && jf.elements) {
+      for (var ii=0; ii<jf.elements.length; ii++) {
+        var elem = jf.elements[ii];
+        $(elem.id, context).suggest(elem.arguments);
+      }
+    }
+  }
+};
diff --git a/jquery_freebase.make b/jquery_freebase.make
index 6045757..7e0ffd5 100644
--- a/jquery_freebase.make
+++ b/jquery_freebase.make
@@ -1,14 +1,12 @@
-; $Id$
-
-core = 6.x
+core = 7.x
 
 libraries[freebase_suggest_css][download][type] = "get"
-libraries[freebase_suggest_css][download][url] = "http://freebaselibs.com/static/suggest/1.2.1/suggest.min.css"
+libraries[freebase_suggest_css][download][url] = "http://freebaselibs.com/static/suggest/1.3/suggest.min.css"
 libraries[freebase_suggest_css][directory_name] = "freebase_suggest"
 libraries[freebase_suggest_css][destination] = "libraries"
 
 libraries[freebase_suggest_js][download][type] = "get"
-libraries[freebase_suggest_js][download][url] = "http://freebaselibs.com/static/suggest/1.2.1/suggest.min.js"
+libraries[freebase_suggest_js][download][url] = "http://freebaselibs.com/static/suggest/1.3/suggest.min.js"
 libraries[freebase_suggest_js][directory_name] = "freebase_suggest"
 libraries[freebase_suggest_js][destination] = "libraries"
 
diff --git a/jquery_freebase.module b/jquery_freebase.module
index 2475f53..1ef6c3a 100644
--- a/jquery_freebase.module
+++ b/jquery_freebase.module
@@ -1,11 +1,18 @@
 <?php
 
-#define('JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH', drupal_get_path('module', 'jquery_freebase') . '/freebase_suggest');
-define('JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH', 'sites/all/libraries/freebase_suggest');
+/**
+ * @file
+ * Provides drupal integration to freebase_suggest javascript library.
+ *
+ * There are 2 (two) ways to use the freebase library:
+ * - textfield widget (field module from drupal)
+ * - using Form API, see jquery_freebase_attach_autocomplete_suggest()
+ */
 
+define('JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH', 'sites/all/libraries/freebase_suggest');
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function jquery_freebase_help($path, $arg) {
   switch ($path) {
@@ -13,289 +20,156 @@ function jquery_freebase_help($path, $arg) {
       return t('Adds autocomplete suggestions to CCK textfields based on topic sets from the Freebase database.');
     case 'admin/help#jquery_freebase':
       $readme = file_get_contents(drupal_get_path('module', 'jquery_freebase') . '/README.txt');
-      $readme = filter_filter('process' , 1, 0, $readme); // newlines
-      $readme = filter_filter('process' , 2, 0, $readme); // urls
-      // Create instructions to run.
-      $fix_script = "";
-      $realpath = realpath('.') . '/'. JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH;
-      if (! is_readable(dirname($realpath))) {
-        $fix_script .= "mkdir '" . dirname($realpath) . "' ;\n";
+      if (module_exists('markdown')) {
+        $readme = _filter_markdown($readme, NULL);
       }
-      if (! is_readable($realpath)) {
-        $fix_script .= "mkdir '$realpath' ; \n";
+      else {
+        $readme = check_markup($readme);
       }
-      $fix_script .= "wget -P '$realpath' http://freebaselibs.com/static/suggest/1.2.1/suggest.min.js ;\n";
-      $fix_script .= "wget -P '$realpath' http://freebaselibs.com/static/suggest/1.2.1/suggest.min.css ;\n";
-      $readme .= "<h3>Suggested commands to run to install: </h3><pre>$fix_script</pre>";
       return $readme;
   }
 }
 
 /**
- * Implementation of hook_requirements().
- */
-function jquery_freebase_requirements($phase) {
-  $requirements = array();
-  $t = get_t();
-  
-  if ($phase == 'runtime') {
-    // Check library availability
-    if (is_readable(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.js')) {
-      $requirements['freebase_suggest'] = array(
-        'title' => $t('jQuery Freebase Suggest'),
-        'value' => $t(
-          'Freebase Suggest library is available in !library_folder', 
-          array('!library_folder' => JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH)
-        )
-      );
-    }
-    else {
-      $requirements['freebase_suggest'] = array(
-        'title' => $t('jQuery Freebase Suggest'),
-        'value' => $t('Freebase Suggest library is not available in !library_folder', array('!library_folder' => JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH)),
-        'severity' => REQUIREMENT_ERROR,
-        'description' => $t('
-          See the README or <a href="@help_url">help</a> for install instructions. 
-          Download the required libraries from 
-          <a href="@freebase_url">the freebase project</a>.', 
-          array(
-            '@freebase_url' => 'http://www.freebase.com/docs/suggest',
-            '@help_url' => url('admin/help/jquery_freebase'),
-          )
-        ),
-      );
-    }
-  }
-
-  return $requirements;
-}
-
-
-/**
- * Implementation of hook_jq() library manager
- * 
- * Support for the (rare) jq.module
- * 
+ * Implements hook_libraries_info().
  */
-function jquery_freebase_jq($op, $plugin = NULL) {
-  switch ($op) {
-    case 'info':
-      return array(
-        'freebase_suggest' => array(
-          'name' => 'Freebase Suggest',
-          'description' => t('This is the Freebase jQuery plugin. It can enhance your forms.'),
-            'version' => 'suggest 1.2.1 // 2009 // jQuery 1.3.2',
-            'url' => 'http://www.freebase.com/docs/suggest',
-          'files' => array(
-            'js' => array(
-              JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.js',
-            ),
-          ),
-        ),
-      );
-    case 'add':
-      // any additional processing required when adding a plugin to a page.
-      switch ($plugin) {
-        case 'freebase_suggest':
-          drupal_add_css(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.css');
-          break;
-      }
-    break;
-  }
-}
-
-/**
- * Implementation of hook_jqp() library manager.
- * 
- * http://drupal.org/project/jqp
- * Declare the files we publish, for management through the jqp IU.
- */
-function jquery_freebase_jqp() {
+function jquery_freebase_libraries_info() {
   $libraries['freebase_suggest'] = array(
-    'name' => 'Freebase Suggest',
-    'description' => 'Provides Autocomplete suggestions from Freebase topics.',
-    'project_url' => 'http://www.freebase.com/docs/suggest',
-    'scripts' => array(
-      array(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.js'), // This will have key 0, so it is the default version
-      '1.2.1' => array(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.js'),
-      '1.2.1-dev' => array(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.js'),
+    'title' => 'Freebase Suggest jQuery Library',
+    'vendor url' => 'http://www.freebase.com',
+    'download url' => 'http://www.freebase.com/docs/suggest',
+    'version arguments' => array(
+      'file' => 'suggest.min.js',
+      'lines' => 2000,
+      'pattern' => "/jQuery\.suggest\.version='Version:(.*?)';/",
     ),
-    'stylesheets' => array(
-      array(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.css'),
-      '1.2.1' => array(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.css'),
-      '1.2.1-dev' => array(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.css'),
+    'files' => array(
+      'css' => array(
+        'suggest.min.css' => array(
+          'type' => 'file',
+          'media' => 'screen',
+        ),
+      ),
+      'js' => array(
+        'suggest.min.js' => array(),
+      ),
     ),
   );
-  return $libraries;
-}
 
-/**
- * Implementation of hook_library()
- * 
- * http://api.drupal.org/api/function/hook_library/7
- */
-function jquery_freebase_library() {
+  return $libraries;
 }
 
-
 /**
- * Load the javascript libraries if needed.
- * 
- * This can be called directly by any module or function that wants to use the
- * suggest function.
- * This is for when NONE of the (currently unstable) library managers are
- * running.
+ * Loads freebase-suggest 3rd party library files.
  */
-function jquery_freebase_add_scripts() {
-  // The important additions are the javascript and jquery lines here.
-  static $scripts_added;
-  if (empty($scripts_added)) {
-    #drupal_add_js(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.js', 'module');
-    drupal_add_js(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.js', 'module');
-    drupal_add_css(JQUERY_FREEBASE_SUGGEST_LIBRARY_PATH . '/suggest.min.css');
-    $scripts_added = TRUE;
-  }
+function jquery_freebase_load_library() {
+  $library = libraries_load('freebase_suggest');
 }
 
 /**
- * Implimentation of hook_widget_info() for CCK
- * 
+ * Implements hook_field_widget_info().
+ *
  * Declare that we provide an alternative widget for text fields.
  */
-function jquery_freebase_widget_info() {
+function jquery_freebase_field_widget_info() {
   return array(
     'jquery_freebase_autocomplete' => array(
-      'label' => t('Text field with autocomplete suggestions from freebase'),
+      'label' => t('Autocomplete text widget (from freebase)'),
       'field types' => array('text'),
-      'multiple values' => CONTENT_HANDLE_CORE,
-      'callbacks' => array(
-        'default value' => CONTENT_CALLBACK_DEFAULT,
+      'settings' => array(
+        'autocomplete_arguments' => '',
+      ),
+     'behaviors' => array(
+        'multiple values' => FIELD_BEHAVIOR_DEFAULT,
+        'default value' => FIELD_BEHAVIOR_DEFAULT,
       ),
     ),
   );
 }
 
 /**
- * Implimentation of hook_widget_settings() for CCK
- * 
+ * Implements hook_field_widget_settings_form().
+ *
  * Additions to the "Manage Field" screen under content types. Configures
  * specific settings for this field instance.
- * 
+ *
  * Edit and save the 'autocomplete_arguments' parameter.
  */
-function jquery_freebase_widget_settings($op, $widget) {
-  switch ($op) {
-    case 'form':
-      $form = array();
-      $autocomplete_arguments = isset($widget['autocomplete_arguments']) ? $widget['autocomplete_arguments'] : '';
-      if ($widget['type'] == 'jquery_freebase_autocomplete') {
-        $form['autocomplete_arguments'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Autocomplete arguments'),
-          '#default_value' => $autocomplete_arguments,
-          '#description' => t('
-            Enter some instructions for filtering the freebase results, 
-            as per the <a href="http://www.freebase.com/docs/suggest">documentation</a>. 
-            This will restrict the results from freebase that the autocomplete 
-            search will return. 
-            Must be in Freebase topic type notation (JSON), 
-            eg <code>{"type":"/location/country"}</code> 
-            or <code>{"type":"/people/person"}</code>
-            , <code>{"type":["/film/production_company", "/book/publishing_company"]}</code>. 
-          '),
-        );
-      }
-      else {
-        $form['autocomplete_arguments'] = array(
-          '#type' => 'hidden', 
-          '#value' => $autocomplete_arguments
-        );
-      }
-      return $form;
+function jquery_freebase_field_widget_settings_form($field, $instance) {
+  $widget = $instance['widget'];
+  $settings = $widget['settings'];
+
+  $form['autocomplete_arguments'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Autocomplete arguments'),
+    '#default_value' => $settings['autocomplete_arguments'],
+    '#description' => t('
+       Enter some instructions for filtering the freebase results,
+       as per the <a href="http://www.freebase.com/docs/suggest">documentation</a>.
+       This will restrict the results from freebase that the autocomplete
+       search will return.
+       Must be in Freebase topic type notation (JSON),
+       eg <code>{"type":"/location/country"}</code>
+       or <code>{"type":"/people/person"}</code>
+       , <code>{"type":["/film/production_company", "/book/publishing_company"]}</code>.
+    '),
+  );
 
-    case 'save':
-      return array('autocomplete_arguments');
-  }
+  return $form;
 }
 
 /**
- * Implimentation of hook_widget() for CCK
- * 
- * Defines how the data entry field on node edit forms works.
- * 
+ * Implements hook_field_widget_form().
+ *
+ * Defines how the data-entry field on node edit-forms works.
+ *
  * It's MOSTLY like a textfield, just with a bit of extra javascript when it
  * gets rendered.
  */
-function jquery_freebase_widget(&$form, &$form_state, $field, $items, $delta = 0) {
-  switch ($field['widget']['type']) {
-    case 'jquery_freebase_autocomplete':
-      $element = array(
-        '#type' => 'text_textfield',
-        '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
-        '#process' => array('jquery_freebase_textfield_process_wrapper'),
-      );
-      break;
-  }
+function jquery_freebase_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
+  $widget = $instance['widget'];
+  $settings = $widget['settings'];
+
+  $element_info = element_info('textfield');
+  $element += array(
+    '#type' => 'textfield',
+    '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
+    '#process' => array_merge($element_info['#process'], array('jquery_freebase_attach_autocomplete_suggest')),
+    '#freebase_suggest_arguments' => $settings['autocomplete_arguments'],
+  );
+
   return $element;
 }
 
 /**
- * Add the js additions to an otherwise normal textfield.
- * 
- * Callback from jquery_freebase_widget(), the real widget renderer for CCK
- * 
- * Prepares the data entry field on node edit forms as a FAPI element
- * 
- * Based on example from noderefcreate_autocomplete_process()
+ * A form #process callback.
+ * Adding a #process attribute to your form elements will make this happen.
+ *
+ * Invoke this when making a FAPI form element by adding:
+ * $form['fieldname'] = array(
+ *   '#type' => 'textfield',
+ *   '#process' => array('jquery_freebase_attach_autocomplete_suggest'),
+ *   '#freebase_suggest_arguments' => "{'type': '/freebase/type_profile'}"
+ * )
+ *
+ * Or in a hook_form_alter():
+ * $form['fieldname']['#process'][] = 'jquery_freebase_attach_autocomplete_suggest';
+ * $form['fieldname']['#freebase_suggest_arguments'] = "{'type': '/freebase/type_profile'}";
  */
-function jquery_freebase_textfield_process_wrapper($element, $edit, $form_state, $form) {
-  // Really, avoid doing any more than we have to.
-  // Just use the textfield routine to do all the weird work.
-  $element = text_textfield_process($element, $edit, $form_state, $form);
-
-  jquery_freebase_add_scripts();
+function jquery_freebase_attach_autocomplete_suggest($element, $form_state) {
+  $element_id = $element['#id'];
+  $search_arguments = $element['#freebase_suggest_arguments'];
+  $settings['jquery_freebase']['elements'][] = array(
+    'id' => "#{$element_id}",
+    'arguments' => $search_arguments,
+  );
 
-  // Add js to invoke the jquery attachment on this element
-  $element_id = $element['#id'] . "-value";
-  $field = $form['#field_info'][$element['#field_name']];
-  $widget = $field['widget'];
-  $search_arguments = $widget['autocomplete_arguments'];
-  $attachment_script = "
-    Drupal.behaviors.freebase_autocomplete = function (context) {
-      $('#{$element_id}').suggest($search_arguments);
-    }
-  ";
-  drupal_add_js($attachment_script, 'inline');
-  // js is now added.
+  // Display UI hint that this element has autocomplete.
+  $element['#attributes']['class'][] = 'form-autocomplete';
 
-  return $element;
-}
-/**
- * A form #process callback
- * 
- * Adding a #process attribute to your form elements will make this happen
- */
-function jquery_freebase_attach_autocomplete_suggest($element, $edit, $form_state, $form) {
- /* 
-    Invoke this when making a FAPI form element by adding:
-    $form['fieldname'] = array(   
-      '#type' => 'textfield',
-      '#process' => array('jquery_freebase_attach_autocomplete_suggest'),
-      '#freebase_suggest_arguments' => "{'type': '/freebase/type_profile'}"
-    )
-    
-  */
+  jquery_freebase_load_library();
+  drupal_add_js(drupal_get_path('module', 'jquery_freebase') . '/jquery_freebase.js');
+  drupal_add_js($settings, 'setting');
 
-  // Add js to invoke the jquery attachment on this element
-  $element_id = $element['#id'];
-  $search_arguments = $element['#freebase_suggest_arguments'];
-  $attachment_script = "
-    Drupal.behaviors.freebase_autocomplete = function (context) {
-      $('#{$element_id}').suggest($search_arguments);
-    }
-  ";
-  jquery_freebase_add_scripts();
-  drupal_add_js($attachment_script, 'inline');
-  // js is now added.
   return $element;
 }
