diff --git a/recaptcha.js b/recaptcha.js
new file mode 100644
index 0000000..a7b2600
--- /dev/null
+++ b/recaptcha.js
@@ -0,0 +1,8 @@
+(function ($) {
+	Drupal.behaviors.recapcha = {
+		attach: function (context) {
+			Recaptcha.create(Drupal.settings.recaptcha.public_key, Drupal.settings.recaptcha.container, {theme: Drupal.settings.recaptcha.theme});
+		},
+		detach: function (context) {}
+	};
+}(jQuery));
diff --git a/recaptcha.module b/recaptcha.module
index 380fb46..53668b6 100644
--- a/recaptcha.module
+++ b/recaptcha.module
@@ -163,9 +163,9 @@ function recaptcha_captcha() {
             '#type' => 'item',
             '#markup' => '<div id="recaptcha_ajax_api_container">' . $html . '</div>',
           );
-          $js = "(function ($) { $(function() { Recaptcha.create('$recaptcha_public_key', 'recaptcha_ajax_api_container', {theme: '$recaptcha_theme'});});})(jQuery);";
           drupal_add_js('https://www.google.com/recaptcha/api/js/recaptcha.js', array('type' => 'external'));
-          drupal_add_js($js, array('type' => 'inline'));
+          drupal_add_js(array('recaptcha' => array('public_key' => $recaptcha_public_key, 'container' => 'recaptcha_ajax_api_container', 'theme' => $recaptcha_theme)), 'setting');
+          drupal_add_js(drupal_get_path('module', 'recaptcha') . '/recaptcha.js');
         }
       }
       return $captcha;
