--- jquery_plugin.module	2008-12-08 15:10:39.000000000 +0100
+++ jquery_plugin.module	2008-12-08 15:10:30.000000000 +0100
@@ -4,10 +4,38 @@
 /**
  * Add a jQuery plugin to a page.
  */
-function jquery_plugin_add($plugin) {
+function jquery_plugin_add($plugin, $message_values = array()) {
   static $plugins = array();
   if (!isset($plugins[$plugin])) {
-    drupal_add_js(drupal_get_path('module', 'jquery_plugin') .'/jquery.'. $plugin .'.min.js');
-    $plugins[$plugin] = TRUE;
+    if ($path = jquery_plugin_exists($plugin, $message_values)) {
+      drupal_add_js($path);
+      $plugins[$plugin] = TRUE;
+    }
   }
 }
+
+/**
+ * Validates the existence of a plugin.
+ *
+ * @param $plugin string The name of the plugin to check for.
+ * @param $module string The name of the module which called this function. This is used for the message if no plugin is found.
+ * @param $link string The url to the plugin downloadpage. If the required plugin isn't found, this link is displayed in an error message.
+ *
+ * @return If a plugin is found, the path to the plugin is returned. If the plugin isn't found, a message will be displayed.
+ */
+function jquery_plugin_exists($plugin, $message_values = array()) {
+  $path = drupal_get_path('module', 'jquery_plugin');
+  foreach (array('pack', 'min', 'src', '') as $type) {
+    if (file_exists("$path/jquery.$plugin.$type.js")) {
+      return "$path/jquery.$plugin.$type.js";
+    }
+  }
+
+  drupal_set_message(t('The jQuery plugin !plugin was not found! This plugin is required by !module. Please download this plugin !link and place it in the jquery_plugin plugins folder (!path).', array(
+    '!plugin' => $plugin,
+    '!module' => (!empty($message_values['module']) ? $message_values['module'] : 'jquery_plugin'),
+    '!link' => l(t('here'), (!empty($message_values['link']) ? $message_values['link'] : 'http://plugins.jquery.com/'), array('target' => '_blank')),
+    '!path' => $path,
+  )), 'error');
+  return FALSE;
+}
