diff -urpN node_media-5-x/CREDITS node_media/CREDITS
--- node_media-5-x/CREDITS	1969-12-31 16:00:00.000000000 -0800
+++ node_media/CREDITS	2008-04-22 17:46:14.000000000 -0700
@@ -0,0 +1,4 @@
+Node Media the new version of Node Media(by Stefano Mallozzi), wich was renamed in order provide a best definition according to new functionalities, because we consider media as: images, video and sound.
+
+Fernando Paredes GarcÌÐa
+Co-developer of Node Media
diff -urpN node_media-5-x/LICENSE.txt node_media/LICENSE.txt
--- node_media-5-x/LICENSE.txt	1969-12-31 16:00:00.000000000 -0800
+++ node_media/LICENSE.txt	2008-04-22 17:46:16.000000000 -0700
@@ -0,0 +1,274 @@
+GNU GENERAL PUBLIC LICENSE
+
+              Version 2, June 1991
+
+Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
+Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
+verbatim copies of this license document, but changing it is not allowed.
+
+                  Preamble
+
+The licenses for most software are designed to take away your freedom to
+share and change it. By contrast, the GNU General Public License is
+intended to guarantee your freedom to share and change free software--to
+make sure the software is free for all its users. This General Public License
+applies to most of the Free Software Foundation's software and to any other
+program whose authors commit to using it. (Some other Free Software
+Foundation software is covered by the GNU Library General Public License
+instead.) You can apply it to your programs, too.
+
+When we speak of free software, we are referring to freedom, not price. Our
+General Public Licenses are designed to make sure that you have the
+freedom to distribute copies of free software (and charge for this service if
+you wish), that you receive source code or can get it if you want it, that you
+can change the software or use pieces of it in new free programs; and that
+you know you can do these things.
+
+To protect your rights, we need to make restrictions that forbid anyone to
+deny you these rights or to ask you to surrender the rights. These restrictions
+translate to certain responsibilities for you if you distribute copies of the
+software, or if you modify it.
+
+For example, if you distribute copies of such a program, whether gratis or for
+a fee, you must give the recipients all the rights that you have. You must make
+sure that they, too, receive or can get the source code. And you must show
+them these terms so they know their rights.
+
+We protect your rights with two steps: (1) copyright the software, and (2)
+offer you this license which gives you legal permission to copy, distribute
+and/or modify the software.
+
+Also, for each author's protection and ours, we want to make certain that
+everyone understands that there is no warranty for this free software. If the
+software is modified by someone else and passed on, we want its recipients
+to know that what they have is not the original, so that any problems
+introduced by others will not reflect on the original authors' reputations.
+
+Finally, any free program is threatened constantly by software patents. We
+wish to avoid the danger that redistributors of a free program will individually
+obtain patent licenses, in effect making the program proprietary. To prevent
+this, we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+The precise terms and conditions for copying, distribution and modification
+follow.
+
+           GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
+               MODIFICATION
+
+0. This License applies to any program or other work which contains a notice
+placed by the copyright holder saying it may be distributed under the terms
+of this General Public License. The "Program", below, refers to any such
+program or work, and a "work based on the Program" means either the
+Program or any derivative work under copyright law: that is to say, a work
+containing the Program or a portion of it, either verbatim or with
+modifications and/or translated into another language. (Hereinafter, translation
+is included without limitation in the term "modification".) Each licensee is
+addressed as "you".
+
+Activities other than copying, distribution and modification are not covered
+by this License; they are outside its scope. The act of running the Program is
+not restricted, and the output from the Program is covered only if its contents
+constitute a work based on the Program (independent of having been made
+by running the Program). Whether that is true depends on what the Program
+does.
+
+1. You may copy and distribute verbatim copies of the Program's source
+code as you receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice and
+disclaimer of warranty; keep intact all the notices that refer to this License
+and to the absence of any warranty; and give any other recipients of the
+Program a copy of this License along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and you
+may at your option offer warranty protection in exchange for a fee.
+
+2. You may modify your copy or copies of the Program or any portion of it,
+thus forming a work based on the Program, and copy and distribute such
+modifications or work under the terms of Section 1 above, provided that you
+also meet all of these conditions:
+
+a) You must cause the modified files to carry prominent notices stating that
+you changed the files and the date of any change.
+
+b) You must cause any work that you distribute or publish, that in whole or in
+part contains or is derived from the Program or any part thereof, to be
+licensed as a whole at no charge to all third parties under the terms of this
+License.
+
+c) If the modified program normally reads commands interactively when run,
+you must cause it, when started running for such interactive use in the most
+ordinary way, to print or display an announcement including an appropriate
+copyright notice and a notice that there is no warranty (or else, saying that
+you provide a warranty) and that users may redistribute the program under
+these conditions, and telling the user how to view a copy of this License.
+(Exception: if the Program itself is interactive but does not normally print such
+an announcement, your work based on the Program is not required to print
+an announcement.)
+
+These requirements apply to the modified work as a whole. If identifiable
+sections of that work are not derived from the Program, and can be
+reasonably considered independent and separate works in themselves, then
+this License, and its terms, do not apply to those sections when you distribute
+them as separate works. But when you distribute the same sections as part
+of a whole which is a work based on the Program, the distribution of the
+whole must be on the terms of this License, whose permissions for other
+licensees extend to the entire whole, and thus to each and every part
+regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest your rights to
+work written entirely by you; rather, the intent is to exercise the right to
+control the distribution of derivative or collective works based on the
+Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of a
+storage or distribution medium does not bring the other work under the scope
+of this License.
+
+3. You may copy and distribute the Program (or a work based on it, under
+Section 2) in object code or executable form under the terms of Sections 1
+and 2 above provided that you also do one of the following:
+
+a) Accompany it with the complete corresponding machine-readable source
+code, which must be distributed under the terms of Sections 1 and 2 above
+on a medium customarily used for software interchange; or,
+
+b) Accompany it with a written offer, valid for at least three years, to give
+any third party, for a charge no more than your cost of physically performing
+source distribution, a complete machine-readable copy of the corresponding
+source code, to be distributed under the terms of Sections 1 and 2 above on
+a medium customarily used for software interchange; or,
+
+c) Accompany it with the information you received as to the offer to distribute
+corresponding source code. (This alternative is allowed only for
+noncommercial distribution and only if you received the program in object
+code or executable form with such an offer, in accord with Subsection b
+above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source code
+means all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation and
+installation of the executable. However, as a special exception, the source
+code distributed need not include anything that is normally distributed (in
+either source or binary form) with the major components (compiler, kernel,
+and so on) of the operating system on which the executable runs, unless that
+component itself accompanies the executable.
+
+If distribution of executable or object code is made by offering access to
+copy from a designated place, then offering equivalent access to copy the
+source code from the same place counts as distribution of the source code,
+even though third parties are not compelled to copy the source along with the
+object code.
+
+4. You may not copy, modify, sublicense, or distribute the Program except as
+expressly provided under this License. Any attempt otherwise to copy,
+modify, sublicense or distribute the Program is void, and will automatically
+terminate your rights under this License. However, parties who have received
+copies, or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+5. You are not required to accept this License, since you have not signed it.
+However, nothing else grants you permission to modify or distribute the
+Program or its derivative works. These actions are prohibited by law if you
+do not accept this License. Therefore, by modifying or distributing the
+Program (or any work based on the Program), you indicate your acceptance
+of this License to do so, and all its terms and conditions for copying,
+distributing or modifying the Program or works based on it.
+
+6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the original
+licensor to copy, distribute or modify the Program subject to these terms and
+conditions. You may not impose any further restrictions on the recipients'
+exercise of the rights granted herein. You are not responsible for enforcing
+compliance by third parties to this License.
+
+7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues), conditions
+are imposed on you (whether by court order, agreement or otherwise) that
+contradict the conditions of this License, they do not excuse you from the
+conditions of this License. If you cannot distribute so as to satisfy
+simultaneously your obligations under this License and any other pertinent
+obligations, then as a consequence you may not distribute the Program at all.
+For example, if a patent license would not permit royalty-free redistribution
+of the Program by all those who receive copies directly or indirectly through
+you, then the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply and
+the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any patents or
+other property right claims or to contest validity of any such claims; this
+section has the sole purpose of protecting the integrity of the free software
+distribution system, which is implemented by public license practices. Many
+people have made generous contributions to the wide range of software
+distributed through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing to
+distribute software through any other system and a licensee cannot impose
+that choice.
+
+This section is intended to make thoroughly clear what is believed to be a
+consequence of the rest of this License.
+
+8. If the distribution and/or use of the Program is restricted in certain
+countries either by patents or by copyrighted interfaces, the original copyright
+holder who places the Program under this License may add an explicit
+geographical distribution limitation excluding those countries, so that
+distribution is permitted only in or among countries not thus excluded. In such
+case, this License incorporates the limitation as if written in the body of this
+License.
+
+9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will be
+similar in spirit to the present version, but may differ in detail to address new
+problems or concerns.
+
+Each version is given a distinguishing version number. If the Program specifies
+a version number of this License which applies to it and "any later version",
+you have the option of following the terms and conditions either of that
+version or of any later version published by the Free Software Foundation. If
+the Program does not specify a version number of this License, you may
+choose any version ever published by the Free Software Foundation.
+
+10. If you wish to incorporate parts of the Program into other free programs
+whose distribution conditions are different, write to the author to ask for
+permission. For software which is copyrighted by the Free Software
+Foundation, write to the Free Software Foundation; we sometimes make
+exceptions for this. Our decision will be guided by the two goals of
+preserving the free status of all derivatives of our free software and of
+promoting the sharing and reuse of software generally.
+
+               NO WARRANTY
+
+11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
+PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
+STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
+WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
+PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
+NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
+AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
+ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
+LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
+SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF THE USE OR INABILITY TO USE THE
+PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
+OR DATA BEING RENDERED INACCURATE OR LOSSES
+SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
+PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
+IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGES.
+
+          END OF TERMS AND CONDITIONS
Binary files node_media-5-x/img/sound_icon.gif and node_media/img/sound_icon.gif differ
Binary files node_media-5-x/img/video_icon.gif and node_media/img/video_icon.gif differ
diff -urpN node_media-5-x/node-example.tpl.php node_media/node-example.tpl.php
--- node_media-5-x/node-example.tpl.php	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node-example.tpl.php	2008-04-22 17:46:17.000000000 -0700
@@ -0,0 +1,32 @@
+<div class="node<?php if ($sticky) { print " sticky"; } ?>">
+    <?php if ($picture) {
+      print $picture;
+    }?>
+    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
+    <span class="submitted"><?php print $submitted?></span>
+    <span class="taxonomy"><?php print $terms?></span>
+
+  <div class="content">
+    <table class="node-content-table"><tr>
+    <td class="node-body">
+	  <?php print $content ?>
+	</td>
+
+    <?php if ($node->node_images) { ?>
+  	  <!-- Node images -->
+	  <td class="node-images" rowspan="2">
+	    <?php print $node->node_images ?><?php ?>
+		<div style="text-align:center;">
+		  <a href="<?php print url('node/'.$node->nid.'/image_gallery'); ?>">Gallery</a>
+		</div>
+	  </td>
+	<?php }?>
+
+	</tr><tr>
+    </tr></table>
+  </div>
+
+  <?php if ($links) { ?>
+    <div class="links">&raquo; <?php print $links?></div>
+  <?php }?>
+</div>
diff -urpN node_media-5-x/node_media.css node_media/node_media.css
--- node_media-5-x/node_media.css	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.css	2008-04-22 17:46:17.000000000 -0700
@@ -0,0 +1,33 @@
+#mediaslideshow-table table {
+  margin: 0;
+  border: 0;
+}
+#mediaslideshow-table td {
+  vertical-align: top;
+  padding-right: 10px;
+  text-align: center;
+  vertical-align: top;
+}
+#mediaslideshow-table .header {
+  margin-bottom: 5px;
+}
+#mediaslideshow-table p.description {
+  margin-top: 5px;
+}
+#mediaslideshow-table img.slideshow-thumb {
+  border: 0;
+}
+#mediaslideshow-table img.active {
+  border: 2px solid #888;
+}
+#mediaslideshow-table .thumb-description {
+  width: 120px;
+  white-space: wrap;
+  margin-bottom: 5px;
+}
+.mediapolaroid {
+  padding: 15px 15px 55px 15px;
+  border: 1px solid #000;
+  background: #fff;
+  text-align: center;
+}
diff -urpN node_media-5-x/node_media.info node_media/node_media.info
--- node_media-5-x/node_media.info	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.info	2008-04-22 17:46:18.000000000 -0700
@@ -0,0 +1,14 @@
+name = Node Media
+description = "Allows users to upload media(images, videos and sounds) and associate them to nodes."
+dependencies[] = upload
+
+core = 6.x
+version = "5.x-0.x-dev"
+project = "node_media"
+
+
+; Information added by drupal.org packaging script on 2007-12-31
+version = "5.x-0.x-dev"
+project = "node_media"
+datestamp = "1199102790"
+
diff -urpN node_media-5-x/node_media.install node_media/node_media.install
--- node_media-5-x/node_media.install	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.install	2008-04-22 17:59:11.000000000 -0700
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Implementation of hook_install().
+ */
+function node_media_install() {
+  drupal_install_schema('node_media');
+}
+
+/**
+ * Implementation of hook_schema
+ */
+function node_media_schema() {
+  $schema['node_media'] = array(
+    'fields' => array(
+      'id' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'nid' => array(
+        'type' => 'int',
+        'length' => '10',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'uid' => array(
+        'type' => 'int',
+        'length' => '10',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'filename' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'filepath' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'filemime' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'filesize' => array(
+        'type' => 'int',
+        'length' => '10',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'thumbpath' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'thumbsize' => array(
+        'type' => 'int',
+        'length' => '10',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'status' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'length' => '1',
+        'not null' => TRUE,
+        'default' => 1,
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'length' => '1',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'description' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'type' => array(
+        'type' => 'int',
+        'length' => '1',
+        'not null' => FALSE,
+      ),
+    ),
+    'indexes' => array(
+      'uid' => array('uid'),
+      'nid' => array('nid'),
+      'status' => array('status'),
+    ),
+    'primary key' => array('id'),
+  );
+  return $schema;
+}
+
+/** 
+ * implementation of hook_uninstall()
+ */
+function node_media_uninstall() {
+  drupal_uninstall_schema('node_media');
+}
diff -urpN node_media-5-x/node_media.js node_media/node_media.js
--- node_media-5-x/node_media.js	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.js	2008-04-22 17:46:19.000000000 -0700
@@ -0,0 +1,61 @@
+$(document).ready(function() {
+  if (Drupal.settings.mediaslideshow) {
+    Drupal.mediaslideshowAttach();
+  }  
+});
+
+Drupal.mediaslideshowAttach = function() {
+  for (var node in Drupal.settings.mediaslideshow) {
+    var mediaslideshow = Drupal.settings.mediaslideshow[node], container = $('.mediaslideshow-' + node);
+    
+    function preloadImages(i) {
+      var n = mediaslideshow.images[++i];
+      if (mediaslideshow.current != i) {
+        if (n) {
+          n.image = $('<img />').src(n.src).load(function() { preloadImages(i); });
+        } else preloadImages(0);
+      }
+    }
+    
+    function updatemediaslideshow(previous) {
+      if (mediaslideshow.current != previous) {
+	    $('#thumb-' + previous).removeClass('active');
+	    $('#thumb-' + mediaslideshow.current).addClass('active');
+	  }
+	  
+	  var current = mediaslideshow.images[mediaslideshow.current];
+      current.title = current.title || '';
+      current.description = current.description || '';
+      current.href = current.href || '#';
+
+      container.        
+        find('.mediapolaroid').src(current.src).css({ opacity: 0.8 }).animate({ opacity: 1, width: current.width, height: current.height }).end().
+        find('.title').html(current.title).end().find('.description').html(current.description).end().
+        find('.link').href(current.href).end().find('.current').html(mediaslideshow.current).end();
+      return false;
+    }
+
+    container.find('.previous').click(function() {
+	  var current = mediaslideshow.current;
+	  if(!(mediaslideshow.images[--mediaslideshow.current])) mediaslideshow.current = mediaslideshow.total;
+      return updatemediaslideshow(current);
+    }).end().
+    
+    find('.next').click(function() {
+	  var current = mediaslideshow.current;
+      if(!(mediaslideshow.images[++mediaslideshow.current])) mediaslideshow.current = 1;
+      return updatemediaslideshow(current);
+    }).end();
+    
+    $('.mediaslideshow-thumb').each(function () {
+	  $(this).click(function() {
+		var previous = mediaslideshow.current;
+		mediaslideshow.current = this.id.substr(6, this.id.length-6);
+		return updatemediaslideshow(previous);
+      });
+    });
+
+    preloadImages(mediaslideshow.current);	
+	$('#thumb-' + mediaslideshow.current).addClass('active');
+  }
+}
diff -urpN node_media-5-x/node_media.module node_media/node_media.module
--- node_media-5-x/node_media.module	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.module	2008-04-26 06:13:35.000000000 -0700
@@ -0,0 +1,1010 @@
+<?php
+/**
+ * @file
+ * This module will add "Images" tab, "Videos" tab and "Sounds" tab to nodes, allowing users to upload media(images, video and sounds) and associate them with the current node.
+ * Requires upload.module
+ * The hook_node_media() allows to conditionally disable media for the specific node
+ */
+
+define('NODE_MEDIA_IMAGE', 0);
+define('NODE_MEDIA_VIDEO', 1);
+define('NODE_MEDIA_SOUND', 2);
+
+
+/**
+ * Implementation of hook_perm().
+ */
+
+function node_media_perm() {
+  return array('create node media', 'administer node media');
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function node_media_menu() {
+  global $user;
+  $items = array();
+  
+  $items['admin/settings/node_media'] = array(
+    'title' => t('node media'),
+    'description' => t('Control how to upload node media.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('node_media_admin_settings'),
+    'access arguments' => array('administer site configuration'),
+  );
+  $items['node_media/js'] = array(
+    'page callback' => '_node_media_js',
+    'access arguments' => array('create node media'),
+    'file' => 'node_media.pages.inc',
+    'type' => MENU_CALLBACK
+  );
+  $items['node_media_save/js'] = array(
+    'page callback' => 'node_media_save_js',
+    'access arguments' => array('create node media'),
+    'file' => 'node_media.pages.inc',
+    'type' => MENU_CALLBACK
+  );
+  $items['node/%node/media'] = array(
+    'title' => t('Media'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('_node_media_edit_form', 1),
+    'access callback' => 'node_media_upload_access',
+    'access arguments' => array(1),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2
+  );
+  
+  $items['node/%node/image_gallery'] = array(
+    'title' => t('Image gallery'),
+    'page callback' => '_node_media_gallery',
+    'page arguments' => array(1),
+    'access callback' => 'node_access',
+    'access arguments' => array('view', '$node'),
+    'file' => 'node_media.pages.inc',
+    'type' => variable_get('node_media_gallery_tabs_'.$node->type, TRUE) ? MENU_LOCAL_TASK : MENU_CALLBACK,
+  );
+  $items['node/%node/video_gallery'] = array(
+    'title' => t('Video gallery'),
+    'page callback' => '_node_media_gallery',
+    'page arguments' => array(1),
+    'access callback' => 'node_access',
+    'access arguments' => array('view', '$node'),
+    'file' => 'node_media.pages.inc',
+    'type' => variable_get('node_media_gallery_tabs_'.$node->type, TRUE) ? MENU_LOCAL_TASK : MENU_CALLBACK,
+  );
+  $items['node/%node/sound_gallery'] = array(
+    'title' => t('Sound gallery'),
+    'page callback' => '_node_media_gallery',
+    'page arguments' => array(1),
+    'access callback' => 'node_access',
+    'access arguments' => array('view', '$node'),
+    'file' => 'node_media.pages.inc',
+    'type' => variable_get('node_media_gallery_tabs_'.$node->type, TRUE) ? MENU_LOCAL_TASK : MENU_CALLBACK,
+  );
+  return $items;
+}
+
+function node_media_upload_access($node) {
+  global $user;
+  return user_access('create node media') && node_access('update', $node);
+}
+
+/**
+ * Implementation of hook_theme()
+ */
+function node_media_theme() {
+  return array(
+     'node_media_list' => array(
+       'arguments' => array('form' => NULL),
+     ),
+     'node_media_gallery' => array(
+       'arguments' => array('element' => NULL),
+     ),
+     'node_media_gallery_thumbs' => array(
+       'arguments' => array('thumbs' => NULL, 'cols' => 2),
+     ),
+     'node_media_view' => array(
+       'arguments' => array('node' => NULL, 'teaser' => NULL, 'page' => NULL, 'format' => NULL),
+     ),
+  );
+}
+
+
+/**
+ * implementation of hook_form_alter()
+ */
+function node_media_form_alter($form, &$form_state, $form_id) {
+  $type = $form['#node_type']->type;
+  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
+    // radio button in the node's content type configuration page
+    _node_media_check_settings();
+    $form['node_media'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('node media'),
+      '#collapsible' => TRUE,
+    );
+    $form['node_media']['node_media_position'] = array(
+      '#type' => 'radios',
+      '#title' => t('Position'),
+      '#default_value' => variable_get('node_media_position_'.$type, 'hide'),
+      '#options' => array('hide' => t('Do not show'), 'above' => t('Show above node body'), 'below' => t('Show below node body'), 
+        'node_template' => t('Manually set in node template by variable $node->node_media')),
+      '#description' => t('The position of images in the node view.'),
+    );
+    $form['node_media']['node_media_gallery_link'] = array(
+      '#type' => 'radios',
+      '#title' => t('Link to image gallery'),
+      '#default_value' => variable_get('node_media_gallery_link_'.$type, TRUE),
+      '#options' => array(t('Do not show'), t('Show')),
+      '#description' => t('Choose whether to show or not the link to the image gallery.'),
+    );
+    $form['node_media']['node_media_gallery_tabs'] = array(
+      '#type' => 'radios',
+      '#title' => t('Media galleries tabs'),
+      '#default_value' => variable_get('node_media_gallery_tabs_'.$type, TRUE),
+      '#options' => array(t('Do not show'), t('Show')),
+      '#description' => t('Choose whether to show or not the tabs to the media galleries.'),
+    );
+    $form['node_media']['node_media_gallery_display_node_details'] = array(
+      '#type' => 'radios',
+      '#title' => t('Node details in media galleries'),
+      '#default_value' => variable_get('node_media_gallery_display_node_details_'.$type, TRUE),
+      '#options' => array(t('Do not show'), t('Show')),
+      '#description' => t('Choose whether to show or not the node details into media galleries.'),
+    );
+    $form['node_media']['node_media_teaser_images'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Number of images in node teaser'),
+      '#default_value' => variable_get('node_media_teaser_images_'.$type, 2),
+      '#size' => 5,
+      '#maxlength' => 2,
+      '#description' => t('The maximum number of images to show in the node teaser. 0 will not show images. Leave blank to show all images.'),
+    );
+    $form['node_media']['node_media_body_images'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Number of images in node body'),
+      '#size' => 5,
+      '#maxlength' => 2,
+      '#default_value' => variable_get('node_media_body_images_'.$type, NULL),
+      '#description' => t('The maximum number of images to show in the node body. 0 will not show images. Leave blank to show all images.'),
+    );
+    $form['node_media']['node_media_teaser_format'] = array(
+      '#type' => 'radios',
+      '#title' => t('Image format in node teaser'),
+      '#default_value' => variable_get('node_media_teaser_format_'.$type, 'thumbs'),
+      '#options' => array('thumbs' => t('Thumbnails'), 'fullsize' => t('Full size images')),
+      '#description' => t('Image format in node teaser.'),
+    );
+    $form['node_media']['node_media_body_format'] = array(
+      '#type' => 'radios',
+      '#title' => t('Image format in node body'),
+      '#default_value' => variable_get('node_media_body_format_'.$type, 'thumbs'),
+      '#options' => array('thumbs' => t('Thumbnails'), 'fullsize' => t('Full size images')),
+      '#description' => t('Image format in node body.'),
+    );
+    $form['submit']['#weight'] = 30;
+    $form['delete']['#weight'] = 31;
+    $form['reset']['#weight'] = 32;
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function node_media_nodeapi(&$node, $op, $teaser, $page) {
+  // test if images are allowed for this node
+  /*
+  if ($op == 'load' || $op == 'view') {
+    if (variable_get('node_media_position_'.$node->type, 'hide') == 'hide') return;
+
+    // fire an additional hook for the specific node type
+    // i.e. node media might be a pro feature, so only subscribed users can view them
+    // if the hook is not present in the node type module, images are loaded by default
+    $show = module_invoke($node->type, 'node_media', $op, $node);
+    if ($show === FALSE) return;
+  }
+  */
+  switch ($op) {
+    case 'load':
+      // load node media for the current node
+      $sql = db_query('SELECT * FROM {node_media} WHERE nid=%d AND status=1 ORDER BY type,weight', $node->nid);
+      while ($r = db_fetch_object($sql)) {
+        $node->node_media[$r->type][$r->id] = $r;
+      }
+      break;
+
+    case 'insert':
+      if (user_access('create node media') && node_access('update', $node) &&
+        variable_get('node_media_position_'.$node->type, 'hide') != 'hide') {
+          drupal_set_message(t('Click the <strong>media</strong> tab to add images, videos and sounds to this node.',
+            array(
+              '!images' => l(t('images'), 'node/'.$node->nid.'/images')/*,
+              '!videos' => l(t('videos'), 'node/'.$node->nid.'/videos'),
+              '!sounds' => l(t('sounds'), 'node/'.$node->nid.'/sounds')*/
+            )));
+      }
+      break;
+
+    case 'delete':
+      // Delete image and thumbnail files
+      $sql = db_query('SELECT filepath, thumbpath FROM {node_media} WHERE nid=%d', $node->nid);
+      while ($r = db_fetch_object($sql)) {
+        file_delete($r->filepath);
+        file_delete($r->thumbpath);
+      }
+      // Delete all images associated with the node
+      db_query('DELETE FROM {node_media} WHERE nid=%d', $node->nid);
+      break;
+
+    case 'view':
+      if (empty($node->node_media)) return;
+
+      // search for a themed view for the current node type
+      $nodetype_function = 'theme_'.$node->type.'_node_media_view';
+      if (function_exists($nodetype_function)) {
+        $output = $nodetype_function($node, $teaser, $page);
+      }
+      else {
+        // use the default theme function
+        $media = theme('node_media_view', $node, $teaser, $page);
+      }
+
+      $output = '<div class="node_media">'. implode('',$media) .'</div>';
+
+      $position = variable_get('node_media_position_'.$node->type, 'hide');
+      switch ($position) {
+        case 'node_template':
+        
+        case 'hide':
+          break;
+
+        case 'above':
+          $node->content['node_media'] = array('#value' => $output, '#weight' => -1);
+          break;
+
+        default:
+          $node->content['node_media'] = array('#value' => $output, '#weight' => 1);
+          break;
+      }
+      return $node;
+  }
+}
+
+/**
+ * Implementation of hook_link().
+ */
+function node_media_link($type, $node = null, $teaser = false) {
+  $links = array();
+
+  if ($type == 'node' && $node->nid && variable_get('node_media_position_'.$node->type, 'hide') != 'hide') {
+    if ($node->node_media[NODE_MEDIA_IMAGE] && variable_get('node_media_gallery_link_'.$node->type, TRUE)) {
+      $links['node_media_image_gallery'] = array(
+        'title' => t('Open the image gallery'),
+        'href' => "node/$node->nid/image_gallery",
+      );
+    }
+    
+    if ($node->node_media[NODE_MEDIA_VIDEO] && variable_get('node_media_gallery_link_'.$node->type, TRUE)) {
+      $links['node_media_video_gallery'] = array(
+        'title' => t('Open the video gallery'),
+        'href' => "node/$node->nid/video_gallery",
+      );
+    }
+    
+    if ($node->node_media[NODE_MEDIA_SOUND] && variable_get('node_media_gallery_link_'.$node->type, TRUE)) {
+      $links['node_media_sound_gallery'] = array(
+        'title' => t('Open the sound gallery'),
+        'href' => "node/$node->nid/sound_gallery",
+      );
+    }
+  }
+
+  return $links;
+}
+
+/**
+ * Implementation of hook_user().
+ */
+function node_media_user($type, &$edit, &$user, $category = NULL) {
+  switch ($type) {
+    case 'delete':
+      // Set uid=0 for images uploaded by the deleted user
+      db_query('UPDATE {node_media} SET uid=0 WHERE uid=%d', $user->uid);
+  }
+}
+
+/**
+ * Implementation of hook_file_download().
+ * Find out if an image is accessible when download method is set to private
+ */
+function node_media_file_download($file) {
+  $path = file_create_path($file);
+  $result = db_query("SELECT * FROM {node_media} WHERE filepath='%s' OR thumbpath='%s'", $path, $path);
+  if ($file = db_fetch_object($result)) {
+    $node = node_load($file->nid);
+    if (node_access('view', $node)) {
+      if ($path == $file->thumbpath) {
+        // update header info if thumb is requested
+        $name = mime_header_encode(basename($file->thumbpath));
+        $size = $file->thumbsize;
+      }
+      else {
+        $name = mime_header_encode($file->filename);
+    $size = $file->filesize;
+      }
+      $type = mime_header_encode($file->filemime);
+      return array(
+        'Content-Type: '. $type .'; name='. $name,
+        'Content-Length: '. $size,
+        'Cache-Control: private'
+      );
+    }
+    else {
+      return -1;
+    }
+  }
+}
+
+
+/************************************************************
+ * Node edit functions
+************************************************************/
+
+/**
+ * Display the page to edit and upload node media.
+ *
+ * @param $node
+ *    the current node
+ * @return
+ *    the node media page.
+ */
+function _node_media_edit_form(&$form_state, $node) {
+  global $user;
+  
+  $form = array();
+  
+  if (!count($node->node_media)) {
+    // Generate image list
+    $result = db_query('SELECT * FROM {node_media} WHERE nid = %d ORDER BY type, weight', $node->nid);
+    while ($asset = db_fetch_object($result)) {
+      $media[$asset->type][$asset->id] = $asset; 
+    }
+  }
+  else {
+    $media = $node->node_media;
+  }
+
+  if (count($media) > 0) {
+    $form = _node_media_list($form_state, $node, $media);
+  }
+  
+  // test if this node can accept new images
+  // i.e. there might be limits to the number of uploaded images for certain node types or user roles
+  // if the hook is not present in the node type module, upload is enabled by default
+  $upload = module_invoke($node->type, 'node_media', 'upload', $node);
+  if ($upload !== FALSE) {
+    $form += _node_media_edit_form_upload($form_state, $node);
+  }
+  $form['#prefix'] = '<div id="attach-wrapper">';
+  $form['#suffix'] = '</div>';
+  drupal_set_title(check_plain($node->title));
+  return $form;
+}
+
+function _node_media_edit_form_upload(&$form_state, $node) {
+  $path = file_directory_path().'/'.variable_get('node_media_path', 'node_media');
+  _node_media_check_directory(NULL, $path);
+  $extensions = variable_get('node_media_extensions', 'jpg jpeg gif png');
+  //die;
+  $form = array();
+
+  // Generate upload form
+  $form['new'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Upload a new media'),
+  );
+  $form['new']['description'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Description'),
+    '#size' => 50,
+    '#maxlength' => 255,
+    '#default_value' => $edit['new']['description'],
+    '#description' => t('Enter a description for the new media, max 255 chars.'),
+    '#prefix' => '<div style="float:left; margin-right:20px;">',
+    '#suffix' => '</div>',
+  );
+  $form['new']['weight'] = array(
+    '#type' => 'weight',
+    '#title' => t('Weight'),
+    '#prefix' => '<div style="float:left; margin-right:20px;">',
+    '#suffix' => '</div><div style="clear:both; height:0.1em;"></div>',
+  );
+  $form['new']['node_media_upload'] = array(
+    '#type' => 'file',
+    '#title' => t('Media file'),
+    '#size' => 50,
+    '#description' => t('Allowed file types: %extensions', array('%extensions' => $extensions)),
+    '#prefix' => '<div style="float:left; margin-right:20px;"></div><div id="attach-hide" style="float:left; margin-right:20px;">',
+    '#suffix' => '</div>',
+  );
+  $form['new']['type'] = array(
+    '#type' => 'select',
+    '#options' => array(NODE_MEDIA_IMAGE => 'Image', NODE_MEDIA_VIDEO => 'Video', NODE_MEDIA_SOUND => 'Sound'),
+    '#title' => t('Type'),
+    '#default_value' => $edit['new']['type'],
+    '#prefix' => '<div style="float:left; margin-right:20px;">',
+    '#suffix' => '</div><div style="clear:both; height:0.1em;"></div>',
+  );
+  $form['new']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Upload'),
+    '#name'=> 'attach',
+    '#ahah' => array(
+      'path' => 'node_media/js',
+      'wrapper' => 'attach-wrapper',
+      'method' => 'replace',
+      'effect' => 'fade',
+      'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
+    ),
+    '#id' => 'attach-button',
+  );
+  // Needed for JS
+  $form['nid'] = array(
+    '#type' => 'hidden',
+    '#value' => $node->nid,
+  );
+
+  $form['#attributes']['enctype'] = 'multipart/form-data';
+  return $form;
+}
+
+/**
+ * Generate a list of images associated to the current node.
+ *
+ * @param $node
+ *    the current node
+ * @param $result
+ *    SQL result containing the node media
+ * @return
+ *    a form representing the image list.
+ */
+function _node_media_list(&$form_state, $node, $media) {
+  global $user;
+  $images = array();
+  $form['rows'] = array('#tree' => TRUE);
+  $delete_access = node_access('delete', $node);
+
+  foreach ($media as $type) {
+    foreach ($type as $id => $asset) {
+      $assets[$id] = $asset;
+      $form['rows'][$asset->id]['description'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $asset->description,
+        '#size' => 30,
+        '#maxlength' => 255,
+      );
+      $form['rows'][$asset->id]['weight'] = array(
+        '#type' => 'weight',
+       '#default_value' => $asset->weight,
+      ); 
+      $form['rows'][$asset->id]['type'] = array(
+       '#type' => 'hidden',
+       '#value' => $asset->type,
+      );
+      
+      // images can be deleted only by users having delete access or users who uploaded the images
+      $disabled = (!$delete_access && $user->uid != $asset->uid);
+      $form['rows'][$asset->id]['delete'] = array('#type' => 'checkbox', '#disabled' => $disabled);
+    }
+  }
+  $form['images'] = array(
+    '#type' => 'value',
+    '#value' => $assets,
+  );
+  
+  $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
+  $form['save'] = array(
+    '#type' => 'submit',
+    '#suffix' => '<div class="clear-block" id="save-status"></div>',
+    '#name' => 'save-changes',
+    '#value' => t('Save changes'),
+    '#ahah' => array(
+      'path' => 'node_media_save/js',
+      'wrapper' => 'attach-wrapper',
+      'method' => 'replace',
+      'effect' => 'fade',
+      'progress' => array('type' => 'bar', 'message' => t('Saving changes...')),
+    ),
+    '#id' => 'save-button',
+  );
+  
+  $form['#theme'] = 'node_media_list';
+
+  // action must be set, otherwise it will be replaced by "node_media/js" (current $_GET['q'] on JS uploads)
+  $form['#action'] = url('node/'.$node->nid.'/media');
+
+  return $form;
+}
+
+/**
+ * Theme node media list.
+ */
+function theme_node_media_list($form) {
+  $header = array('', t('Thumbnail'), t('Description').' / '.t('Path'), t('Size'), t('Weight'), t('Delete'));
+  drupal_add_tabledrag('node-media-attachments', 'order', 'sibling', 'upload-weight');
+ 
+  $rows = array();
+  foreach($form['images']['#value'] as $id => $image) {
+    $form['rows'][$image->id]['#attributes']['class'] = 'upload-weight-'.$id;
+    $row = array();
+    $row[] = '';
+    $row[] = '<img src="'. file_create_url($image->thumbpath). '" />';
+    $row[] = drupal_render($form['rows'][$image->id]['description']).$image->filepath;
+    $row[] = array('data' => format_size($image->filesize));
+    if (isset($form['rows'][$image->id]['weight'])) {
+      $form['rows'][$image->id]['weight']['#attributes']['class'] = 'upload-weight';
+      $row[] = drupal_render($form['rows'][$image->id]['weight']);
+    }
+    $row[] = array('data' => drupal_render($form['rows'][$image->id]['delete']), 'align' => 'center');
+    $rows[] = array('data' => $row, 'class' => 'draggable');
+  }
+
+  $output = '<fieldset><legend>'.t('Uploaded images').'</legend>';
+  $output = theme('table', $header, $rows, array('id' => 'node-media-attachments'));
+  $output .= drupal_render($form);
+  $output .= '</fieldset>';
+  
+  return $output;
+}
+
+/**
+ * Process result from node media list.
+ */
+function _node_media_list_submit($form, &$form_state) {
+  global $user;
+  $node = node_load($form_values['nid']);
+  if (!node_access('update', $node)) return;
+  $delete_access = node_access('delete', $node);
+
+  foreach($form_values['rows'] as $id => $edit) {
+    if ($edit['delete']) {
+      _node_media_delete_media($id, $node, $delete_access);
+    }
+    else {
+      // update image data
+      db_query('UPDATE {node_media} SET description="%s", weight=%d WHERE id=%d AND nid=%d', $edit['description'], $edit['weight'], $id, $node->nid);
+    }
+  }
+  drupal_set_message(t('The changes have been saved.'));
+}
+
+function _node_media_delete_media($id, &$node, $delete_access) {
+  global $user;
+  
+  $r = db_fetch_object(db_query('SELECT filepath, thumbpath, uid, type FROM {node_media} WHERE id=%d AND nid=%d', $id, $node->nid));
+  
+  // if user has no delete access to the node, he can delete his own images only
+  if (!$delete_access && $user->uid != $r->uid) {
+  
+  } else {    
+    // delete selected image
+    file_delete($r->filepath);
+    file_delete($r->thumbpath);
+    db_query('DELETE FROM {node_media} WHERE id=%d AND nid=%d', $id, $node->nid);
+    unset($node->node_media[$r->type][$id]);
+  }
+}
+
+/**
+ * Upload a new image and associate it to the current node.
+ *
+ * @param $edit
+ *    array containing the submitted values
+ * @param $node
+ *    the image file
+ * @return
+ *    the uploaded image file, or FALSE if upload fails
+ */
+
+/**
+ * Upload a new image and associate it to the current node.
+ *
+ * @param $edit
+ *    array containing the submitted values
+ * @param $node
+ *    the image file
+ * @return
+ *    the uploaded image file, or FALSE if upload fails
+ */
+function _node_media_upload($edit, $node) {
+  global $user;
+  
+  if (user_access('create node media')) { 
+    $image_path = file_create_path(_node_media_get_directory());
+    $extensions = variable_get('node_media_extensions', 'jpg jpeg gif png');
+    $validators = array(
+      //'file_validate_is_image' => array(),
+      'file_validate_extensions' => array($extensions),
+    );
+  
+    if ($file = file_save_upload('node_media_upload', $validators, FALSE, FILE_EXISTS_RENAME)) {
+      switch($edit['type']){
+        case NODE_MEDIA_IMAGE:
+          // The uploaded file must be an image
+          $info = image_get_info($file->filepath);
+          if (!$info) {
+            form_set_error('upload', t('The uploaded file !name is not a valid image.', array('!name' => theme('placeholder', $file->filename))));
+            return FALSE;
+          }
+          break;
+        case NODE_MEDIA_VIDEO:
+          break;
+        case NODE_MEDIA_SOUND:
+          break;
+       }
+      /*
+      // Validation from upload.module
+      $fid = 'upload_'.$user->uid;
+      $node->files = array($fid => $file);
+      _upload_validate($node);
+      if (!isset($node->files[$fid])) return FALSE;
+      */
+      
+      if (($extension == '.zip' || $extension == '.gz') && module_exists('node_media_upload_zip')) {
+        $files = _node_media_process_archive($file, $edit, $extension);
+      } 
+      else {
+        $files = _node_media_process_media($file, $edit);
+      }
+      return $files;
+    }
+  }
+}
+
+/**
+ * Helper Function For Saving Uploads: This function processes a single file
+ */
+function _node_media_process_media($file, $edit = array(), $media_path = NULL, $file_info = NULL) {
+  global $user;
+  
+  if (is_null($file_info)) {
+    $file_info = image_get_info($file->filepath);
+  }
+  if (is_null($image_path)) {
+    $path = file_create_path(_node_media_get_directory());
+    if ($edit['nid']) {
+      $media_path = $path .'/'. $edit['nid'];
+    }
+    file_check_directory($media_path, 1, $edit['nid']);
+  }
+  if (trim($edit['description']) == '') {
+    $edit['description'] = basename($file->filename);
+  }
+  if (variable_get('node_media_md5name', FALSE)) {
+    // set md5 file name
+    $extension = $file_info['extension'];
+    $file->filename = substr(md5($dest .'/'. $file->filename), 0, 16);
+    if ($extension) {
+      $file->filename .= '.'. $extension;
+    }
+  }
+  
+  $file->filename = preg_replace('/ +/', '_', $file->filename);
+      
+  //Munge the filename as needed for security purposes.
+  $file->filename = file_munge_filename($file->filename, $extensions, 0);
+     
+  // Scale image to the maximum allowed resolution (default is 400x300)
+  // (if not set in the node_media admin settings, use the default upload max resolution
+  list($width, $height) = explode('x', variable_get('node_media_large_resolution', '400x300'));
+  
+  if (!$width || !$height) {
+    list($width, $height) = explode('x', variable_get('upload_max_resolution', '400x300'));
+  }
+  if (!$width || !$height) {
+    list($width, $height) = explode('x', '400x300');
+  }
+  if ($width && $height) {
+    $result = image_scale($file->filepath, $file->filepath, $width, $height);
+    if ($result) {
+      //$file->filesize = filesize($file->filepath);
+       drupal_set_message(t('The image was resized to fit within the maximum allowed resolution of %resolution pixels.',
+         array('%resolution' => $width.'x'.$height)));
+       }
+    }
+      
+    // Save uploaded image 
+    if (file_move($file->filepath, $image_path .'/'. strtolower($file->filename), FILE_EXISTS_RENAME) ) {
+      $thumb = _node_media_create_thumbnail($file->filepath);
+     // $medium = _node_media_create_thumbnail($file->filepath, '_med', variable_get('node_media_medium_resolution', '250x250'));
+      
+      $file->filesize = filesize($file->filepath);
+      db_query("INSERT INTO {node_media} (nid, uid, filename, filepath, filemime, filesize, thumbpath, thumbsize, weight, description, type)
+        VALUES (%d, %d, '%s', '%s', '%s', %d, '%s', %d, %d, '%s', %d)",
+        $edit['nid'], $user->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize,
+        $thumb->filepath, $thumb->filesize, $edit['weight'], $edit['description'], $edit['type']);
+     
+     /*
+      db_query("INSERT INTO {node_media} (nid, uid, filename, filepath, filemime, filesize, mediumpath, mediumsize, thumbpath, thumbsize, weight, description)
+        VALUES (%d, %d, '%s', '%s', '%s', %d, '%s', %d, '%s', %d, %d, '%s')",
+        $edit['nid'], $user->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $medium->filepath, $medium->filesize, $thumb->filepath, $thumb->filesize, $edit['weight'], $edit['description']);
+     */ 
+      // Append file object so we can rebuild our form properly.
+      //
+      $file->id = db_last_insert_id('node_media', 'id');
+      $file->thumbpath = $thumb->filepath;
+      //$file->mediumpath =$medium->filepath;
+      $file->thumbsize = $thumb->filesize;
+      $file->uid = $user->uid;
+      $file->weight = $edit['weight'];
+      $file->description = $edit['description'];
+      $file->type = $edit['type'];         
+  }
+  return $file;
+}
+
+/************************************************************
+ * Node view functions
+ ************************************************************/
+
+/**
+ * Show node media in the node view.
+ */
+function theme_node_media_view($node, $teaser, $page, $format = NULL) {
+  //if (str_replace(arg(2)) == 'image_gallery' || empty($node->node_media)) return;
+  $output = array('','','');
+  $i = 0;
+
+  // set maximum number of images for teaser/body
+  $view = ($teaser ? 'teaser' : 'body');
+  $count = variable_get('node_media_'.$view.'_images_'.$node->type, 2);
+  if (isset($count) && $count === 0) return;
+  if (!$format) {
+    $format = variable_get('node_media_'.$view.'_format_'.$node->type, 'thumbs');
+  }
+
+  foreach((array)$node->node_media[NODE_MEDIA_IMAGE] as $id=>$image) {
+    $description = check_plain($image->description);
+    $pattern = '<img src="%path" alt="%description" />';
+    $thumb = strtr($pattern, array('%path'=>file_create_url($image->thumbpath), '%description'=>$description));
+    $fullsize = strtr($pattern, array('%path'=>file_create_url($image->filepath), '%description'=>$description));
+
+    if ($info = getimagesize($image->filepath)) {
+      $width = $info[0] + 36;
+      $height = $info[1] + 36;
+    }
+    else {
+      $width = 420;
+      $height = 315;
+    }
+
+    if ($format == 'thumbs') {
+      $output[0] .= '<a href="javascript:void(0);" title="'.$description.'" onclick="window.open(\''.
+        file_create_url($image->filepath).'\', \'\', \'height='.$height.',width='.$width.'\');">'.$thumb.'</a> ';
+    }
+    else {
+      $output[0] .= $fullsize.' ';
+    }
+    if ($count>0 && ++$i >= $count) break;
+  }
+  
+  foreach((array)$node->node_media[NODE_MEDIA_VIDEO] as $id=>$video) {
+    $description = check_plain($video->description);
+    $iconpath = variable_get('video_media_icon_path','/modules/node_media/img/video_icon.gif');
+    $pattern = '<img src="'.$iconpath.'" alt="%description" />';
+    $thumb = strtr($pattern, array('%path'=>file_create_url($iconpath), '%description'=>$description));
+    $fullsize = strtr($pattern, array('%path'=>file_create_url($iconpath), '%description'=>$description));
+    
+    list($width, $height) = explode('x', variable_get('video_media_max_resolution', '400x300'));
+
+    if ($format == 'thumbs') {
+      $output[1] .= '<a href="javascript:void(0);" title="'.$description.'" onclick="window.open(\''.
+        file_create_url($video->filepath).'\', \'\', \'height='.$height.',width='.$width.'\');">'.$thumb.'</a> ';
+    }
+    else {
+      $output[1] .= $fullsize.' ';
+    }
+    if ($count>0 && ++$i >= $count) break;
+  }
+  
+  return $output;
+}
+
+
+/************************************************************
+ * Helper functions - admin settings
+ ************************************************************/
+
+/**
+ * Menu callback; admin settings page.
+ */
+function node_media_admin_settings() {
+  _node_media_check_settings();
+
+  $form['node_media_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Node media path'),
+    '#default_value' => variable_get('node_media_path', 'node_media'),
+    '#maxlength' => 255,
+    '#description' => t('Subdirectory in the directory %dir where the node media will be stored. This directory has to exist and be writable by Drupal. You can use the following variables: %uid, %username', array('%dir' => file_directory_path() .'/')),
+    '#after_build' => array('_node_media_check_directory'),
+  );
+  $form['node_media_large_resolution'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Resolution for large images'),
+    '#default_value' => variable_get('node_media_large_resolution', '400x300'),
+    '#size' => 19,
+    '#maxlength' => 9,
+    '#description' => t('The size for large images in the node gallery, expressed as WIDTHxHEIGHT (e.g. 400x300). If not set, the image will be resized to the maximum allowed resolution in the upload module settings.'),
+  );
+  $form['node_media_thumb_resolution'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Resolution for thumbnails'),
+    '#default_value' => variable_get('node_media_thumb_resolution', '100x100'),
+    '#size' => 15,
+    '#maxlength' => 7,
+    '#description' => t('The thumbnail size expressed as WIDTHxHEIGHT (e.g. 100x75).'),
+  );
+  $form['node_media_extensions'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default permitted media extensions'),
+    '#default_value' => variable_get('node_media_extensions', 'jpg jpeg gif png'),
+    '#maxlength' => 255,
+    '#description' => t('Default image extensions that users can upload. Separate extensions with a space and do not include the leading dot.'),
+  );
+  $form['node_media_max_images'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Maximum number of images'),
+    '#default_value' => variable_get('node_media_max_images', 4),
+    '#size' => 6,
+    '#maxlength' => 2,
+    '#description' => t('The maximum number of images a user can upload for each node.'),
+  );
+  $form['node_media_max_videos'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Maximum number of videos'),
+    '#default_value' => variable_get('node_media_max_videos', 4),
+    '#size' => 6,
+    '#maxlength' => 2,
+    '#description' => t('The maximum number of videos a user can upload for each node.'),
+  );
+  $form['node_media_max_sounds'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Maximum number of sounds'),
+    '#default_value' => variable_get('node_media_max_sounds', 4),
+    '#size' => 6,
+    '#maxlength' => 2,
+    '#description' => t('The maximum number of sounds a user can upload for each node.'),
+  );
+  $form['node_media_md5name'] = array(
+    '#type' => 'checkbox',
+    '#title'=> t('MD5 filenames'),
+    '#description' => t('Override uploaded filenames with the MD5 hash of the file.'),
+    '#default_value' => variable_get('node_media_md5name', FALSE),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
+ * Checks if the upload.module is enabled, and the existence of an image toolkit.
+ *
+ * @param $form_element
+ *   The form element containing the name of the directory to check.
+ */
+function _node_media_check_settings() {
+  // Make sure upload module is enabled
+  if (!module_exists('upload')) {
+    drupal_set_message(t('node_media.module require upload.module to be enabled.'), 'error');
+  }
+
+  // Make sure we've got a working toolkit
+  if (!image_get_toolkit()) {
+    drupal_set_message(t('Make sure you have a working image toolkit installed and enabled, for more information see: %settings', array('%settings' => l(t('the settings page'), 'admin/settings/image-toolkit'))), 'error');
+  }
+}
+
+
+/************************************************************
+ * Helper functions - other
+ ************************************************************/
+
+/**
+ * Checks the existence of the destination directory.
+ * The directory can be specified either in $form_element (when called from the admin settings)
+ * or in $path (when called from the node media edit page).
+ *
+ * @param $form_element
+ *   The form element containing the name of the directory to check.
+ */
+ function _node_media_check_directory($form_element = NULL, $path = '') {
+  global $user;
+  $variables = array('%uid' => $user->uid, '%username' => $user->name);
+  if ($form_element) {
+    $path = file_directory_path().'/'.strtr($form_element['#value'], $variables);
+    _node_media_mkdir_recursive($path, FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
+    return $form_element;
+  }
+  $path = strtr($path, $variables);
+  _node_media_mkdir_recursive($path, FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
+}
+
+function _node_media_mkdir_recursive($path, $mode, $form_item) {
+  $folders = explode("/", $path);
+  $dirs = array();
+  foreach($folders as $folder) {
+    $dirs[] = $folder;
+    $dir = implode('/', $dirs);
+    if ($dir != 'sites' && $dir != 'sites/default' && !file_check_directory($dir, $mode, $form_item)) {
+      mkdir($dir);
+    }
+  }
+}
+
+/**
+ * Return the destination directory.
+ */
+function _node_media_get_directory() {
+  global $user;
+  $path = file_directory_path().'/'.variable_get('node_media_path', 'node_media');
+  return strtr($path, array('%uid' => $user->uid, '%username' => $user->name));
+}
+
+/**
+ * Create the thumbnail for the uploaded image.
+ */
+function _node_media_create_thumbnail($source, $suffix = '_tn', $size = NULL, $path = NULL) {
+  if (is_null($size)) {
+    $size = variable_get('node_media_thumb_resolution', '100x100'); 
+  } 
+  list($width, $height) = explode('x', $size);
+  $dest = preg_replace('!(\.[^/.]+?)?$!', "$suffix\\1", $source, 1);
+
+  if ($size = @getimagesize($source)) {
+    if (!image_scale($source, $dest, $width, $height)) {
+      file_copy($source, $dest, FILE_EXISTS_REPLACE);
+    }
+    $info = image_get_info($dest);
+    $thumb = new stdClass();
+    $thumb->filename = basename($dest);
+    $thumb->filepath = $dest;
+    $thumb->filesize = $info['file_size'];
+    $thumb->filemime = $info['mime_type'];
+    return $thumb;
+  }
+  return NULL;
+}
+
+
+/**
+ * Determine how much disk space is occupied by a user's uploaded files.
+ *
+ * @param $uid
+ *   The integer user id of a user.
+ * @return
+ *   The amount of disk space used by the user in bytes.
+ */
+function _node_media_space_used($uid) {
+  return db_result(db_query('SELECT SUM(filesize+thumbsize) FROM {node_media} WHERE uid=%d', $uid));
+}
+
+
+/************************************************************
+ * Views API hooks
+ ************************************************************/
+
+/**
+ * Implementation of hook_views_default_tables().
+ */
+function node_media_views_tables() {
+  require_once './'. drupal_get_path('module', 'node_media') .'/node_media.views.inc';
+  return _node_media_views_tables();
+}
+
+/**
+ * Implementation of hook_views_pre_query().
+ */
+function node_media_views_pre_query() {
+  require_once './'. drupal_get_path('module', 'node_media') .'/node_media.views.inc';
+}
diff -urpN node_media-5-x/node_media.pages.inc node_media/node_media.pages.inc
--- node_media-5-x/node_media.pages.inc	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.pages.inc	2008-04-26 06:13:39.000000000 -0700
@@ -0,0 +1,337 @@
+<?php
+// $Id: node_media.pages.inc, Exp $
+
+/**
+ * @file
+ * Page callbacks for node_media galleries, javascript uploads and updates
+ */
+
+/************************************************************
+ * Gallery functions
+ ************************************************************/
+
+function _node_media_gallery($node) {
+  $location = arg(2);
+  switch ($location) {
+    case 'image_gallery':
+      $type = NODE_MEDIA_IMAGE;
+      $type_name = 'images';
+      $page_title = 'Image';
+      break;
+    case 'video_gallery':
+      $type = NODE_MEDIA_VIDEO;
+      $type_name = 'videos';
+      $page_title = 'Video';
+      break;
+    case 'sound_gallery':
+      $type = NODE_MEDIA_SOUND;
+      $type_name = 'sounds';
+      $page_title = 'Sound';
+      break;
+  }
+  
+  $access = FALSE;
+  if((count($node->node_media[$type]) && node_access('view', $node)) || node_access('view', $node)) {
+    $access = TRUE;
+  }
+  if (!$access) {
+    drupal_access_denied();
+    return;
+  }
+  
+  if (empty($node->node_media[$type])) {
+    drupal_set_message(t("No $type_name uploaded for this content."));
+    if (user_access('create node media') && node_access('update', $node)) {
+      $output = t("Click <a href=". !url .">here</a> to upload new $type_name.", array('!url' => url('node/'.$node->nid.'/media')));
+    }
+    return '<p>'.$output.'</p>';
+  }
+  
+  $settings = array('images' => array());
+
+  $i = 1;
+  $thumbs = array();
+  foreach ($node->node_media[$type] as $id=>$image) {
+    $thumb_path = file_create_url($image->thumbpath);
+    $thumbs[$i] = array(
+      'src' => $thumb_path,
+      'title' => $image->description,
+    );
+
+    $path = $image->filepath;
+    $info = image_get_info($path);
+    $settings['images'][$i++] = array(
+      'src' => file_create_url($path),
+      'title' => $image->filename,
+      'description' => $image->description,
+      'width' => $info['width'],
+      'height' => $info['height'],
+      'thumb' => $thumb_path,
+    );
+  }
+  $total = count($settings['images']);
+
+  if ($total > 0) {
+    $current = (int)$_GET['page'];
+    $current = ($current < 1 || $current > $total) ? 1 : $current;
+
+    $settings['current'] = $current;
+    $settings['total'] = $total;
+
+    $path = drupal_get_path('module', 'node_media');
+    drupal_add_js($path.'/node_media.js');
+    drupal_add_js(array('slideshow' => array($node->nid => $settings)), 'setting');
+    drupal_add_css($path.'/node_media.css');
+
+    $slideshow = array(
+      '#type' => 'node_media_gallery',
+      '#title' => $settings['images'][$current]['title'],
+      '#attributes' => array('class' => 'mediaslideshow-'. $node->nid),
+      '#status' => array(
+        'current' => $current,
+        'total' => $total,
+        'previous' => $current < 1 ? $total : $current - 1,
+        'next' => $current >= $total ? 1 : $current + 1,
+      ),
+      '#media' => $settings['images'][$current],
+      '#weight' => -5,
+    );
+  }
+
+  list($width, $height) = explode('x', variable_get('upload_max_resolution', 0));
+  
+  $output = '';
+  if(variable_get('node_media_gallery_display_node_details_'.$node->type, TRUE))
+    $output = node_view($node);
+  $output .= '<table id="mediaslideshow-table"><tr>';
+  $output .= '<td>'.drupal_render($slideshow).'</td>';
+  $output .= '<td>'.theme('node_media_gallery_thumbs', $thumbs).'</td>';
+  $output .= '</tr></table>';
+  //$output .= node_view($node).'<hr />';
+  
+  $title = t('!type gallery for %title', array('!type' => $page_title, '%title' => $node->title));
+  drupal_set_title($title);
+  return $output;
+}
+
+function theme_node_media_gallery($element) {
+  switch($element['#media']['type']){
+    case NODE_MEDIA_IMAGE:
+        $asset = '<img src="'. url($element['#media']['src']) .'" class="mediapolaroid" />';
+      break;
+    case NODE_MEDIA_VIDEO:
+      $asset = '<embed src="'. url($element['#media']['src']) .'" autostart="0"
+          showcontrols="1" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/windowsmedia/download/"
+          height="'. $element['#media']['height'] .'" width="'. $element['#media']['width'] .'"> ';
+      break;
+    case NODE_MEDIA_SOUND;
+      break;
+  }
+  
+  $output = '<div'. drupal_attributes($element['#attributes']) .'><div class="header">';
+  if ($element['#status']['current'] > 1) {
+    $output .= l(t('Previous'), $_GET['q'], array('query' => 'page='. $element['#status']['previous'], 'class' => 'previous', 'rel' => 'nofollow'), 'page='. $element['#status']['previous']) .' | ';
+  }
+  $output .= t('Image !current of !total', array('!current' => '<span class="current">'. $element['#status']['current'] .'</span>', '!total' => '<span class="total">'. $element['#status']['total'] .'</span>')) .' | ';
+  if ($element['#status']['current'] < $element['#status']['total']) {
+    $output .= l(t('Next'), $_GET['q'], array('query' => 'page='. $element['#status']['next'], 'class' => 'next', 'rel' => 'nofollow'), 'page='. $element['#status']['next']);
+  }
+  $output .= '</div>';
+  $output .= $asset;
+  $output .= '<p class="description">'. $element['#title'] .'</p>
+    </div>';
+  return $output;
+}
+
+function theme_node_media_gallery_thumbs($thumbs, $cols = 2) {
+  $count = count($thumbs);
+  $output = '<table id="thumbs-table">';
+
+  $i = 0;
+  foreach($thumbs as $id => $thumb) {
+    if ($i % $cols == 0) $output .= '<tr>';
+    $description = '<div class="thumb-description">'.truncate_utf8($thumb['title'], 40, FALSE, TRUE).'</div>';
+    $output .= '<td>'.l('<img src="'.$thumb['src'].'" class="slideshow-thumb" id="thumb-'.$id.'" />', $_GET['q'],
+      array('html' => TRUE, 'title' => $thumb['title'], 'rel' => 'nofollow', 'query' => 'page='.$id), NULL, FALSE, TRUE).$description.'</td>';
+    if ($i % $cols == $cols - 1 || $n >= $count) $output .= "</tr>";
+    $i++;
+  }
+
+  $output .= '</table>';
+  return $output;
+}
+
+
+/**
+ * Menu-callback for JavaScript-based uploads.
+ */
+function _node_media_js() {
+  $GLOBALS['devel_shutdown'] = FALSE;
+  $edit = $_POST;
+  /*
+  foreach ($edit as $k => $a) {
+    $debug .= $k .'='. $a .'<br />';
+  }
+ print drupal_to_js(array('status' => TRUE, 'data' => $debug. $output));
+exit();
+  */
+  if (ctype_digit($edit['nid'])) {
+    $node = node_load($edit['nid']);
+    // upload image
+    if($file = _node_media_upload($edit, $node)) {
+      if (is_array($file)) {
+        //append $node->node_media with our new files
+        foreach ($file as $key => $newfile) {
+          $node->node_media[$newfile->type][$key] = $newfile;
+        }        
+      } else {
+        //$form_element =  _node_media_image_form($file);
+        $node->node_media[$file->type][$file->id] = $file;
+      }
+      
+      // Build the new form.
+      
+      $form_state = array('submitted' => FALSE);
+      $form_build_id = $_POST['form_build_id'];
+      $form_state['storage']['mode'] = $edit['mode'];
+      
+      $form = form_get_cache($form_build_id, $form_state);
+      // Rebuild our form_state
+      foreach ($node->node_media as $type) {
+        foreach ($type as $id => $asset) {
+          $form_state['values']['rows'][$id] = array(
+            'thumbnail' => $asset->thumbpath,
+            //'mediumpath' => $image->mediumpath,
+            'description' => $asset->description,
+            'filepath' => $asset->filepath,
+            'filesize' => $asset->filesize,
+            'weight' => $asset->weight,
+            'delete' => $asset->delete,
+            'type' => $asset->type,
+          );
+        }
+      }
+      $form = drupal_rebuild_form('_node_media_edit_form', $form_state, array($form_state, $node));      
+      $form_state['values']['nid'] = $edit['nid'];
+      form_set_cache($form_build_id, $form, $form_state);
+      $form += array(
+        '#post' => $_POST,
+        '#programmed' => FALSE,
+        '#parents' => array(),
+      );
+      drupal_alter('form', $form, array(), '_node_media_js');
+      $form = form_builder('_node_media_edit_form', $form, $form_state);
+      
+      if(isset($form['body_field']) && isset($form['node_media'])) {
+        //$form['node_media']['node_media'][$file->id] = $form_element;
+        $return_form = $form['node_media']['node_media'];
+        unset($form_state['storage'], $form_state['rebuild']);
+         
+      }
+      else {
+        //$form['node_media']['node_media'][$file->id] = $form_element;
+        $return_form = $form;
+      }      
+      unset($return_form['#prefix'], $return_form['#suffix'], $return_form['node_media']['#prefix'], $return_form['node_media']['#suffix']);
+    }
+  } 
+  else {
+    drupal_set_message(t('Unable to attach media to the current node.'));
+  }
+  $output = theme('status_messages');
+  if ($return_form) {
+    $output .= drupal_render($return_form);
+  }
+
+  // We send the updated file attachments form.
+  print drupal_to_js(array('status' => TRUE, 'data' => $debug. $output));
+  exit;
+}
+
+ 
+/**
+* Processes changes made in form produced by node_media() and submitted via javascript
+*/
+function node_media_save_js() {
+  global $user;
+  $GLOBALS['devel_shutdown'] = FALSE;
+  
+  $edit = $_POST;
+  $form_state = array('submitted' => FALSE);
+  $form_build_id = $_POST['form_build_id'];
+  
+  $node = node_load($edit['nid']);
+  $delete_access = node_access('delete', $node);
+  if (ctype_digit($edit['nid']) && user_access('create node media', $user)) {
+    foreach($edit['rows'] as $id => $asset) {
+      if ($asset['delete'] == TRUE) {
+        _node_media_delete_media($id, $node, $delete_access);
+      }
+      else {
+        //db_query("UPDATE {node_media} SET filename='%s', description='%s', caption='%s' WHERE id=%d AND nid=%d", $image['meta']['filename'], $image['meta']['description'], $image['meta']['caption'], $id, $edit['nid']);
+        db_query("UPDATE {node_media} SET filename='%s', description='%s', weight=%d WHERE id=%d AND nid=%d", $asset['filename'], $asset['description'], $asset['weight'], $id, $edit['nid']);
+        $node->node_media[$asset['type']][$id]->description = $asset['description'];
+        $node->node_media[$asset['type']][$id]->weight = $asset['weight'];
+      }
+    }
+    drupal_set_message('Changes saved.');
+    
+    // Reorder node media by re-assigned weight
+    foreach ($node->node_media as $type) {
+      foreach ($type as $id => $asset) {
+        $assets_tmp[$id] = $asset;
+      }
+    }
+    unset($node->node_media);
+    usort($assets_tmp, '_node_media_sort_weight');
+    foreach ($assets_tmp as $id => $asset) {
+      $node->node_media[$asset->type][$id] = $asset;
+      $form_state['values']['rows'][$id] = array(
+        'thumbnail' => $asset->thumbpath,
+        //'mediumpath' => $image->mediumpath,
+        'description' => $asset->description,
+        'filepath' => $asset->filepath,
+        'filesize' => $asset->filesize,
+        'weight' => $asset->weight,
+        'delete' => $asset->delete,
+        'type' => $asset->type,
+      );
+    }
+    unset($assets_tmp);
+  }
+  // Build the new form.
+ 
+  //$form_state['storage']['mode'] = $edit['mode'];
+  $form = form_get_cache($form_build_id, $form_state);
+  $form = drupal_rebuild_form('_node_media_edit_form', $form_state, array($form_state, $node));      
+  $form_state['values']['nid'] = $edit['nid'];
+  form_set_cache($form_build_id, $form, $form_state);
+  $form += array(
+    '#post' => $_POST,
+    '#programmed' => FALSE,
+    '#parents' => array(),
+  );
+  drupal_alter('form', $form, array(), '_node_media_save_js');
+  $form = form_builder('_node_media_edit_form', $form, $form_state);
+      
+  unset($form['#prefix'], $form['#suffix']);
+ 
+  $output = theme('status_messages');
+  if ($form) {
+    $output .= drupal_render($form);
+  }
+
+  // We send the updated file attachments form.
+  print drupal_to_js(array('status' => TRUE, 'data' => $debug. $output));
+  exit;
+}
+
+/**
+ * Helper function to sort assets by weight prior to rebuilding javascript submitted form
+ */
+function _node_media_sort_weight($asset1, $asset2) {
+  if ($asset1->weight == $asset2->weight) {
+    return 0;
+  }
+  return ($asset1->weight < $asset2->weight) ? -1 : 1;
+}
\ No newline at end of file
diff -urpN node_media-5-x/node_media.views.inc node_media/node_media.views.inc
--- node_media-5-x/node_media.views.inc	1969-12-31 16:00:00.000000000 -0800
+++ node_media/node_media.views.inc	2008-04-22 17:46:21.000000000 -0700
@@ -0,0 +1,86 @@
+<?php
+/**
+ * @file
+ * Views API hook implementations for the node_media module.
+ */
+
+function _node_media_views_tables() {
+  $tables['node_media'] = array(
+    'name' => 'node_media',
+    'provider' => 'internal',
+    'join' => array(
+      'left' => array(
+        'table' => 'node',
+        'field' => 'nid'
+      ),
+      'right' => array(
+        'field' => 'nid'
+      ),
+    ),
+    'fields' => array(
+      'node_media_display' => array(
+        'name' => t('Node media: Display node media'),
+        'notafield' => TRUE,
+        'query_handler' => '_node_media_query_handler_display',
+        'handler' => array(
+          '_node_media_views_handler_image_thumb' => t('Thumbnails'),
+          '_node_media_views_handler_image_fullsize' => t('Full size'),
+        ),
+        'sortable' => false,
+        'help' => t('Display all node media in one field.'),
+      ),
+    ),
+    'filters' => array(
+      'nid' => array(
+        'name' => t('Node media: Has node media'),
+        'operator' => array('=' => t('Exists')),
+        'list' => 'views_handler_operator_yesno',
+        'list-type' => 'select',
+        'handler' => '_node_media_handler_images_exist',
+        'help' => t('Filter whether the node has node media.'),
+      ),
+    ),
+  );
+  return $tables;
+}
+
+function _node_media_query_handler_display($field, $fieldinfo, &$query) {
+  $query->add_field('nid', 'node');
+}
+
+/**
+ * Views handler for displaying images.
+ */
+function _node_media_views_handler_image_thumb($fieldinfo, $fielddata, $value, $data, $thumb = TRUE) {
+  $node = node_load(array('nid' => $data->nid));
+  $format = ($thumb ? 'thumbs' :'fullsize');
+  $return = theme('node_media_view', $node, TRUE, FALSE, $format);
+  return $return[0];
+}
+
+/**
+ * Views handler for displaying images in links to a popup window
+ */
+function _node_media_views_handler_image_fullsize($fieldinfo, $fielddata, $value, $data) {
+  return _node_media_views_handler_image_thumb($fieldinfo, $fielddata, $value, $data, FALSE);
+}
+
+/**
+ * Views handler for filtering
+ */
+function _node_media_handler_images_exist($op, $filter, $filterdata, &$query) {
+  switch ($op) {
+    case 'handler':
+      $query->ensure_table('node_media');
+      if ($filter['value']) {
+        $query->set_distinct();
+        $table_data = _views_get_tables();
+        $joins = array('type' => 'inner');
+        $joins = array_merge($joins, $table_data['node_media']['join']);
+        $query->joins['node_media'][1] = $joins;
+      }
+      else {
+        $query->add_where('ISNULL(node_media.id)');
+      }
+  }
+}
