array('selectedMedia' => array_values($files)));
    drupal_add_js($setting, 'setting');
    return $output;
  }
  // Normal browser operation.
  foreach (module_implements('media_browser_plugin_info') as $module) {
    foreach (module_invoke($module, 'media_browser_plugin_info') as $key => $plugin_data) {
      $plugins[$key] = $plugin_data + array(
        '#module' => $module,
        '#weight' => 0,
      );
      $plugins[$key]['#weight'] += count($plugins)/1000;
    }
  }
  // Only the plugins in this array are loaded.
  if (!empty($params['enabledPlugins'])) {
    $plugins = array_intersect_key($plugins, array_fill_keys($params['enabledPlugins'], 1));
  }
  elseif (!empty($params['disabledPlugins'])) {
    $plugins = array_diff_key($plugins, array_fill_keys($params['disabledPlugins'], 1));
  }
  foreach ($plugins as $key => &$plugin) {
    $plugin += module_invoke($plugin['#module'], 'media_browser_plugin_view', $key, $params);
  }
  // Allow modules to change the tab names or whatever else they want to change
  // before we render.  Perhaps this should be an alter on the theming function
  // that we should write to be making the tabs.
  drupal_alter('media_browser_plugins', $plugins);
  $tabs = array(); // List of tabs to render.
  $settings = array('media' => array('browser' => array()));
  $browser_settings =& $settings['media']['browser'];
  //@todo: replace with Tabs module if it gets upgraded.
  foreach (element_children($plugins, TRUE) as $key) {
    $plugin =& $plugins[$key];
    //Add any JS settings
    $browser_settings[$key] = isset($plugin['#settings']) ? $plugin['#settings'] : array();
    // If this is a "ajax" style tab, add the href, otherwise an id.
    $href = isset($plugin['#callback']) ? $plugin['#callback'] : "#media-tab-$key";
    $tabs[] = "{$plugin['#title']} 
EOS;
    $plugin['#suffix'] = <<
    
EOS;
  }
  drupal_add_js($settings, 'setting');
  $output['tabset'] = array(
    '#prefix' => '',
    '#suffix' => '
',
  );
  $output['tabset']['list'] = array(
    '#markup' => '' . implode(' ', $tabs) . '  Launch Media Browser ';
  $form['options'] = array(
    '#type' => 'textarea',
    '#title' => 'Options (JSON)',
    '#rows' => 10,
  );
  $form['launcher'] = array(
    '#markup' => $launcher,
  );
  $form['result'] = array(
    '#type' => 'textarea',
    '#title' => 'Result',
  );
  $js = <<').change(function() { jQuery('#edit-options').val(jQuery(this).val())});
      jQuery('.form-item-options').append('Recent');
      jQuery('.form-item-options').append(recentSelectBox);
      jQuery('.form-item-options').append(jQuery('Reset ').click(function() {alert('reset'); jQuery.cookie("recentOptions", null); window.location.reload(); }));
      jQuery.each(recentOptions, function (idx, val) {
        recentSelectBox.append(jQuery('