 cookiecontrol.module | 42 +++++++++++++++++-------------------------
 js/cookiecontrol.js  | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 25 deletions(-)

diff --git a/cookiecontrol.module b/cookiecontrol.module
index 21cad08..661d0aa 100644
--- a/cookiecontrol.module
+++ b/cookiecontrol.module
@@ -82,36 +82,28 @@ function cookiecontrol_preprocess_html(&$variables) {
     $cookiecontrol_cookiename = cookiecontrol_generatesitecookie();
     $cookiecontrol_consentmodel = variable_get('cookiecontrol_consentmodel', 'information_only');
   
-    $cookiecontrol_settings = "
-    jQuery(document).ready(function($) {
-    cookieControl({
-        introText: '{$cookiecontrol_text}',
-        fullText: '{$cookiecontrol_fulltext}',
-        theme: '{$cookiecontrol_theme}',
-        html: '{$cookiecontrol_html}',
-        position: '{$cookiecontrol_position}',
-        shape: '{$cookiecontrol_shape}',
-        startOpen: {$cookiecontrol_startopen},
-        autoHide: {$cookiecontrol_timeout},
-        onAccept: function(cc){cookiecontrol_accepted(cc)},
-        onReady: function(){},
-        onCookiesAllowed: function(cc){cookiecontrol_cookiesallowed(cc)},
-        onCookiesNotAllowed: function(cc){cookiecontrol_cookiesnotallowed(cc)},
-        countries: '{$cookiecontrol_countries}',
-        subdomains: true,
-        cookieName: '{$cookiecontrol_cookiename}',
-        iconStatusCookieName: 'ccShowCookieIcon',
-        consentModel: '{$cookiecontrol_consentmodel}',
-        });
-      });
-    ";
-  
+    drupal_add_js(array(
+      'cookiecontrol' => array(
+        'introText'    => $cookiecontrol_text,
+        'fullText'     => $cookiecontrol_fulltext,
+        'theme'        => $cookiecontrol_theme,
+        'html'         => $cookiecontrol_html,
+        'position'     => $cookiecontrol_position,
+        'shape'        => $cookiecontrol_shape,
+        'startOpen'    => $cookiecontrol_startopen,
+        'autoHide'     => $cookiecontrol_timeout,
+        'countries'    => $cookiecontrol_countries,
+        'cookieName'   => $cookiecontrol_cookiename,
+        'consentModel' => $cookiecontrol_consentmodel,
+      )
+    ), 'setting');
+
     // If country restrictions are specified include the required plugin
     if ($cookiecontrol_countries) {
       drupal_add_js('https://ssl.geoplugin.net/javascript.gp', array('type' => 'external'));
     }
   
-    drupal_add_js($cookiecontrol_settings, array(
+    drupal_add_js(base_path() . drupal_get_path('module', 'cookiecontrol') . '/js/cookiecontrol.js', array(
       'type' => 'inline',
       'preprocess' => TRUE,
       'scope' => 'footer',
diff --git a/js/cookiecontrol.js b/js/cookiecontrol.js
new file mode 100644
index 0000000..100cdad
--- /dev/null
+++ b/js/cookiecontrol.js
@@ -0,0 +1,39 @@
+/**
+ * Behaviors for the cookiecontrol module
+ * @file
+ */
+
+(function($) {
+/**
+ * Behavior for the cookiecontrol. Initializes the cookiecontrol baxed on the 
+ * settings in Drupal.settings.
+ */
+Drupal.behaviors.cookiecontrol = {
+  attach: function(context, settings) {
+    $(document.body).once('cookiecontrol', Drupal.behaviors.cookiecontrol.init);
+  },
+  init: function() {
+    if(Drupal.settings.cookiecontrol) {
+      cookieControl({
+        introText           : Drupal.settings.cookiecontrol.cookiecontrol_text,
+        fullText            : Drupal.settings.cookiecontrol.cookiecontrol_fulltext,
+        theme               : Drupal.settings.cookiecontrol.cookiecontrol_theme,
+        html                : Drupal.settings.cookiecontrol.cookiecontrol_html,
+        position            : Drupal.settings.cookiecontrol.cookiecontrol_position,
+        shape               : Drupal.settings.cookiecontrol.cookiecontrol_shape,
+        startOpen           : Drupal.settings.cookiecontrol.cookiecontrol_startopen,
+        autoHide            : Drupal.settings.cookiecontrol.cookiecontrol_timeout,
+        onAccept            : cookiecontrol_accepted(cc),
+        onReady             : function() { },
+        onCookiesAllowed    : cookiecontrol_cookiesallowed,
+        onCookiesNotAllowed : cookiecontrol_cookiesnotallowed(cc),
+        countries           : Drupal.settings.cookiecontrol.cookiecontrol_countries,
+        subdomains          : true,
+        cookieName          : Drupal.settings.cookiecontrol.cookiecontrol_cookiename,
+        iconStatusCookieName: 'ccShowCookieIcon',
+        consentModel        : Drupal.settings.cookiecontrol.cookiecontrol_consentmodel
+      });
+    }
+  }
+};
+})(jQuery);
\ No newline at end of file
