diff --git colorbox_file.info colorbox_file.info
index cba488e..bfa5ae4 100644
--- colorbox_file.info
+++ colorbox_file.info
@@ -1,11 +1,9 @@
-; $Id
-name = Colorbox File
-description = Integrates Colorbox with the Media module via a colorbox file formatter.
-package = Styles
+name = Colorbox file
+description = Provides integration between Colorbox and file fields.
 core = 7.x
 php = 5.2
 
 files[] = colorbox_file.module
 
-dependencies[] = image
-dependencies[] = colorbox
\ No newline at end of file
+dependencies[] = file_entity
+dependencies[] = colorbox
diff --git colorbox_file.module colorbox_file.module
index 033f094..0d95b29 100644
--- colorbox_file.module
+++ colorbox_file.module
@@ -1,9 +1,7 @@
 <?php
-// $Id:
-
 /**
  * @file
- * A light-weight integration between Colorbox and a Media image
+ * Provides integration between Colorbox and file fields.
  */
 
 /**
@@ -11,85 +9,166 @@
  */
 function colorbox_file_theme() {
   return array(
-    // file.module.
-    'file_colorbox' => array(
+    'colorbox_file' => array(
       'variables' => array(
-        'file' => NULL, 
-        'icon_directory' => NULL, 
-        'styles_overrides' => NULL, 
-        'colorbox_node_style' => NULL,
-        'colorbox_image_style' => NULL,
-       ),
+        'item' => array(),
+        'entity_id' => NULL,
+        'field' => array(),
+        'display_settings' => array(),
+        'langcode' => NULL,
+        'path' => NULL,
+        'title' => NULL,
+      ),
     ),
   );
 }
 
 /**
+ * Implements hook_menu().
+ */
+function colorbox_file_menu() {
+  $items['colorbox_media/%file/%/%'] = array(
+    'title' => 'Colorbox',
+    'page callback' => 'colorbox_media_callback',
+    'page arguments' => array(1, 2, 3),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  return $items;
+}
+
+/**
+ * Menu callback; Displays a given field inside a colorbox.
+ */
+function colorbox_media_callback($file, $view_mode, $langcode) {
+  print '<div>' . drupal_render(file_view($file, $view_mode, $langcode)) . '</div>';
+  exit;
+}
+
+/**
  * Implements hook_field_formatter_info().
  */
 function colorbox_file_field_formatter_info() {
-  //the same approach used by the colorbox module for image fields
   return array(
-    'file_colorbox' => array(
-      'label' => t('Colorbox file'),
-      'field types' => array('file'),
-      'settings' => array('colorbox_node_style' => '', 'colorbox_image_style' => ''),
+    'media_colorbox' => array(
+      'label' => t('Colorbox media'),
+      'field types' => array('media', 'file', 'image'),
+      'settings' => array(
+        'file_view_mode' => 'default',
+        'colorbox_view_mode' => 'default',
+        'colorbox_gallery' => 'post',
+        'colorbox_gallery_custom' => '',
+        'colorbox_caption' => 'auto',
+      ),
     ),
   );
 }
 
 /**
- * Implementation of hook_field_formatter_settings_form().
+ * Implements hook_field_formatter_settings_form().
  */
 function colorbox_file_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
   $display = $instance['display'][$view_mode];
   $settings = $display['settings'];
 
-  $image_styles = image_style_options(FALSE);
-  $element['colorbox_node_style'] = array(
-    '#title' => t('Node image style'),
-    '#type' => 'select',
-    '#default_value' => $settings['colorbox_node_style'],
-    '#empty_option' => t('None (original image)'),
-    '#options' => $image_styles,
-  );
-  $element['colorbox_image_style'] = array(
-    '#title' => t('Colorbox image style'),
-    '#type' => 'select',
-    '#default_value' => $settings['colorbox_image_style'],
-    '#empty_option' => t('None (original image)'),
-    '#options' => $image_styles,
-  );
+  $element = array();
+
+  if ($display['type'] == 'media_colorbox') {
+    $entity_info = entity_get_info('file');
+    $options = array('default' => t('Default'));
+    foreach ($entity_info['view modes'] as $file_view_mode => $file_view_mode_info) {
+      $options[$file_view_mode] = $file_view_mode_info['label'];
+    }
+
+    $element['file_view_mode'] = array(
+      '#title' => t('File view mode'),
+      '#type' => 'select',
+      '#default_value' => $settings['file_view_mode'],
+      '#options' => $options,
+    );
+    $element['colorbox_view_mode'] = array(
+      '#title' => t('Colorbox view mode'),
+      '#type' => 'select',
+      '#default_value' => $settings['colorbox_view_mode'],
+      '#options' => $options,
+    );
+    $gallery = array(
+      'post' => t('Per post gallery'),
+      'page' => t('Per page gallery'),
+      'field_post' => t('Per field in post gallery'),
+      'field_page' => t('Per field in page gallery'),
+      'custom' => t('Custom'),
+      'none' => t('No gallery'),
+    );
+    $element['colorbox_gallery'] = array(
+      '#title' => t('Gallery (image grouping)'),
+      '#type' => 'select',
+      '#default_value' => $settings['colorbox_gallery'],
+      '#options' => $gallery,
+      '#description' => t('How Colorbox should group the image galleries.'),
+    );
+    $element['colorbox_gallery_custom'] = array(
+      '#title' => t('Custom gallery'),
+      '#type' => 'machine_name',
+      '#maxlength' => 32,
+      '#default_value' => $settings['colorbox_gallery_custom'],
+      '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
+      '#required' => FALSE,
+      '#machine_name' => array(
+        'exists' => 'colorbox_gallery_exists',
+        'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
+      ),
+      '#states' => array(
+        'visible' => array(
+          ':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
+        ),
+      ),
+    );
+  }
 
   return $element;
 }
 
 /**
- * Implementation of hook_field_formatter_settings_summary().
+ * Implements hook_field_formatter_settings_summary().
  */
 function colorbox_file_field_formatter_settings_summary($field, $instance, $view_mode) {
   $display = $instance['display'][$view_mode];
   $settings = $display['settings'];
-
   $summary = array();
 
-  $image_styles = image_style_options(FALSE);
-  // Unset possible 'No defined styles' option.
-  unset($image_styles['']);
-  // Styles could be lost because of enabled/disabled modules that defines
-  // their styles in code.
-  if (isset($image_styles[$settings['colorbox_node_style']])) {
-    $summary[] = t('Node image style: @style', array('@style' => $image_styles[$settings['colorbox_node_style']]));
-  }
-  else {
-    $summary[] = t('Node image style: Original image');
-  }
+  if ($display['type'] == 'media_colorbox') {
+    $entity_info = entity_get_info('file');
+    $options = array('default' => t('Default'));
+    foreach ($entity_info['view modes'] as $file_view_mode => $file_view_mode_info) {
+      $options[$file_view_mode] = $file_view_mode_info['label'];
+    }
 
-  if (isset($image_styles[$settings['colorbox_image_style']])) {
-    $summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']]));
-  }
-  else {
-    $summary[] = t('Colorbox image style: Original image');
+    if (isset($options[$settings['file_view_mode']])) {
+      $summary[] = t('File view mode: @style', array('@style' => $options[$settings['file_view_mode']]));
+    }
+    else {
+      $summary[] = t('File view mode: none');
+    }
+
+    if (isset($options[$settings['colorbox_view_mode']])) {
+      $summary[] = t('Colorbox view mode: @style', array('@style' => $options[$settings['colorbox_view_mode']]));
+    }
+    else {
+      $summary[] = t('Colorbox view mode: none');
+    }
+
+    $gallery = array(
+      'post' => t('Per post gallery'),
+      'page' => t('Per page gallery'),
+      'field_post' => t('Per field in post gallery'),
+      'field_page' => t('Per field in page gallery'),
+      'custom' => t('Custom'),
+      'none' => t('No gallery'),
+    );
+    if (isset($settings['colorbox_gallery'])) {
+      $summary[] = t('Colorbox gallery type: @type', array('@type' => $gallery[$settings['colorbox_gallery']])) . ($settings['colorbox_gallery'] == 'custom' ? ' (' . $settings['colorbox_gallery_custom'] . ')' : '');
+    }
   }
 
   return implode('<br />', $summary);
@@ -100,77 +179,99 @@ function colorbox_file_field_formatter_settings_summary($field, $instance, $view
  */
 function colorbox_file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
   $element = array();
-  switch ($display['type']) {
-    case 'file_colorbox':
-      $styles_overrides = array();
-      if (isset($entity->override)) {
-        $styles_overrides = $entity->override;
+
+  if ($display['type'] == 'media_colorbox') {
+    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
+    $files = array();
+    
+    foreach ($items as $delta => $item) {
+      if (isset($item['file'])) {
+        $files[$item['fid']] = $item['file'];
       }
-      foreach ($items as $delta => $item) {
-        $element[$delta] = array(
-          '#theme' => 'file_colorbox',
-          '#file' => (object) $item,
-          '#styles_overrides' => $styles_overrides,
-          '#colorbox_node_style' => $display['settings']['colorbox_node_style'],
-          '#colorbox_image_style' => $display['settings']['colorbox_image_style'],
-        );
+      else {
+        $files[$item['fid']] = (object) $item;
       }
-      break;
+    }
+    $build = file_view_multiple($files, $display['settings']['file_view_mode'], 0, $langcode);
+
+    foreach (element_children($build) as $fid) {
+      $element[$fid] = array(
+        '#theme' => 'colorbox_file',
+        '#item' => $build[$fid]['file'],
+        '#entity_id' => $id,
+        '#field' => $field,
+        '#display_settings' => $display['settings'],
+        '#langcode' => $langcode,
+        '#path' => 'colorbox_media/' . $fid . '/' . $display['settings']['colorbox_view_mode'] . '/' . $langcode,
+        '#title' => isset($instance['label']) ? $instance['label'] : NULL,
+      );
+    }
+
+    drupal_add_js(drupal_get_path('module', 'colorbox_file') . '/colorbox_file.js');
   }
 
   return $element;
 }
 
 /**
- * Returns HTML for a link to a file.
+ * Returns HTML for a Colorbox file field formatter.
  *
  * @param $variables
  *   An associative array containing:
- *   - file: A file object to which the link will be created.
- *   - icon_directory: (optional) A path to a directory of icons to be used for
- *     files. Defaults to the value of the "file_icon_directory" variable.
+ *   - item: A build array.
+ *   - entity_id: The entity ID.
+ *   - field: The field data.
+ *   - display_settings: The display settings.
+ *   - langcode: The language code.
+ *   - path: The path to the content.
+ *   - title: The title of the content.
  *
  * @ingroup themeable
  */
-function theme_file_colorbox($variables) {
-  $output = '';
-  
-  $file = $variables['file'];
-  $icon_directory = $variables['icon_directory'];
-  
-  $attributes = array();
-  if (isset($variables['styles_overrides']['style'])) {
-    $attributes['style'] = $variables['styles_overrides']['style'];
-  }
-  $title = '';
-  if (isset($variables['styles_overrides']['title'])) {
-    $title = $variables['styles_overrides']['title'];
-  }
-  $alt = '';
-  if (isset($variables['styles_overrides']['alt'])) {
-    $alt = $variables['styles_overrides']['alt'];
-  }
-  if($file->type == 'image') {
-    $image = array(
-      'path' => $file->uri,
-      'alt' => $alt,
-      'title' => $title,
-      'style_name' => $variables['colorbox_node_style'],
-      'attributes' => $attributes,
-    );
-    
-    $path = '';
-    if ($style_name = $variables['colorbox_image_style']) {
-      $path = image_style_url($style_name, $image['path']);
-    }
-    else {
-      $path = file_create_url($image['path']);
-    }
-    $output = theme('colorbox_imagefield', array('image' => $image, 'path' => $path, 'title' => $image['title']));
+function theme_colorbox_file($variables) {
+  $entity_id = $variables['entity_id'];
+  $field = $variables['field'];
+  $settings = $variables['display_settings'];
+  $caption = $variables['title'];
+
+  // Shorten the caption for the example styles or when caption shortening is active.
+  $colorbox_style = variable_get('colorbox_style', 'default');
+  $trim_length = variable_get('colorbox_caption_trim_length', 75);
+  if ((variable_get('colorbox_caption_trim', 0)) && (drupal_strlen($caption) > $trim_length)) {
+    $caption = drupal_substr($caption, 0, $trim_length - 5) . '...';
   }
-  else {
-    $output = theme('file_link', array('file' => $file, 'icon_directory' => $icon_directory));
+
+  // Build the gallery id.
+  switch ($settings['colorbox_gallery']) {
+    case 'post':
+      $gallery_id = 'gallery-' . $entity_id;
+      break;
+    case 'page':
+      $gallery_id = 'gallery-all';
+      break;
+    case 'field_post':
+      $gallery_id = 'gallery-' . $entity_id . '-' . $field['field_name'];
+      break;
+    case 'field_page':
+      $gallery_id = 'gallery-' . $field['field_name'];
+      break;
+    case 'custom':
+      $gallery_id = $settings['colorbox_gallery_custom'];
+      break;
+    default:
+      $gallery_id = '';
   }
 
-  return $output;
+  return theme('link', array(
+    'text' => drupal_render($variables['item']),
+    'path' => $variables['path'],
+    'options' => array(
+      'html' => TRUE,
+      'attributes' => array(
+        'title' => $caption,
+        'class' => 'colorbox-file',
+        'rel' => $gallery_id,
+      ),
+    ),
+  ));
 }
