Index: /extensions/Automatic_Oversize/language/ca_ES/description.txt
===================================================================
--- /extensions/Automatic_Oversize/language/ca_ES/description.txt	(revision 31834)
+++ /extensions/Automatic_Oversize/language/ca_ES/description.txt	(revision 31834)
@@ -0,0 +1,1 @@
+Automàticament selecciona la menor mida d'imatge que pugui cobrir tota la pantalla
Index: /extensions/Automatic_Oversize/language/en_UK/description.txt
===================================================================
--- /extensions/Automatic_Oversize/language/en_UK/description.txt	(revision 31834)
+++ /extensions/Automatic_Oversize/language/en_UK/description.txt	(revision 31834)
@@ -0,0 +1,1 @@
+Automatically selects the smallest image size required to cover the full screen
Index: /extensions/Automatic_Oversize/language/es_ES/description.txt
===================================================================
--- /extensions/Automatic_Oversize/language/es_ES/description.txt	(revision 31834)
+++ /extensions/Automatic_Oversize/language/es_ES/description.txt	(revision 31834)
@@ -0,0 +1,1 @@
+Automáticamente selecciona el menor tamaño de imagen que pueda cubrir toda la pantalla
Index: /extensions/Automatic_Oversize/language/fr_FR/description.txt
===================================================================
--- /extensions/Automatic_Oversize/language/fr_FR/description.txt	(revision 31834)
+++ /extensions/Automatic_Oversize/language/fr_FR/description.txt	(revision 31834)
@@ -0,0 +1,1 @@
+Sélectionne automatiquement la plus petite taille de photo nécessaire pour couvrir toute l'écran
Index: /extensions/Automatic_Oversize/main.inc.php
===================================================================
--- /extensions/Automatic_Oversize/main.inc.php	(revision 31834)
+++ /extensions/Automatic_Oversize/main.inc.php	(revision 31834)
@@ -0,0 +1,106 @@
+<?php
+/*
+Plugin Name: Automatic Oversize
+Version: 1.0
+Description: Automatically selects the smallest image size required to cover the full screen
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=854 
+Author: lexming
+Author URI: http://piwigo.org/forum/profile.php?id=23261
+Note: This plugin is heavily based on the Automatic Size plugin by plg
+      (http://piwigo.org/ext/extension_view.php?eid=702)
+*/
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+  die('Hacking attempt!');
+}
+
+define('ASIZE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
+
+add_event_handler(
+  'render_element_content',
+  'asize_picture_content',
+  EVENT_HANDLER_PRIORITY_NEUTRAL-1,
+  2
+  );
+
+function asize_picture_content($content, $element_info)
+{
+  global $conf;
+
+  if ( !empty($content) )
+  {// someone hooked us - so we skip;
+    return $content;
+  }
+
+  if (isset($_COOKIE['picture_deriv']))
+  {
+    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
+    {
+      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
+    }
+  }
+  $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
+  $selected_derivative = $element_info['derivatives'][$deriv_type];
+  $unique_derivatives = array();
+  $show_original = isset($element_info['element_url']);
+  $added = array();
+  foreach(array_reverse($element_info['derivatives']) as $type => $derivative)
+  {
+    if ($type==IMG_SQUARE || $type==IMG_THUMB)
+      continue;
+    if (!array_key_exists($type, ImageStdParams::get_defined_type_map()))
+      continue;
+    $url = $derivative->get_url();
+    if (isset($added[$url]))
+      continue;
+    $added[$url] = 1;
+    $show_original &= !($derivative->same_as_source());
+    $unique_derivatives[$type]= $derivative;
+
+    if (isset($_COOKIE['available_size']) and !isset($_COOKIE['picture_deriv']))
+    {
+      $available_size = explode('x', $_COOKIE['available_size']);
+
+      $size = $derivative->get_size();
+      if (!isset($automatic_size) or ($size and ($size[0] >= $available_size[0] or $size[1] >= $available_size[1])))
+      {
+        $automatic_size = $type;
+      }
+    }
+  }
+
+  global $page, $template;
+
+  if (isset($automatic_size)) {
+    $selected_derivative = $element_info['derivatives'][$automatic_size];
+  }
+	
+  if ($show_original)
+  {
+    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
+  }
+
+  $template->append('current', array(
+      'selected_derivative' => $selected_derivative,
+      'unique_derivatives' => $unique_derivatives,
+    ), true);
+
+
+  $template->set_filenames(
+    array('default_content'=>'picture_content.tpl')
+    );
+
+  $template->assign( array(
+      'ALT_IMG' => $element_info['file'],
+      'COOKIE_PATH' => cookie_path() )
+    );
+
+  $template->set_filename('asize_picture_js', realpath(ASIZE_PATH.'picture_js.tpl'));
+  $template->parse('asize_picture_js');
+  
+  return $template->parse( 'default_content', true);
+}
+
+
+?>
Index: /extensions/Automatic_Oversize/picture_js.tpl
===================================================================
--- /extensions/Automatic_Oversize/picture_js.tpl	(revision 31834)
+++ /extensions/Automatic_Oversize/picture_js.tpl	(revision 31834)
@@ -0,0 +1,13 @@
+{footer_script require='jquery'}{literal}
+jQuery().ready(function() {
+  if (jQuery("#theImage").size() > 0) {
+    function save_available_size() {
+      var width = window.screen.width;
+      var height = window.screen.height;
+
+      document.cookie= 'available_size='+width+'x'+height+';path={/literal}{$COOKIE_PATH}{literal}';
+    }
+    save_available_size();
+  }
+});
+{/literal}{/footer_script}
