diff --git a/swipebox.info b/swipebox.info
index c8aa530..5e9da10 100644
--- a/swipebox.info
+++ b/swipebox.info
@@ -2,4 +2,5 @@ name = Swipebox
 description = "Add a formatter to image fields to make use of the Swipebox jQuery plugin"
 package = User interface
 core = 7.x
-files[] = swipebox.module
\ No newline at end of file
+
+dependencies[] = jquery_update
\ No newline at end of file
diff --git a/swipebox.js b/swipebox.js
index 6904c52..2219260 100644
--- a/swipebox.js
+++ b/swipebox.js
@@ -2,11 +2,18 @@
  * @file
  * Integration file for swipebox module.
  */
-
 (function($) {
-  $(document).ready(function() {
-    $(".swipebox").swipebox({
-      hideBarsDelay: 0, // always show title and action bar
-    });
-   });
+  Drupal.behaviors.swipebox = {
+    attach: function (context, settings) {
+      $('.swipebox').swipebox({
+        useCSS : true, // false will force the use of jQuery for animations.
+        useSVG : true, // false to force the use of png for buttons.
+        hideBarsOnMobile : false, // false will show the caption and navbar on mobile devices.
+        hideBarsDelay : 3000, // delay before hiding bars.
+        videoMaxWidth : 1140, // videos max width.
+        beforeOpen: function() {}, // called before opening.
+        afterClose: function() {} // called after closing.
+      });
+    }
+  };
 })(jQuery);
diff --git a/swipebox.module b/swipebox.module
index a3e2a5c..92e9f62 100644
--- a/swipebox.module
+++ b/swipebox.module
@@ -1,28 +1,48 @@
 <?php
-
 /**
  * @file
  * Provides the swipebox jQuery plugin for displaying images, HTML content and
  * multimedia in an elegant box.
  */
 
-define('SWIPEBOX_PATH', 'sites/all/libraries/swipebox');
-
 /**
- * Implements hook_init().
+ * Implements hook_library().
  */
-function swipebox_init() {
+function swipebox_library() {
+  $libraries = array();
 
-  $settings = variable_get('swipebox_settings');
+  $library_path = libraries_get_path('swipebox', FALSE);
+  if (empty($library_path)) {
+    drupal_set_message(t('Please install the Swipebox JS library in sites/.../libraries/swipebox/.'), 'error');
+    return array();
+  }
 
-  $modulepath = drupal_get_path('module', 'swipebox');
-  drupal_add_js(SWIPEBOX_PATH . '/source/jquery.swipebox.min.js');
-  drupal_add_js($modulepath.'/swipebox.js');
-  drupal_add_css(SWIPEBOX_PATH . '/source/swipebox.css');
+  $settings = variable_get('swipebox_settings');
+  // TODO: add settings to the library properties, see hook_library() docs.
+
+  $libraries['swipebox'] = array(
+    'title' => 'Swipebox jQuery Plugin',
+    'website' => 'http://brutaldesign.github.io/swipebox/',
+    'version' => '1.2.9',
+    'js' => array(
+      drupal_get_path('module', 'swipebox') . '/swipebox.js' => array('type' => 'file'),
+      "{$library_path}/src/js/jquery.swipebox.min.js" => array('type' => 'file'),
+//      array(
+//        'type' => 'setting',
+//        'data' => array('swipebox' => TRUE),
+//      ),
+    ),
+    'css' => array(
+      "{$library_path}/src/css/swipebox.min.css" => array('type' => 'file'),
+    ),
+    'dependencies' => array(
+      array('system', 'jquery'),
+    ),
+  );
 
+  return $libraries;
 }
 
-
 /**
  * Implements hook_theme().
  */
diff --git a/swipebox.theme.inc b/swipebox.theme.inc
index e17b906..a49066f 100644
--- a/swipebox.theme.inc
+++ b/swipebox.theme.inc
@@ -110,6 +110,9 @@ function theme_swipebox_image_formatter($variables) {
  * @param $variables array
  */
 function theme_swipebox_imagefield($variables) {
+  // Load Swipebox library where it's necessary.
+  drupal_add_library('swipebox', 'swipebox', FALSE);
+
   $image = $variables['image'];
   $path = $variables['path'];
   $caption = $variables['caption'];
