Index: MediaEntityController.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/MediaEntityController.php,v
retrieving revision 1.2
diff -u -p -r1.2 MediaEntityController.php
--- MediaEntityController.php	7 Apr 2010 06:29:34 -0000	1.2
+++ MediaEntityController.php	5 Nov 2010 16:07:29 -0000
@@ -11,7 +11,7 @@ class MediaEntityController extends Drup
   public function load($ids = array(), $conditions = array()) {
     $this->ids = $ids;
     $this->conditions = $conditions;
-
+    
     $entities = array();
 
     // Revisions are not statically cached, and require a different query to
Index: media.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.admin.inc,v
retrieving revision 1.22
diff -u -p -r1.22 media.admin.inc
--- media.admin.inc	18 Sep 2010 02:42:05 -0000	1.22
+++ media.admin.inc	5 Nov 2010 16:07:30 -0000
@@ -65,26 +65,54 @@ function media_admin($form, $form_state)
   $form['options'] = array(
     '#type' => 'fieldset',
     '#title' => t('Operations'),
-    '#prefix' => '<div class="container-inline">',
-    '#suffix' => '</div>',
   );
   $options = array();
   foreach (module_invoke_all('media_operations') as $operation => $array) {
     $options[$operation] = $array['label'];
   }
-  $form['options']['operation'] = array(
+  $form['options']['operations'] = array(
+    '#type' => 'container',
+    '#prefix' => '<div class="container-inline">',
+    '#suffix' => '</div>'
+  );
+  $form['options']['operations']['operation'] = array(
     '#type' => 'select',
     '#options' => $options,
     '#default_value' => 'delete',
   );
   $options = array();
-  $form['options']['submit'] = array(
+  $form['options']['operations']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
     '#submit' => array('media_admin_submit'),
     '#validate' => array('media_admin_validate'),
   );
-
+  $form['options']['category'] = array(
+    '#type' => 'container',
+  );
+  $form['options']['category']['selected_category'] = array(
+    '#type' => 'select',
+    '#title' => t('Media Category*'),
+    '#required' => FALSE,
+    '#options' => media_get_categories_hierarchy()
+  );
+  $form['options']['category']['submit'] = array(
+    '#type' => 'container',
+    '#prefix' => '<div class="container-inline">',
+    '#suffix' => '</div>'
+  );
+  $form['options']['category']['submit']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Change Category'),
+    '#submit' => array('media_admin_category_change_submit'),
+    '#validate' => array('media_admin_validate'),
+  );
+  $form['options']['category']['submit']['notice'] = array(
+    '#type' => 'item',
+    '#markup' => t('*: change will be applied to ALL selected media files')
+  );
+  
+  
   include_once $types[$display]['file'];
 
   $form['admin'] = $types[$display]['callback']();
@@ -101,6 +129,7 @@ function media_admin_list() {
   $header = array(
    'title' => array('data' => t('Title'), 'field' => 'f.filename'),
    'type' => array('data' => t('Type'), 'field' => 'f.filemime'),
+   'category' => array('data' => t('Catgeory'), 'field' => 'ttd.name'),
    'size' => array('data' => t('Size'), 'field' => 'f.filesize'),
    'author' => array('data' => t('Author'), 'field' => 'u.name'),
    'timestamp' => array('data' => t('Updated'), 'field' => 'f.timestamp', 'sort' => 'asc'),
@@ -109,14 +138,30 @@ function media_admin_list() {
 
   $query = db_select('file_managed', 'f')->extend('PagerDefault')->extend('TableSort');
   $query->join('users', 'u', 'f.uid = u.uid');
+  $query->leftJoin('taxonomy_term_data', 'ttd', 'f.media_cid = ttd.tid');
 
-  $result = $query
+  $query
    ->fields('f')
    ->fields('u', array('name'))
+   ->fields('ttd', array('name'))
    ->limit(50)
-   ->orderByHeader($header)
-   ->execute();
-
+   ->orderByHeader($header);
+   
+  // looking for a filter
+  if(isset($_SESSION['media-filter'])){ 
+  	if(strlen($_SESSION['media-filter']['filename'])){
+  	  $query->condition('f.filename', "%".$_SESSION['media-filter']['filename']."%", 'LIKE');
+  	}
+  	if(count($_SESSION['media-filter']['type'])){
+  	  $query->condition('f.type', explode(",", $_SESSION['media-filter']['type']), 'IN');
+  	}
+  	if(count($_SESSION['media-filter']['media_cid'])){
+  	  $query->condition('f.media_cid', $_SESSION['media-filter']['media_cid'], 'IN');
+  	}
+  }
+  // execution the query after applying a possible filter
+  $result = $query->execute();
+  
   $destination = drupal_get_destination();
   $files = array();
   $options = array();
@@ -124,6 +169,7 @@ function media_admin_list() {
   foreach ($result as $file) {
     $options[$file->fid] = array(
       'title' => theme('media_link', array('file' => $file)),
+      'category' => $file->ttd_name,
       'type' =>  check_plain($file->filemime),
       'size' => format_size($file->filesize),
       'author' => theme('username', array('account' => $file)),
@@ -131,7 +177,9 @@ function media_admin_list() {
     );
     $options[$file->fid]['operations'] = l(t('edit'), 'media/' . $file->fid . '/edit', array('query' => $destination));
   }
-
+  
+  $form['filter'] = media_admin_filter_form();
+  
   $form['files'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
@@ -145,13 +193,238 @@ function media_admin_list() {
 }
 
 /**
+ * 
+ * Called when the filter form is submitted.
+ * Adds filter to session and redirects back to callee
+ * 
+ * @param $argument
+ */
+function media_admin_filter_submit($form, $form_state) {
+  // process filter
+  $_SESSION['media-filter']['filename'] = check_plain($form_state['input']['filename']);
+  $_SESSION['media-filter']['type'] = count($form_state['values']['media_type']) > 0 ? 
+    implode(",", $form_state['values']['media_type']) :
+    implode(",", media_type_get_type_names());
+  $_SESSION['media-filter']['include_subcategories'] = $form_state['values']['include_subcategories'];
+  //
+  $temp = array();
+  //
+  if(count($form_state['values']['media_cid']) == 0){
+    $all = taxonomy_get_tree(variable_get('media_categories_vocabulary'));
+    //
+  	foreach($all as $key=>$term){
+  	  $temp[$term->tid] = $term->tid;
+  	}
+  }
+  else {
+    foreach($form_state['values']['media_cid'] as $key=>$value){
+  	  $tid = (int)str_replace("_", "", $value);
+  	  $temp[$tid] = $tid;
+  	  //
+  	  if($form_state['values']['include_subcategories']){
+  	    $children = taxonomy_get_tree(variable_get('media_categories_vocabulary'), $tid);
+        //
+  	    foreach($children as $key=>$term){
+  	      $temp[$term->tid] = $term->tid;
+  	    }
+  	  }
+    }
+  }
+  $_SESSION['media-filter']['media_cid'] = array_keys($temp);
+  //
+  $destination = array();
+  if (isset($_GET['destination'])) {
+    $destination = drupal_get_destination();
+    unset($_GET['destination']);
+  }
+  $form_state['redirect'] = array('admin/content/media/list/', array('query' => $destination));
+}
+
+/**
+ * 
+ * Validates the filter form
+ * 
+ * @param unknown_type $form
+ * @param unknown_type $form_state
+ */
+function media_admin_filter_validate($form, &$form_state) {
+  // @todo: implement filter minimum check
+}
+
+/**
+ * 
+ * Enter description here ...
+ * @param unknown_type $form
+ * @param unknown_type $form_state
+ */
+function media_admin_category_change_submit($form, $form_state){
+  //
+  $fids = array_keys(array_filter($form_state['values']['files']));
+  $cid = (int)str_replace("_", "", $form_state['values']['selected_category']);
+  //
+  db_update('file_managed')
+    ->fields(array('media_cid' => $cid))
+    ->condition('fid', $fids, 'IN')
+    ->execute();
+  //
+  drupal_set_message(t('Category changes applied successfully'));
+}
+
+/**
+ * generates and returns the filter form
+ * 
+ * 
+ */
+function media_admin_filter_form(){
+  // getting the media categories for filter selection
+  $categories = media_get_categories_hierarchy();
+  // setting default filter selections - will be overwritten when a filter is active
+  $selectedTypes = array_keys(media_type_get_type_names());
+  $selectedCategories = array_keys($categories);
+  //
+  if(isset($_SESSION['media-filter'])){ 
+  	if(count($_SESSION['media-filter']['type'])){
+  	  $selectedTypes = explode("," ,$_SESSION['media-filter']['type']);	
+  	}
+    if(count($_SESSION['media-filter']['media_cid'])){
+  	  $selectedCategories = array(); 
+  	  foreach($_SESSION['media-filter']['media_cid'] as $key=>$value){
+  	  	$selectedCategories[] = "_" . $value;
+  	  }	
+  	}
+  }
+  //
+  $form['filter'] = array(
+  	'#type' => 'fieldset',
+  	'#title' => t('Filter Media'),
+    '#collapsible' => TRUE,
+    '#collapsed' => !isset($_SESSION['media-filter']),
+    '#weight' => -10,
+  
+    'filename' => array(
+  	    '#type' => 'textfield',
+        '#title' => t('Title'),
+        '#maxlength' => 125,
+        '#size' => 40,
+        '#value' => (isset($_SESSION['media-filter']['filename']) ? 
+                     $_SESSION['media-filter']['filename'] : ""),
+        '#required' => FALSE),
+                     
+    'criterias' => array(
+      '#type' => 'container',
+  
+      'media_type' => array(
+  	    '#type' => 'select',
+        '#title' => t('Media Type'),
+        '#multiple' => TRUE,
+        '#options' => media_type_get_type_names(),
+        '#default_value' => $selectedTypes,
+        '#weight' => 5,
+        '#required' => FALSE,
+        '#attributes' => array('class' => array('media-filter-select')),
+        '#prefix' => '<div style="float:left; padding-right: 20px;">',
+        '#suffix' => '</div>'),
+  
+      'media_cid' => array(
+        '#type' => 'select',
+        '#title' => t('Media Category'),
+        '#multiple' => TRUE,
+        '#required' => FALSE,
+        '#options' => $categories,
+        '#default_value' => $selectedCategories,
+        '#weight' => 6,
+        '#attributes' => array('class' => array('media-filter-select')),
+        '#prefix' => '<div style="float:left; padding-right: 20px;">',
+        '#suffix' => '</div>')
+    ),
+    
+    'include_subcategories' => array(
+        '#type' => 'checkbox',
+        '#weight' => 10,
+        '#prefix' => '<div style="clear: both;">',
+        '#suffix' => '</div>',
+        '#attributes' => array('class' => array('media-filter')),
+        '#title' => t('include subcategories of selected categories'),
+        '#default_value' => (isset($_SESSION['media-filter']['include_subcategories']) ? 
+                     $_SESSION['media-filter']['include_subcategories'] : 0)
+      ),
+    
+    'actions' => array(
+      '#type' => 'container',
+      '#weight' => 11,
+      
+      'submit' => array(
+        '#type' => 'submit',
+        '#value' => t('Filter'),
+        '#submit' => array('media_admin_filter_submit'),
+        '#validate' => array('media_admin_filter_validate')
+      ),
+      
+    )
+  );
+  
+  if(isset($_SESSION['media-filter'])){ 
+  	$form['filter']['actions']['clear'] = array(
+        '#type' => 'submit',
+        '#value' => t('Clear'),
+        '#submit' => array('media_admin_filter_clear'),
+        '#validate' => array('media_admin_filter_clear_validate')
+    );
+  }
+  
+  return $form['filter'];
+}
+/**
+ * 
+ * Called when the filter form is submitted.
+ * Adds filter to session and redirects back to callee
+ * 
+ * @param $argument
+ */
+function media_admin_filter_clear($form, $form_state) {
+  // remove filter
+  unset($_SESSION['media-filter']);
+  //
+  $destination = array();
+  if (isset($_GET['destination'])) {
+    $destination = drupal_get_destination();
+    unset($_GET['destination']);
+  }
+  $form_state['redirect'] = array('admin/content/media/list/', array('query' => $destination));
+}
+
+/**
+ * 
+ * Validates the filter form
+ * 
+ * @param unknown_type $form
+ * @param unknown_type $form_state
+ */
+function media_admin_filter_clear_validate($form, &$form_state) {
+  // @todo: implement filter minimum check
+}
+
+/**
  * Form builder: Builds the media thumbnails administration overview.
  */
 function media_admin_thumbnails() {
   $limit = variable_get('media_admin_limit', 50);
-
+  $conditions = array();
+  
+  if(isset($_SESSION['media-filter'])){
+  	if(strlen($_SESSION['media-filter']['filename'])){
+  	  $conditions[] = array('filename', "%".$_SESSION['media-filter']['filename']."%", 'LIKE');
+  	}
+  	if(count($_SESSION['media-filter']['type'])){
+  	  $conditions[] = array('type', explode(",", $_SESSION['media-filter']['type']), 'IN');
+  	}
+  	if(count($_SESSION['media-filter']['media_cid'])){
+  	  $conditions[] = array('media_cid', $_SESSION['media-filter']['media_cid'], 'IN');
+  	}
+  }
+  
   $entity_controller = entity_get_controller('media');
-  $media_entities = $entity_controller->load(NULL, array(), 0, $limit);
+  $media_entities = $entity_controller->load(NULL, $conditions, 0, $limit);
 
   $destination = drupal_get_destination();
   $rows = array();
@@ -162,6 +435,11 @@ function media_admin_thumbnails() {
    '#suffix' => '</ul></div>',
   );
 
+  $form['filter'] = media_admin_filter_form();
+  // need to move the filter fieldset down in grid view
+  $form['filter']['#prefix'] = '<div style="clear: both;">';
+  $form['filter']['#suffix'] = '</div>';
+  
   if (count($media_entities)) {
     foreach ($media_entities as $media) {
      $form['files'][$media->fid] = array(
Index: media.browser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.browser.inc,v
retrieving revision 1.24
diff -u -p -r1.24 media.browser.inc
--- media.browser.inc	4 Nov 2010 21:35:24 -0000	1.24
+++ media.browser.inc	5 Nov 2010 16:07:30 -0000
@@ -234,7 +234,7 @@ function media_media_browser_plugin_view
       else {
         $upload_form_id = 'media_add_upload';
       }
-
+      
       $upload_form = drupal_get_form($upload_form_id, $types);
       return array(
         '#title' => t('Upload'),
Index: media.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.info,v
retrieving revision 1.4
diff -u -p -r1.4 media.info
--- media.info	7 Apr 2010 06:29:34 -0000	1.4
+++ media.info	5 Nov 2010 16:07:30 -0000
@@ -18,3 +18,4 @@ dependencies[] = file
 dependencies[] = image
 dependencies[] = file_styles
 dependencies[] = entity
+dependencies[] = taxonomy
Index: media.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.install,v
retrieving revision 1.17
diff -u -p -r1.17 media.install
--- media.install	26 Oct 2010 13:36:36 -0000	1.17
+++ media.install	5 Nov 2010 16:07:30 -0000
@@ -42,6 +42,12 @@ function media_install() {
   // Alter {file_managed}.type and add it as an index.
   db_add_field('file_managed', 'type', _media_type_field_spec());
   db_add_index('file_managed', 'file_type', array('type'));
+  db_add_field('file_managed', 'media_cid', array(
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+  				'default' => 0,
+				'description' => t('Term ID of the associated media category')));
 }
 
 /**
@@ -142,6 +148,10 @@ function media_enable() {
   foreach ($roles as $rid => $role) {
     user_role_grant_permissions($rid, array('view media'));
   }
+  
+  // create vocabularies for categorization and tagging
+  media_get_vocabulary_categories();
+  media_get_vocabulary_tagging();
 }
 
 /**
@@ -185,6 +195,33 @@ function media_schema() {
     ),
     'primary key' => array('uid'),
   );
+  
+  $schema['media_taxonomy_file'] = array(
+		'description' => t('Enables (Taxonomy) Term File Association.'),
+		'fields' => array(
+			'fid' => array(
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+				'description' => t('File ID')),
+			'tid' => array(
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+				'description' => t('Term ID')),
+			'uid' => array(
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+				'description' => t('The users.uid of the user who created this entry.')),
+			'created' => array(
+				'type' => 'int',
+				'default' => 0,
+				'not null' => TRUE,
+				'description' => t('Unix timestamp indicating when this entry was created'))
+		),
+		'primary key' => array('fid','tid')
+		);
 
   $schema['cache_media_xml'] = drupal_get_schema_unprocessed('system', 'cache');
   $schema['cache_media_xml']['description'] = 'Cache table for the the results of retreived XML documents for remote streams.';
@@ -239,9 +276,14 @@ function media_uninstall() {
    * See comment above in media_install.
    */
   db_drop_field('file_managed', 'type');
+  db_drop_field('file_managed', 'media_cid');
   foreach (media_variable_default() as $name => $value) {
     media_variable_del($name);
   }
+  taxonomy_vocabulary_delete(variable_get('media_categories_vocabulary'));
+  taxonomy_vocabulary_delete(variable_get('media_tagging_vocabulary'));
+  variable_del('media_categories_vocabulary');
+  variable_del('media_tagging_vocabulary');
 }
 
 /**
Index: media.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.module,v
retrieving revision 1.56
diff -u -p -r1.56 media.module
--- media.module	26 Oct 2010 22:46:37 -0000	1.56
+++ media.module	5 Nov 2010 16:07:30 -0000
@@ -353,6 +353,7 @@ function media_theme() {
       'variables' => array('file' => NULL),
       'file' => 'media.theme.inc',
     ),
+    
   );
 }
 
@@ -1146,3 +1147,102 @@ function media_file_validate_types(stdCl
   
   return $errors;
 }
+
+/**
+ * 
+ * creates a select list with indendations for subcategories
+ */
+function media_get_categories_hierarchy($prefixPadding = ".."){
+  $categories = taxonomy_get_tree(variable_get('media_categories_vocabulary'));
+  
+  $list = array();
+  
+  foreach($categories as $category){
+  	$pad = (($category->depth * strlen($prefixPadding)) + strlen($category->name));
+    $list['_' . $category->tid] = str_pad($category->name, $pad, $prefixPadding, STR_PAD_LEFT); 
+  }
+ 
+  return $list;
+}
+
+/**
+ * loads and/or creates the Media Categories Vocabulary
+ * 
+ * @return Vocabulary Object
+ */
+function media_get_vocabulary_categories()
+{
+  // create vocabularies for categorization and tagging
+  $vid = (int) variable_get('media_categories_vocabulary');
+  
+  if($vid == 0 || is_null(taxonomy_vocabulary_load($vid))){
+  	// searching for vid in DB
+  	$res = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module='media' AND machine_name='media_categories'");
+    $vid = is_object($res->fetchObject()) ? $res->fetchObject()->vid : 0;
+    // no vocabulary found
+    if(!$vid){
+      // create new vocabulary
+      $temp = array(
+        'name' => t('Media Categories'),
+        'machine_name' => 'media_categories',
+        'description' => t('Media Categories Vocabulary'),
+        'hierarchy' => 1,
+        'module' => 'media',
+        'weight' => -10,
+      );
+      $vocabulary = (object) $temp;
+      
+      taxonomy_vocabulary_save($vocabulary);
+      variable_set('media_categories_vocabulary', $vocabulary->vid);
+      $vid = $vocabulary->vid;
+      // created default category
+      $media_root_term = new stdClass();
+      $media_root_term->name = 'Media Root';
+      $media_root_term->description = 'default media category';
+      $media_root_term->vid = $vocabulary->vid;
+      $media_root_term->weight = '-10';
+      
+      taxonomy_term_save($media_root_term);
+      // apply default category to all files
+      db_update('file_managed')
+        ->fields(array('media_cid' => $media_root_term->tid))
+        ->execute();
+    }
+  }
+  return taxonomy_vocabulary_load($vid);
+}
+
+/**
+ * loads and/or creates the Media tagging Vocabulary
+ * 
+ * @return Vocabulary Object
+ */
+function media_get_vocabulary_tagging()
+{
+  // create vocabularies for categorization and tagging
+  $vid = (int) variable_get('media_tagging_vocabulary');
+  
+  if($vid == 0 || is_null(taxonomy_vocabulary_load($vid))){
+  	// search for vocabulary in DB
+  	$res = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module='media' AND machine_name='media_tagging'");
+    $vid = is_object($res->fetchObject()) ? $res->fetchObject()->vid : 0;
+    // no vocabulary found
+    if(!$vid){
+      // create new one
+      $temp = array(
+        'name' => t('Media Tagging'),
+        'machine_name' => 'media_tagging',
+        'description' => t('Media Tagging Vocabulary'),
+        'hierarchy' => 0,
+        'module' => 'media',
+        'weight' => -9,
+      );
+      $vocabulary = (object) $temp;
+      
+      taxonomy_vocabulary_save($vocabulary);
+      variable_set('media_tagging_vocabulary', $vocabulary->vid);
+      $vid = $vocabulary->vid;
+    }
+  }
+  return taxonomy_vocabulary_load($vid);
+}
\ No newline at end of file
Index: media.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.pages.inc,v
retrieving revision 1.28
diff -u -p -r1.28 media.pages.inc
--- media.pages.inc	17 Sep 2010 19:49:57 -0000	1.28
+++ media.pages.inc	5 Nov 2010 16:07:31 -0000
@@ -165,7 +165,7 @@ function media_multiple_delete_confirm_s
  * @todo: should use the AJAX uploader
  */
 function media_add_upload($form, &$form_state, $types = NULL) {
-
+  
   $validators = array(
    'file_validate_extensions' => array(media_variable_get('file_extensions')),
    'file_validate_size' => array(parse_size(media_variable_get('max_filesize'))),
@@ -197,12 +197,20 @@ function media_add_upload($form, &$form_
     '#description' => theme('file_upload_help', array('description' => '', 'upload_validators' => $validators)),
     '#upload_validators' => $validators,
   );
-
+  
+  $form['media_cid'] = array(
+      '#type' => 'select',
+      '#title' => t('File Category'),
+      '#options' => media_get_categories_hierarchy(),
+      '#description' => t('Select a category this file should be put in')
+  );
+  
+  
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
   );
-
+  
   return $form;
 }
 
@@ -243,6 +251,12 @@ function media_add_upload_submit($form, 
 
   if ($file) {
     drupal_set_message(t('The file @name was uploaded', array('@name' => $file->filename)));
+    // saving the media file category
+    $cid = (int)str_replace("_", "", $form_state['values']['media_cid']);
+    db_update('file_managed')
+      ->fields(array('media_cid' => $cid))
+      ->condition('fid', $file->fid, '=')
+      ->execute();
   }
   else {
     drupal_set_message(t('An error occurred and no file was uploaded.'), 'error');
@@ -312,9 +326,31 @@ function media_edit($form, $form_state, 
   $form['#attributes']['class'][] = 'media-image-left';
   $form['#attributes']['class'][] = 'media-edit-form';
   
-  $form['preview'] = field_view_field('media', $media, 'file', 'media_preview');
-  $form['preview']['#weight'] = -10;
-  $form['preview']['#suffix'] = '<div class="no-overflow">';
+  // @TODO: Include media_cid into the media object and remove this code
+  $result = db_select('file_managed', 'f')
+    ->fields('f')
+    ->condition('f.fid', $media->fid, '=')
+    ->execute()
+    ->fetchObject();
+  $media->media_cid = $result->media_cid;
+  
+  $form['image'] = array(
+  	'#type' => 'fieldset',
+  	'#title' => t('Edit Media File'),
+
+    'media_cid' => array(
+      '#type' => 'select',
+      '#title' => t('Media File Category'),
+      '#options' => media_get_categories_hierarchy(),
+      '#default_value' => "_" . $media->media_cid,
+      '#weight' => 5,
+      '#description' => t('Select a category this file should be put in'))
+  
+  );
+  
+  $form['image']['preview'] = field_view_field('media', $media, 'file', 'media_preview');
+  $form['image']['preview']['#weight'] = 0;
+  $form['image']['preview']['#suffix'] = '<div class="no-overflow">';
 
   // Add the buttons.
   $form['actions'] = array('#type' => 'actions');
@@ -353,6 +389,13 @@ function media_edit_submit($form, &$form
   $media = media_load($form_state['values']['fid']);
   field_attach_submit('media', $media, $form, $form_state);
   media_save($media);
+  //
+  $cid = (int)str_replace("_", "", $form_state['values']['media_cid']);
+    db_update('file_managed')
+      ->fields(array('media_cid' => $cid))
+      ->condition('fid', $media->fid, '=')
+      ->execute();
+  //
   $form_state['redirect'] = 'media/' . $media->fid;
 }
 
@@ -368,6 +411,7 @@ function media_edit_delete_submit($form,
 
 function media_add_remote($form, &$form_state) {
   // Totally prototyping code to show designs.
+  die("ups");
   $form['sources'] = array(
     '#type' => 'vertical_tabs',
     '#title' => 'Sources',
@@ -377,8 +421,7 @@ function media_add_remote($form, &$form_
     '#type' => 'fieldset',
     '#title' => 'Paste URL or embed code',
   );
-
-
+  
   $providers = '';
   $providers .= '<img style="height:50px; margin:20px" src="http://www.macuser.com/2008/10/09/top_youtube_logo_31_Dec_06.jpg">';
   $providers .= '<img style="height:50px; margin:20px" src="http://jasonhilldesign.com/FlikrLogo.jpg">';
@@ -408,6 +451,13 @@ function media_add_remote($form, &$form_
   $form['sources']['youtube']['stupid'] = array(
     '#markup' => $boxes,
   );
+  
+  $form['media_cid'] = array(
+      '#type' => 'select',
+      '#title' => t('File Category'),
+      '#options' => media_get_categories_hierarchy(),
+      '#description' => t('Select a category this file should be put in')
+  );
 
   $form['submit'] = array(
     '#type' => 'submit',
Index: media.theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.theme.inc,v
retrieving revision 1.14
diff -u -p -r1.14 media.theme.inc
--- media.theme.inc	26 Oct 2010 22:45:53 -0000	1.14
+++ media.theme.inc	5 Nov 2010 16:07:31 -0000
@@ -322,3 +322,28 @@ function theme_media_formatter_large_ico
   $icon = file_icon_path((object)$file, $icon_dir);
   return theme('image', array('path' => $icon));
 }
+
+/**
+ * 
+ * 
+ * Enter description here ...
+ * @param unknown_type $variables
+ */
+function theme_media_category_hierarchy_select($variables)
+{
+  //
+  $categories = $variables['categories'];
+  $skip_categories = isset($variables['skip_categories']) ? $variables['skip_categories'] : array();
+  //
+  $list = array();
+  //
+  foreach($categories as $category)
+  {
+  	//
+  	$pad = (($category->depth * 2) + strlen($category->name));
+    $list['_' . $category->tid] = str_pad($category->name, $pad, "..", STR_PAD_LEFT); 
+  }
+  //
+  return $list;
+  //
+}
Index: media.types.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/media.types.inc,v
retrieving revision 1.12
diff -u -p -r1.12 media.types.inc
--- media.types.inc	3 Sep 2010 19:04:53 -0000	1.12
+++ media.types.inc	5 Nov 2010 16:07:31 -0000
@@ -172,6 +172,26 @@ function media_type_get_types() {
 }
 
 /**
+ * Loads just the labels of the types keyed by names.
+ * Used for the filter form
+ * 
+ * @return array 
+ * Media Types (labels only) keyed by names
+ */
+function media_type_get_type_names()
+{
+  $temp = media_type_get_types();
+  $types = array();
+  
+  foreach($temp as $key=>$value)
+  {
+  	$types[$value->name] = $value->label;
+  }
+  
+  return $types;
+}
+
+/**
  *  Create the basic class and defaults for a media entity bundle type.
  */
 function media_type_set_defaults($info) {
@@ -321,7 +341,7 @@ else {
       // Conditions using the = (equals) operator.
       $normal_conditions = array();
       $normal_conditions['status'] = TRUE;
-
+      
       $this->start = $start;
       $this->limit = $limit;
 
Index: css/media.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/css/media.css,v
retrieving revision 1.22
diff -u -p -r1.22 media.css
--- css/media.css	26 Oct 2010 14:55:15 -0000	1.22
+++ css/media.css	5 Nov 2010 16:07:31 -0000
@@ -381,4 +381,10 @@ a.button {
   margin: 10px 5px 0 0;
 }
 
+.media-filter-select
+{
+	width: 200px;
+	height: 100px;
+}	
+
 /* @end media format form */
\ No newline at end of file
Index: javascript/media-admin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/javascript/media-admin.js,v
retrieving revision 1.16
diff -u -p -r1.16 media-admin.js
--- javascript/media-admin.js	14 Sep 2010 18:25:39 -0000	1.16
+++ javascript/media-admin.js	5 Nov 2010 16:07:31 -0000
@@ -105,7 +105,7 @@ Drupal.behaviors.mediaAdmin = {
   // edit-options panel.
   showOrHideEditOptions: function() {
     var fieldset = $('#edit-options');
-    if (!$('#media-admin input[type=checkbox]:checked').size()) {
+    if (!$('#media-admin input[type=checkbox]:checked:not(.media-filter)').size()) {
       fieldset.slideUp('fast');
     }
     else {
Index: modules/media_internet/media_internet.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/modules/media_internet/media_internet.module,v
retrieving revision 1.7
diff -u -p -r1.7 media_internet.module
--- modules/media_internet/media_internet.module	25 Oct 2010 23:50:37 -0000	1.7
+++ modules/media_internet/media_internet.module	5 Nov 2010 16:07:31 -0000
@@ -59,6 +59,12 @@ function media_internet_add($form, &$for
     '#maxlength' => 2083,
   );
   
+  $form['media_cid'] = array(
+      '#type' => 'select',
+      '#title' => t('File Category'),
+      '#options' => media_get_categories_hierarchy(),
+      '#description' => t('Select a category this file should be put in')
+  );
   
   // @todo:
   // Add live previews back (currently broken)
@@ -186,6 +192,14 @@ function media_internet_add_submit($form
     form_set_error('url', 'Unknown error: unable to add file, please check URL / Embed code and try again ' . $embed_code);
     return;
   }
+  else {
+  	// saving the media file category
+    $cid = (int)str_replace("_", "", $form_state['values']['media_cid']);
+    db_update('file_managed')
+      ->fields(array('media_cid' => $cid))
+      ->condition('fid', $file->fid, '=')
+      ->execute();
+  }
 
   $form_state['redirect'] = array('media/browser', array('query' => array('render' => 'media-popup', 'fid' => $file->fid)));
 }
