--- geoip.module	2011-01-24 16:47:25.000000000 -0500
+++ geoip.module.new	2011-02-18 12:53:32.000000000 -0500
@@ -18,11 +18,26 @@
     'access arguments' => array('administer site configuration'),
     'file' => 'geoip.admin.inc',
   );
-
+  $items['geoip/json/country'] = array(
+    'page callback' => 'geoip_json_country',
+    'page arguments' => array(3),
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
 /**
+ * Implementation of hook_init().
+ */
+function geoip_init() {
+  // Disable caching on JSON request.
+  if ($_GET['q'] == 'geoip/json/country') {  
+    $GLOBALS['conf']['cache'] = CACHE_DISABLED;
+  }
+}
+
+/**
  * Implementation of hook_requirements().
  */
 function geoip_requirements($phase) {
@@ -72,6 +87,31 @@
 }
 
 /**
+ * Helper function to include geoIP JSON scripts.
+ */
+function geoip_include_json() {
+  static $geoip_json_included;
+  if (!$geoip_json_included) {
+    $settings = array(
+      'debug' => $_GET['geoip_debug'] ? $_GET['geoip_debug'] : '', // If in debug mode, place the IP in settings.
+      'lifetime' => 1, // Lifetime of country cookie in days.
+    );  
+    
+    drupal_add_js(array('geoIP' => $settings), 'setting');
+    drupal_add_js(drupal_get_path('module', 'geoip') .'/geoip.js');
+    $geoip_json_included = TRUE;
+  }
+}
+
+/**
+ * Perform a country code lookup.
+ */
+function geoip_json_country($ip = NULL) {
+  print drupal_to_js(array('cc' => geoip_country_code($ip)));
+  exit();
+}
+
+/**
  * Singleton wrapper around geoip_open().
  */
 function geoip_instance() {
