diff --git a/autologout.js b/autologout.js
index b33da3f..03e693f 100644
--- a/autologout.js
+++ b/autologout.js
@@ -6,8 +6,24 @@ Drupal.behaviors.autologout = function (context) {
   
   function init() {
     if (Drupal.settings.autologout.jquery_ui) {
-      dialog();
-      paddingTimer = setTimeout(logout, Drupal.settings.autologout.timeout_padding);
+      theDialog = dialog();
+      paddingTimer = setTimeout(confirmLogout, Drupal.settings.autologout.timeout_padding);
+
+      // While the countdown timer is going, lookup the remaining time. If there
+      // is more time remaining (i.e. a user is navigating in another tab), then
+      // close the dialog and reset the timer for opening the dialog again.
+      $.ajax({
+        url : Drupal.settings.basePath + 'autologout_ajax_get_time_left',
+        dataType: 'json',
+        success: function(data) {
+          window.console.log(data.time);
+          if(data.time > 0) {
+            clearTimeout(paddingTimer);
+            $(theDialog).dialog('destroy');
+            t = setTimeout(init, data.time);
+          }
+        }
+      });
     } else {
       if (confirm(Drupal.settings.autologout.message) ) {
         refresh();    
@@ -18,7 +34,7 @@ Drupal.behaviors.autologout = function (context) {
   }
   
   function dialog() {
-    $('<div> ' +  Drupal.settings.autologout.message + '</div>').dialog({
+    return $('<div> ' +  Drupal.settings.autologout.message + '</div>').dialog({
       modal: true,
       closeOnEscape: false,
       width: 'auto',
@@ -53,6 +69,26 @@ Drupal.behaviors.autologout = function (context) {
     });
   }
   
+  // A user could have used the reset button on the tab/window they're actively
+  // using, so we need to double check before actually logging out.
+  function confirmLogout() {
+    $(theDialog).dialog('destroy');
+    $.ajax({
+      url : Drupal.settings.basePath + 'autologout_ajax_get_time_left',
+      dataType: 'json',
+      error: logout,
+      success: function(data) {
+        window.console.log(data.time);
+        if(data.time > 0) {
+          t = setTimeout(init, data.time);
+        }
+        else {
+          logout();
+        }
+      }
+    });
+  }
+
   function logout() {
     $.ajax({
       url: Drupal.settings.basePath + 'autologout_ahah_logout',
diff --git a/autologout.module b/autologout.module
index b060931..e63291a 100644
--- a/autologout.module
+++ b/autologout.module
@@ -40,6 +40,12 @@ function autologout_menu() {
     'access callback' => '_autologout_access_ahah',
     'type' => MENU_CALLBACK
   );
+  $items['autologout_ajax_get_time_left'] = array(
+    'title' => 'JS Logout AJAX Get Time Until Logout',
+    'page callback' => 'autologout_ahah_get_remaining_time',
+    'access callback' => '_autologout_access_ahah',
+    'type' => MENU_CALLBACK
+  );
   
   return $items;
 }
@@ -67,6 +73,14 @@ function autologout_help($path, $arg) {
  */
 function autologout_init() {
   global $user;
+
+  // The AJAX callbacks should not influence the time until a user is logged
+  // out, nor is the the JS inclusion necessary.
+  $ajax_callbacks = array('autologout_ahah_logout', 'autologout_ahah_set_last', 'autologout_ajax_get_time_left');
+  if (in_array($_GET['q'], $ajax_callbacks)) {
+    return;
+  }
+
   if ($user->uid && _autologout_logout_role($user)) {
     // should we be enforcing on admin pages?
     if (arg(0) == 'admin' && !variable_get('autologout_enforce_admin', FALSE)) {
@@ -164,3 +178,12 @@ function _autologout_logout_role($user) {
   
   return FALSE;
 }
+
+/**
+ * AJAX callback that returns the time remaining for this user is logged out.
+ */
+function autologout_ahah_get_remaining_time() {
+  $timeout = variable_get('autologout_timeout', 1800);
+  $time_passed = time() - $_SESSION['autologout_last'];
+  drupal_json(array('time' => (($timeout - $time_passed) * 1000)));
+}
\ No newline at end of file
