Index: /trunk/action.php
===================================================================
--- /trunk/action.php	(revision 12854)
+++ /trunk/action.php	(revision 12855)
@@ -61,5 +61,5 @@
     or !is_numeric($_GET['id'])
     or !isset($_GET['part'])
-    or !in_array($_GET['part'], array('t','e','i','h') ) )
+    or !in_array($_GET['part'], array('e','r') ) )
 {
   do_error(400, 'Invalid request - id/part');
@@ -103,19 +103,13 @@
 switch ($_GET['part'])
 {
-  case 't':
-    $file = get_thumbnail_path($element_info);
-    break;
   case 'e':
-    $file = get_element_path($element_info);
-    break;
-  case 'i':
-    $file = get_image_path($element_info);
-    break;
-  case 'h':
     if ( $user['enabled_high']!='true' )
     {
       do_error(401, 'Access denied h');
     }
-    $file = get_high_path($element_info);
+    $file = get_element_path($element_info);
+    break;
+  case 'r':
+    $file = original_to_representative( get_element_path($element_info), $element_info['representative_ext'] );
     break;
 }
@@ -176,5 +170,5 @@
 $http_headers[] = 'Content-Type: '.$ctype;
 
-if (!isset($_GET['view']))
+if (isset($_GET['download']))
 {
   $http_headers[] = 'Content-Disposition: attachment; filename="'.$element_info['file'].'";';
Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 12854)
+++ /trunk/admin/include/functions.php	(revision 12855)
@@ -201,19 +201,10 @@
     $files[] = get_element_path($row);
 
-    if (!empty($row['tn_ext']))
-    {
-      $files[] = get_thumbnail_path($row);
-    }
-    
-    if (!empty($row['has_high']) and get_boolean($row['has_high']))
-    {
-      $files[] = get_high_path($row);
-    }
-    
+   
     if (!empty($row['representative_ext']))
     {
       $pi = pathinfo($row['path']);
       $file_wo_ext = get_filename_wo_extension($pi['basename']);
-      $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$row['representative_ext'];
+      $files[] = original_to_representative( $files[0], $row['representative_ext']);
     }
 
Index: /trunk/admin/picture_modify.php
===================================================================
--- /trunk/admin/picture_modify.php	(revision 12854)
+++ /trunk/admin/picture_modify.php	(revision 12855)
@@ -304,12 +304,4 @@
   );
 
-if ($row['has_high'] == 'true')
-{
-  $template->assign(array(
-    'HIGH_FILESIZE' => isset($row['high_filesize']) ? $row['high_filesize'].' KB' : l10n('unknown'),
-    'HIGH_DIMENSIONS' => isset($row['high_width']) ? $row['high_width'].' * '.$row['high_height'] : l10n('unknown'),
-    ));
-}
-
 // image level options
 $selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
Index: /trunk/admin/themes/default/template/picture_modify.tpl
===================================================================
--- /trunk/admin/themes/default/template/picture_modify.tpl	(revision 12854)
+++ /trunk/admin/themes/default/template/picture_modify.tpl	(revision 12855)
@@ -67,16 +67,4 @@
       </tr>
 
-{if isset($HIGH_FILESIZE) }
-      <tr>
-        <td><strong>{'High dimensions'|@translate}</strong></td>
-        <td>{$HIGH_DIMENSIONS}</td>
-      </tr>
-      
-      <tr>
-        <td><strong>{'High filesize'|@translate}</strong></td>
-        <td>{$HIGH_FILESIZE}</td>
-      </tr>
-{/if}
-
       <tr>
         <td><strong>{'Storage album'|@translate}</strong></td>
Index: /trunk/include/derivative.inc.php
===================================================================
--- /trunk/include/derivative.inc.php	(revision 12854)
+++ /trunk/include/derivative.inc.php	(revision 12855)
@@ -139,7 +139,6 @@
   }
 
-  static function get_all($infos)
-  {
-    $src_image = new SrcImage($infos);
+  static function get_all($src_image)
+  {
     $ret = array();
     foreach (ImageStdParams::get_defined_type_map() as $type => $params)
Index: /trunk/include/functions.inc.php
===================================================================
--- /trunk/include/functions.inc.php	(revision 12854)
+++ /trunk/include/functions.inc.php	(revision 12855)
@@ -741,4 +741,18 @@
 }
 
+/**
+ * @param element_info array containing element information from db;
+ * at least 'id', 'path' should be present
+ */
+function get_element_path($element_info)
+{
+  $path = $element_info['path'];
+  if ( !url_is_remote($path) )
+  {
+    $path = PHPWG_ROOT_PATH.$path;
+  }
+  return $path;
+}
+
 
 /* Returns the PATH to the thumbnail to be displayed. If the element does not
Index: /trunk/include/functions_picture.inc.php
===================================================================
--- /trunk/include/functions_picture.inc.php	(revision 12854)
+++ /trunk/include/functions_picture.inc.php	(revision 12855)
@@ -22,46 +22,4 @@
 // +-----------------------------------------------------------------------+
 
-/**
- * @param element_info array containing element information from db;
- * at least 'id', 'path' should be present
- */
-function get_element_path($element_info)
-{
-  $path = get_element_location($element_info);
-  if ( !url_is_remote($path) )
-  {
-    $path = PHPWG_ROOT_PATH.$path;
-  }
-  return $path;
-}
-
-/*
- * @param element_info array containing element information from db;
- * at least 'id', 'path' should be present
- */
-function get_element_url($element_info)
-{
-  $url = get_element_location($element_info);
-  if ( !url_is_remote($url) )
-  {
-    $url = embellish_url(get_root_url().$url);
-  }
-  // plugins want another url ?
-  return trigger_event('get_element_url', $url, $element_info);
-}
-
-/**
- * Returns the relative path of the element with regards to to the root
- * of PWG (not the current page). This function is not intended to be
- * called directly from code.
- * @param element_info array containing element information from db;
- * at least 'id', 'path' should be present
- */
-function get_element_location($element_info)
-{
-  // maybe a cached watermark ?
-  return trigger_event('get_element_location',
-    $element_info['path'], $element_info);
-}
 
 
@@ -84,98 +42,4 @@
 }
 
-
-/**
- * Returns the PATH to the image to be displayed in the picture page. If the
- * element is not a picture, then the representative image or the default
- * mime image. The path can be used in the php script, but not sent to the
- * browser.
- * @param element_info array containing element information from db;
- * at least 'id', 'path', 'representative_ext' should be present
- */
-function get_image_path($element_info)
-{
-  global $conf;
-  $ext = get_extension($element_info['path']);
-  if (in_array($ext, $conf['picture_ext']))
-  {
-    if (isset($element_info['element_path']) )
-    {
-      return $element_info['element_path'];
-    }
-    return get_element_path($element_info);
-  }
-
-  $path = get_image_location($element_info);
-  if ( !url_is_remote($path) )
-  {
-    $path = PHPWG_ROOT_PATH.$path;
-  }
-  return $path;
-}
-
-/**
- * Returns the URL of the image to be displayed in the picture page. If the
- * element is not a picture, then the representative image or the default
- * mime image. The URL can't be used in the php script, but can be sent to the
- * browser.
- * @param element_info array containing element information from db;
- * at least 'id', 'path', 'representative_ext' should be present
- */
-function get_image_url($element_info)
-{
-  global $conf;
-  $ext = get_extension($element_info['path']);
-  if (in_array($ext, $conf['picture_ext']))
-  {
-    if (isset($element_info['element_url']) )
-    {
-      return $element_info['element_url'];
-    }
-    return get_element_url($element_info);
-  }
-
-  $url = get_image_location($element_info);
-  if ( !url_is_remote($url) )
-  {
-    $url = embellish_url(get_root_url().$url);
-  }
-  return $url;
-}
-
-/**
- * Returns the relative path of the image (element/representative/mimetype)
- * with regards to the root of PWG (not the current page). This function
- * is not intended to be called directly from code.
- * @param element_info array containing element information from db;
- * at least 'id', 'path', 'representative_ext' should be present
- */
-function get_image_location($element_info)
-{
-    if (isset($element_info['representative_ext'])
-          and $element_info['representative_ext'] != '')
-    {
-      $pi = pathinfo($element_info['path']);
-      $file_wo_ext = get_filename_wo_extension($pi['basename']);
-      $path =
-        $pi['dirname'].'/pwg_representative/'
-        .$file_wo_ext.'.'.$element_info['representative_ext'];
-    }
-    else
-    {
-      $ext = get_extension($element_info['path']);
-      $path = get_themeconf('mime_icon_dir');
-      $path.= strtolower($ext).'.png';
-      if ( !file_exists(PHPWG_ROOT_PATH.$path)
-          and !empty($element_info['tn_ext']) )
-      {
-        $path = get_thumbnail_location($element_info);
-      }
-    }
-
-  // plugins want another location ?
-  return trigger_event( 'get_image_location', $path, $element_info);
-}
-
-
 /*
  * @param element_info array containing element information from db;
@@ -223,21 +87,4 @@
 
 
-/**
- * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image),
- *   'h' (high resolution image)
- * @param element_info array containing element information from db;
- * at least 'id', 'path' should be present
- */
-function get_download_url($what_part, $element_info)
-{
-  $url = get_root_url().'action.php';
-  $url = add_url_params($url,
-      array(
-        'id' => $element_info['id'],
-        'part' => $what_part,
-      )
-    );
-  return trigger_event( 'get_download_url', $url, $element_info);
-}
 
 /*
Index: /trunk/include/functions_url.inc.php
===================================================================
--- /trunk/include/functions_url.inc.php	(revision 12854)
+++ /trunk/include/functions_url.inc.php	(revision 12855)
@@ -661,4 +661,38 @@
 }
 
+
+/**
+ * @param id image id
+ * @param what_part string one of 'e' (element), 'r' (representative)
+ */
+function get_action_url($id, $what_part, $download)
+{
+  $params = array(
+        'id' => $id,
+        'part' => $what_part,
+      );
+  if ($download)
+  {
+    $params['download'] = null;
+  }
+  
+  return add_url_params(get_root_url().'action.php', $params);
+}
+
+/*
+ * @param element_info array containing element information from db;
+ * at least 'id', 'path' should be present
+ */
+function get_element_url($element_info)
+{
+  $url = $element_info['path'];
+  if ( !url_is_remote($url) )
+  {
+    $url = embellish_url(get_root_url().$url);
+  }
+  return $url;
+}
+
+
 /**
  * Indicate to build url with full path
Index: /trunk/include/ws_functions.inc.php
===================================================================
--- /trunk/include/ws_functions.inc.php	(revision 12854)
+++ /trunk/include/ws_functions.inc.php	(revision 12855)
@@ -148,4 +148,7 @@
 {
   $ret = array();
+  
+  $src_image = new SrcImage($image_row);
+
   global $user;
   if ($user['enabled_high'])
@@ -154,5 +157,5 @@
   }
   
-  $derivatives = DerivativeImage::get_all($image_row);
+  $derivatives = DerivativeImage::get_all($src_image);
   $derivatives_arr = array();
   foreach($derivatives as $type=>$derivative)
Index: /trunk/picture.php
===================================================================
--- /trunk/picture.php	(revision 12854)
+++ /trunk/picture.php	(revision 12855)
@@ -163,5 +163,6 @@
   $selected_derivative = $element_info['derivatives'][$deriv_type];
 
-  $available_derivatives = array();
+  $unique_derivatives = array();
+  $show_original = isset($element_info['element_url']);
   $added = array();
   foreach($element_info['derivatives'] as $type => $derivative)
@@ -171,12 +172,18 @@
       continue;
     $added[$url] = 1;
-    $available_derivatives[] = $type;
-  }
-
-  global $user, $page, $template;
+    $show_original &= !($derivative->same_as_source());
+    $unique_derivatives[$type]= $derivative;
+  }
+
+  global $page, $template;
   
+  if ($show_original)
+  {
+    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
+  }
+
   $template->append('current', array(
       'selected_derivative' => $selected_derivative,
-      'available_derivative_types' => $available_derivatives,
+      'unique_derivatives' => $unique_derivatives,
     ), true);
 
@@ -492,25 +499,22 @@
   }
 
-
-
-  $row['derivatives'] = DerivativeImage::get_all($row);
-  $row['src_image'] = $row['derivatives'][IMG_THUMB]->src_image;
+  $row['src_image'] = new SrcImage($row);
+  $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
   
-  // ------ build element_path and element_url
-  $row['element_path'] = get_element_path($row);
-  $row['element_url'] = get_element_url($row);
-
   if ($i=='current')
   {
+    $row['element_path'] = get_element_path($row);
+
     if ( $row['src_image']->is_original() )
-    {
+    {// we have a photo
       if ( $user['enabled_high']=='true' )
       {
-        $row['download_url'] = get_download_url('e',$row);
+        $row['element_url'] = $row['src_image']->get_url();
+        $row['download_url'] = get_action_url($row['id'], 'e', true);
       }
     }
     else
     { // not a pic - need download link
-      $row['download_url'] = $row['element_url'];
+      $row['download_url'] = $row['element_url'] = get_element_url($row);;
     }
   }
Index: /trunk/themes/default/template/picture_content.tpl
===================================================================
--- /trunk/themes/default/template/picture_content.tpl	(revision 12854)
+++ /trunk/themes/default/template/picture_content.tpl	(revision 12855)
@@ -3,5 +3,5 @@
 	title="{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}" {else} title="{$current.TITLE|@replace:'"':' '} - {$ALT_IMG}"
 {/if}>
-{if count($current.available_derivative_types)>1}
+{if count($current.unique_derivatives)>1}
 {footer_script}{literal}
 function changeImgSrc(url,type,display)
@@ -35,7 +35,10 @@
 <a id="derivativeSwitchLink" onclick="toggleDerivativeSwitchBox()" style="cursor:pointer">{$current.selected_derivative->get_type()|@translate}</a>
 <div id="derivativeSwitchBox" onclick="toggleDerivativeSwitchBox()" style="display:none">
-{foreach from=$current.available_derivative_types item=derivative_type}
-<a onclick="changeImgSrc('{$current.derivatives[$derivative_type]->get_url()|@escape:javascript}', '{$derivative_type}', '{$derivative_type|@translate|@escape:javascript}')" style="cursor:pointer">{$derivative_type|@translate} ({$current.derivatives[$derivative_type]->get_size_hr()})</a><br>
+{foreach from=$current.unique_derivatives item=derivative key=derivative_type}
+<a href="javascript:changeImgSrc('{$derivative->get_url()|@escape:javascript}', '{$derivative_type}', '{$derivative->get_type()|@translate|@escape:javascript}')" style="cursor:pointer">{$derivative->get_type()|@translate} ({$derivative->get_size_hr()})</a><br>
 {/foreach}
+{if isset($U_ORIGINAL)}
+<a  href="javascript:phpWGOpenWindow('{$U_ORIGINAL}','xxx','scrollbars=yes,toolbar=no,status=no,resizable=yes')" title="{'Click on the photo to see it in high definition'|@translate}">{'original'|@translate}</a>
+{/if}
 </div>
 {/if}
Index: /trunk/tools/triggers_list.php
===================================================================
--- /trunk/tools/triggers_list.php	(revision 12854)
+++ /trunk/tools/triggers_list.php	(revision 12855)
@@ -160,10 +160,4 @@
   'vars' => array('string' => 'url', 'array' => 'element_info'),
   'files' => array('include\functions_picture.inc.php (get_download_url'),
-),
-array(
-  'name' => 'get_element_location',
-  'type' => 'trigger_event',
-  'vars' => array('string' => 'path', 'array' => 'element_info'),
-  'files' => array('include\functions_picture.inc.php (get_element_location)'),
 ),
 array(
