--- video_image.module.original	2007-02-18 06:45:47.000000000 -0800
+++ video_image.module	2007-06-15 09:41:23.000000000 -0700
@@ -61,6 +61,12 @@ function video_image_admin_settings() {
       '#title' => t('Promote the thumbnails to the front page'),
       '#default_value' => _video_image_promote_thumbnails(),
     );
+  $form['video_image_remove_old_thumbnail'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Remove Old Thumbnail'),
+      '#default_value' => variable_get('video_image_remove_old_thumbnail', false),
+      '#description' => t('If you change the thumbnail on a video, then the old thumbnail will be deleted.'),
+  );
     
   return system_settings_form($form);
 }
@@ -71,20 +77,28 @@ function video_image_admin_settings() {
 function video_image_form_alter($form_id, &$form) {
 
   if($form_id == 'video_node_form') {
-
     $node = $form['#node'];
+    
     $value = ($node->new_image) ? '#value' : '#default_value';
     $form['iid'] = array('#type' => 'hidden', $value => $node->iid);
-
+    
     if (function_exists('_image_check_settings')) {
       _image_check_settings();
+      
+      $collapsed = TRUE;
+      if($node->image) {
+        $collapsed = FALSE;
+      }
+      
       $form['#attributes'] = array("enctype" => "multipart/form-data");
-
-     
-      $form['image'] = array('#type' => 'fieldset', '#title' => t('Image thumbnails'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -17, '#description' => t('Use this form to upload an image.'));
       
+      
+      $form['image'] = array('#type' => 'fieldset', '#title' => t('Image thumbnails'), '#collapsible' => TRUE, '#collapsed' => $collapsed, '#weight' => -17, '#description' => t('Use this form to upload an image.'));
+      if($node->image) {
+        $form['image']['current_image'] = array('#type'=>'markup', '#value' => '<img src="'. file_create_url($node->image->images['thumbnail']) .'" align="right" />');
+      }
       $form['image']['image'] = array('#type' => 'file', '#title' => t('Image'));
-      $form['image']['image_title'] = array('#type' => 'textfield', '#title' => t('Image title'), '#default_value' => $node->image->image_title);
+      $form['image']['image_title'] = array('#type' => 'textfield', '#title' => t('Image title'), '#default_value' => $node->image->title);
     }
   }
 
@@ -97,10 +111,14 @@ function video_image_form_alter($form_id
 function video_image_nodeapi(&$node, $op, $teaser) {
   if($node->type == 'video') {
     switch ($op) {
-      case 'load': 
+      case 'load':
+        $image = node_load(array('nid'=>$node->serial_data['iid']));
         $output['iid'] = $node->serial_data['iid'];
+        $output['image'] = $image;
+        
         return $output;
       case 'submit':
+      
         if (variable_get('video_image_auto_thumbnail_debug', false) && variable_get('video_image_auto_thumbnail', false)) {
           drupal_set_message(t('video_image_nodeapi: prepare: ready to thumbnail image'));
         }
@@ -116,7 +134,10 @@ function video_image_nodeapi(&$node, $op
           $field_name = _video_ffmpeg_helper_auto_thumbnail($node);
         }
         else {
-          $image->title = $_POST['edit']['image_title'];
+          $image->title = $_POST['image_title'];
+          if(!strlen(trim($image->title))) {
+		$image->title = $_POST['title']." thumbnail";
+          }
           $field_name = 'image';
         }
         image_prepare($image, $field_name);
@@ -129,6 +150,11 @@ function video_image_nodeapi(&$node, $op
             // needed to set the correct status and promote values if the user does not have enought permissions. Is there a better solution???
             db_query('UPDATE {node} SET status = %d, promote = %d WHERE nid = %d AND vid = %d', _video_image_publish_thumbnails(), _video_image_promote_thumbnails(), $image->nid, $image->vid); 
             
+            //if the image has been changed, then delete the old one
+            if($image->nid != $_POST['iid'] && ctype_digit($_POST['iid']) && variable_get('video_image_remove_old_thumbnail', false)) {
+              node_delete($_POST['iid']);
+            }
+            
             $node->iid = $node->serial_data['iid'] = $image->nid;
             $_SESSION['video_upload_file']->iid = $image->nid;
             $node->new_image = TRUE;
