diff --git a/absolute_messages.js b/absolute_messages.js
index 10af7a5..ccf1c5a 100644
--- a/absolute_messages.js
+++ b/absolute_messages.js
@@ -2,8 +2,20 @@ Drupal.absolute_messages = Drupal.absolute_messages || {};
 
 (function ($) {
 
-  Drupal.absolute_messages.initialize = function(){
+  /**
+   * Attaches absolute messages behavior.
+   */
+  Drupal.behaviors.absoluteMessages = {
+    attach: function (context, settings) {
+      $('body', context).once('absolute-messages', function () {
+        Drupal.absolute_messages.initialize(settings.absolute_messages);
+      }); 
+    }
+  };
 
+  Drupal.absolute_messages.initialize = function(settings){
+    $.extend(Drupal.absolute_messages, settings);
+    
     Drupal.absolute_messages.timeouts = new Array();
     if ($("#absolute-messages-messages").length > 0) {
       // Move messages from closure to right after opening of body tag.
@@ -220,9 +232,5 @@ Drupal.absolute_messages = Drupal.absolute_messages || {};
       Drupal.absolute_messages.checkIcons();
     });
   };
-  
-  $(document).ready(function(){
-    Drupal.absolute_messages.initialize();
-  });
 
 })(jQuery);
diff --git a/absolute_messages.module b/absolute_messages.module
index 495a7ac..b04d4d1 100644
--- a/absolute_messages.module
+++ b/absolute_messages.module
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Module displaying system messages in colored horizontal bars on top 
+ * Module displaying system messages in colored horizontal bars on top
  * of the page, similar to Stack Overflow / Stack Exchange network notifications.
  */
 
@@ -64,9 +64,7 @@ function absolute_messages_init() {
     $settings['max_lines'] = $max_lines;
   }
   // Pass configuration to JS.
-  drupal_add_js(strtr('jQuery.extend(Drupal.absolute_messages, !settings);', array(
-    '!settings' => drupal_json_encode($settings),
-  )), 'inline');
+  drupal_add_js(array('absolute_messages' => $settings), 'setting');
 
 }
 
@@ -137,7 +135,7 @@ function theme_absolute_messages($variables) {
   // Provide hook_messages_alter($messages) to other modules.
   // Allows modules to update messages before they are displayed.
   drupal_alter('messages', $all_messages);
-  
+
   // Theme all messages for output.
   $output = '';
   $total_messages = 0;
