Index: /extensions/Autosize/admin/admin_autosize.php
===================================================================
--- /extensions/Autosize/admin/admin_autosize.php	(revision 17502)
+++ /extensions/Autosize/admin/admin_autosize.php	(revision 17503)
@@ -97,5 +97,8 @@
  $visible=true;	
  $path = AUTOSIZE_PATH;
- $autosize_parametres = cl_autosize_Get_Options();
+global $has_pamoorama,$select_type,$autosize_parametres;
+global $defined_types,$maxi_img ,$pictureDeriv ,$liste_type,$SRC_IMG;
+  $defined_types = array_keys(ImageStdParams::get_defined_type_map());  
+  $autosize_parametres = cl_autosize_Get_Options();
 	  
    if (isset($_POST['submit']))  {  
@@ -109,5 +112,5 @@
 		 unset($_POST);
 		 }
- include (AUTOSIZE_PATH."include/affiche.php"); 	 	 
+  include (AUTOSIZE_PATH."include/affiche.php"); 	 	 
 //================================================================================
 $base_url = get_root_url().'admin_autosize.php';
@@ -127,5 +130,5 @@
     <div class='autosize' 
          autosize='MargeBasse:30px;MargeHaute:30px;parent:fieldset;ResizePicture:true'>
-        <img src='./plugins/Autosize/images/ECO_050.jpg ' width='100%' />       
+        <img src='./plugins/Autosize/images/quadrille_100.png ' width='100%' />       
     </div>
 </fieldset>"; 
Index: /extensions/Autosize/autosize.inc.php
===================================================================
--- /extensions/Autosize/autosize.inc.php	(revision 17502)
+++ /extensions/Autosize/autosize.inc.php	(revision 17503)
@@ -21,30 +21,312 @@
 // +-----------------------------------------------------------------------+
 class autosize_controler {
- //============================================================
- /*
-  *  cl_autosize_script_1
- */
- static public function cl_autosize_script_1()
-	{
+	/*********************************
+	* cl_autosize_admin
+	**********************************/
+	static public function cl_autosize_admin($menu)		{
+		global  $lang ;
+		array_push($menu, array('NAME' => 'Autosize',
+		'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
+		return $menu;
+	} //function cl_autosize_admin
+/*********************
+* INIT
+*********************/
+static public function init($content){
+  // header ('X-UA-Compatible: n=7')  ;
+ // header ('X-UA-Compatible: IE=Edge')  ; 
+ global  $template,$version,$icon_path,$page,$picture,$conf;
+
+   $current = $template->get_template_vars('current'); 
+
+   $model=  $_COOKIE['picture_deriv'] ;
+      $has_pamoorama=isset($template->files['pamooramics_content']);
+ //====================================================================    
+    $pictureDeriv = pwg_get_session_var('picture_deriv',$conf['derivative_default_size']); 
+    $SRC_IMG=""; 
+       $selected_derivative =  $current['derivatives'][$pictureDeriv];
+        if (!isset($current['selected_derivative'])){  
+          $template->append('current', array(
+                                        'selected_derivative' => $selected_derivative
+                                            ), 
+                             true);
+          $current = $template->get_template_vars('current');
+        }
+
+        if(isset($current['derivatives'][$model])) {
+            $selected_derivative =  $current['derivatives'][$model];
+            $template->assign('current[selected_derivative]', $selected_derivative
+                              , true);
+            $current = $template->get_template_vars('current'); 
+        }
+   
+    return $content;
+
+}//INIT
+/**************************
+*  autosize_calcContent   *
+**************************/
+ static public function autosize_calcContent($content){
+  global $conf,$page, $template,$picture,$user; 
+  global $defined_types,$maxi_img ,$pictureDeriv ,$liste_type,$SRC_IMG,$select_type;
+  global  $has_pamoorama;
+  global $autosize_parametres,$user_status;
+$defined_types = array_keys(ImageStdParams::get_defined_type_map());   
+//===============================================================
+ if(isset($page['body_id']) &&	$page['body_id'] == 'theAdminPage' ) return ;   
+    if (!isset($_COOKIE['autosize_reload'])){    
+ 	    $autoscript="<script type='text/javascript' src='themes/default/js/jquery.min.js'></script>			       <script type='text/javascript' src='plugins/autosize/js/autosizeDetect.js'></script>
+      <script type='text/javascript' src='plugins/Autosize/js/autosize.cookie.js'></script>
+      <body onload=on_load() style='background-color:black;color :white;font-size:30px '  >  
+     please wait, loading...
+      </body>";   
+		  echo $autoscript;  
+      die();
+    }  
+  $current = $template->get_template_vars('current'); 
+                       if (!isset($current)) return ;
+//===============================================================
+    $derivative = $current['src_image'] ;
+    $imgScaledWH = $derivative->get_size();
+    $SRC_IMG    = $derivative->get_url();  
+    $picture['current']['scaled_width']=$imgScaledWH[0];
+    $picture['current']['scaled_height']= $imgScaledWH[1];
+    $picture['current']['high_url']= $SRC_IMG;   
+    $picture['current']['image_url']=$SRC_IMG;  
+//===============================================================
+
+    $user_status = $user['status'] ;
+    $autosize_parametres = cl_autosize_Get_Options();
+    $user_type= get_user_status($user_status)."_type";
+    $select_type=$autosize_parametres->$user_type ;
+ 
+
+  if (isset($_COOKIE['theImageHeight'])){    
+      pwg_set_session_var('theImageWidtht',$_COOKIE['theImageWidth']);  
+      pwg_set_session_var('theImageHeight',$_COOKIE['theImageHeight']);   
+  } 
+if (isset($_COOKIE['theMainImageHeight']))  pwg_set_session_var('theMainImageHeight',$_COOKIE['theMainImageHeight']);  
+if (isset($_COOKIE['theMainImageWidth']))  pwg_set_session_var('theImageWidth',$_COOKIE['theMainImageWidth']); 
+
+
+if (isset($_COOKIE['picture_deriv']))  
+    pwg_set_session_var('picture_deriv',$_COOKIE['picture_deriv']); 
+else 
+  pwg_set_session_var('picture_deriv',$select_type); 
+
+ 
+$model=   $conf['derivative_default_size'] ; // par defaut 
+  $pictureDeriv = pwg_get_session_var('picture_deriv',  $model); 
+
+ 
+ $model=$pictureDeriv ;
+
+    $value=0;
+    $liste_type="";
+    $maxi_info="";
+    if($model!="Autosize" & $model!="SelMaxi"){
+      
+    }else{
+        $model=$conf['derivative_default_size'] ;  
+    }
+  $derivative=$current['derivatives'][$model] ;  
+    $img_all= $derivative->get_all($derivative->src_image);
+    $maxi_img="";
+    $mini_img="";
+    $maxi_url="";
+    $imgSizeWH  = $derivative->get_size();	
+    //==== valeur taille image ====
+    
+     $window_width=$imgSizeWH[0];
+     $window_height=$imgSizeWH[1];
+ //echo "<div style='background-color:black;color:white' >INIT: $model  w:$window_width x  h:$window_height  </div>";
+
+   
+    $window_width = pwg_get_session_var('theMainImageWidth',$imgSizeWH[0]); 
+ $window_height =  pwg_get_session_var('theMainImageHeight',$imgSizeWH[1]);
+
+ if (!isset($_COOKIE['theMainImageHeight']))    setcookie('theMainImageHeight', $window_height ); 
+if (!isset($_COOKIE['theMainImageWidth']))  setcookie('theMainImageWidth',$window_width); 
+
+  //  echo "<div style='background-color:black;color:white' >$select_type w: $window_width x h: $window_height  </div>";
+
+    $last_defined=ImageStdParams::get_defined_type_map();    
+    foreach ($img_all as $img_select){
+            $img_type  =  $img_select->get_type();	
+            if ($img_type=="square" || $img_type=="thumb" ) continue ;
+
+            $img_url  = $img_select->get_url();
+            $imgSizeWH  =  $img_select->get_size();	
+            if($img_type=="Autosize" || $img_type=="SelMaxi"){
+                $img_url = $img_select->src_image->get_url();
+                $imgSizeWH  =  $img_select->src_image->get_size();
+                $liste_type[$img_type]=$img_type.",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
+            }else{ 
+            $liste_type[$img_type]=$img_type.",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
+            if ($img_type=="Original"){
+          
+            break ;
+            }
+            
+               
+
+              if($window_height < $imgSizeWH[0] ){
+                          $maxi_img=  $img_type;
+                          $maxi_url= $img_url;
+                          $maxi_i=$img_select;
+              }
+              if($window_height < $imgSizeWH[0] && $mini_img==""){ 
+                      $mini_img=  $img_type;
+                      $mini_url= $img_url;
+                      $mini_i=$img_select;
+                      
+                 }else if($imgSizeWH[0] > 10 && $maxi_img==""){ 
+                      $last_img=$img_select;
+              }
+
+ 
+               if($select_type==$img_type){ 
+                  if($maxi_img==""){
+                      $maxi_img=  $img_type;
+                      $maxi_url= $img_url;
+                      $maxi_i=$img_select;
+                  }
+                     
+                      break ;
+                    }
+         }
+
+      }
+  
+//==============================================================    
+  //==== Réécriture selection ====
+  if( $img_type=="SelMaxi"){
+  $maxi_img= $mini_img;
+  $maxi_url= $mini_img;
+  }
+  if ( !array_key_exists($maxi_img, $last_defined) ){
+            $maxi_img = $last_img->get_type();	 
+            $maxi_url  = $last_img->get_url();
+            $imgSizeWH  =  $last_img->get_size();	
+  }
+    $model= $maxi_img;
+    pwg_set_session_var('picture_deriv', $maxi_img);
+    $_COOKIE['picture_deriv']=$maxi_img ;
+    $_COOKIE['picture_map']=  $maxi_img ;
+    $_COOKIE['imgSrc']=       $maxi_url;
+
+  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']);
+        }else{
+        echo "<pre>".$_COOKIE['picture_deriv']. "No exist  " ;
+        print_r($img_all );
+        die();
+        }
+    setcookie('picture_deriv', false, 0, cookie_path() );
+  }  
+
+  
+return false ;
+
+ }
+
+/************************
+* cl_autosize_affiche
+*************************/	
+	static public function cl_autosize_affiche(){
+		global $user, $picture, $template,$page,$known_script;
+		global $content, $element_info;   
+		global $infos_message,$erreur_message;
+		global  $conf,$lang ,$user,$userdata;
+      global $defined_types,$maxi_img ,$pictureDeriv ,$liste_type,$SRC_IMG,$select_type;
+  global  $has_pamoorama;
+  global $autosize_parametres,$user_status;
+
+    if(isset($page['body_id']) &&	$page['body_id'] == 'theAdminPage' ) return ;   
+
+ if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
+		load_language('plugin.lang', AUTOSIZE_PATH);
+		$AUTOSIZE_PATH = dirname(__FILE__).'/';
+		 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
+
+			if ( isset($picture['current'])){	
+				include (AUTOSIZE_PATH."include/affiche.php"); 
+
+        $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
+        $template->set_filenames(array('autosize_content_header'=> $file )); 
+        $template->assign(
+  					array(  
+            'select_type' =>$select_type,
+            ));
+
+        $template->concat('autosize_content', $template->parse('autosize_content_header', true));  
+
+        $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
+        $template->set_filenames(array('autosize_init_header'=> $file ));
+        $template->parse( 'autosize_init_header', false);      
+
+        	$theme=$user['theme'];  
+                         		
+				if($autosize_parametres->check_icon_v == 'on'){				 
+						$template->assign('cl_autosize_button', 
+						array(	'cl_autosize_info' => 'cl_autosize_info' ,
+                    'cl_autosize_info_1' => 'cl_autosize_info_' ,  
+								    'cl_autosize_info_2' => 'cl_autosize_info_2' ,    
+								    'URL' => $_SERVER['REQUEST_URI'] ,
+								    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
+								    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png',
+                    'ICON1' => AUTOSIZE_PATH . 'icons/button-no.png'
+								)
+
+							); 
+					$template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
+					$template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
+				}
+				 $template->set_filenames(
+						array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl',
+             'theme' => $theme   )
+					);
+			$template->concat('autosize_content', $template->parse('autosize_content_header', true));	
+      	
+      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
+        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
+        $template->func_combine_script(array('id'=>'my_script_2',
+        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
+        'require' => 'jquery'),
+        $template->smarty);
+        $template->assign(array( 
+                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
+                          ));					
+        $template->parse('mes_script');
+      }    
+        return $template->parse( 'autosize_content', false);
+     				  }
+		}
+
+	} //public function cl_autosize_affiche
+
+   /************************
+ *  cl_autosize_script_1
+ *************************/
+ static public function cl_autosize_script_1(){
   global $user,$page,$template,$cl_plugin;
- // header ('X-UA-Compatible: n=7')  ;
- // header ('X-UA-Compatible: IE=Edge')  ;
     if(isset($page['body_id']) &&	$page['body_id'] == 'theAdminPage' ) return ;    
+  
     $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
-    if ($ma_page=='thePiwiShackControllerPage') return ;
-    if (!isset($template->files['pamooramics_content'])) return ;  
+    if ($ma_page=='thePiwiShackControllerPage') return ;   
     if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
+    global  $has_pamoorama;
     $has_pamoorama=isset($template->files['pamooramics_content']);
-
-    $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
-    $template->set_filenames(array('autosize_init_header'=> $file ));
+  if (!$has_pamoorama) return ; 
+
     $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
-//================================================================
-$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
-$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
-$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
-//======================================================================
     $autosize_parametres =	 cl_autosize_Get_Options() ;			
     $theme=$user['theme'];
+    //==============================================================================
+    $DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
+    $DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] :  $DEBUG_autosize ;
+    $DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ;
+    //==============================================================================
     $template->assign(
       array(   
@@ -54,12 +336,11 @@
           'name' => $cl_plugin['name'] ,
           'pamoorama' =>  $has_pamoorama,                						 
-          'theme' => $theme  ,
-          'DEBUG_autosize' =>  $DEBUG_autosize ,
+          'theme' => $theme  ,  
+          'DEBUG_autosize' => $DEBUG_autosize,
           'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
           'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
           'Version_pwg' => PHPWG_VERSION           )
     );
- 	 	$template->concat('cl_conflit_init', $template->parse('autosize_init_header', true));
-		return $template->parse( 'autosize_init', false);
+    return $template->parse( 'autosize_init', false);
 	}// function cl_autosize_script_1
 
@@ -71,6 +352,10 @@
 	   global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
      		global  $template,$user,$conf,$picture ,$page, $cl_plugin ;
+            if(isset($page['body_id']) &&	$page['body_id'] == 'theAdminPage' ) return ;   
+    
    if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
-   if (!isset($PAMOORAMICS_PATH)) return ;    
+     global  $has_pamoorama;
+       if (!$has_pamoorama) return ; 
+      
 			$AUTOSIZE_PATH = dirname(__FILE__).'/';
 //================================================================
@@ -88,4 +373,7 @@
     $src_img_h=isset($_POST['src_img_h'])?$_POST['src_img_h']: $img_width               ;
     $src_img_w= isset($_POST['src_img_w'])?$_POST['src_img_w']:$img_height              ;
+
+
+  include_once (PHPWG_ROOT_PATH.'include/functions_cookie.inc.php') ;
 if(isset($_COOKIE['img_w'])){
     $src_img_w=$_COOKIE['img_w'];
@@ -93,6 +381,6 @@
 }
 
-$window_height= isset($_POST['window_height'])?$_POST['window_height']: $img_scaled_height ;
-$window_width= isset($_POST['window_width'])?$_POST['window_width']: $img_scaled_width    ;
+$window_height= isset($_SESSION['height'])?$_SESSION['height']: $img_scaled_height ;
+$window_width= isset($_SESSION['width'])?$_SESSION['width']: $img_scaled_width    ;
 
 
@@ -118,5 +406,5 @@
 					)
 						);
-  include_once (PHPWG_ROOT_PATH.'include/functions_cookie.inc.php') ;
+
 			$autoscript="<script type='text/javascript'>
 			/* cl_autosize_script_2 */
@@ -131,14 +419,11 @@
  * cl_autosize_script_3()
  **************************************/
- static public function cl_autosize_script_3()
- {
-	   global  $template;
-  
-
-    $has_pamoorama=isset($template->files['pamooramics_content']);
-    if (!$has_pamoorama) return ;  
-
-			$autoscript="<div id='debug' >TEST</div>
-      <script type='text/javascript'>			
+ static public function cl_autosize_script_3() {
+	   global  $template,$page;
+    if(isset($page['body_id']) &&	$page['body_id'] == 'theAdminPage' ) return ;   
+          global  $has_pamoorama;
+       if (!$has_pamoorama) return ; 
+
+			$autoscript="<script type='text/javascript'>			
  			if (typeof (Ajout_Ajax) == 'function')
 			   Ajout_Ajax();  
@@ -148,127 +433,4 @@
  }// function cl_autosize_script_3
 
-	//================================================================
-	/*
-	* cl_autosize_admin
-	*/
-	static public function cl_autosize_admin($menu)
-		{
-		global  $lang ;
-		array_push($menu, array('NAME' => 'Autosize',
-		'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
-		return $menu;
-	} //function cl_autosize_admin
-  //=====================================
-
-
-  // this is the default handler that generates the display for the element
- static public function autosize_calcContent($content)
-{
-  global $conf; 
-   
- global $page, $template,$picture;
-
-
-  $current = $template->get_template_vars('current'); 
-  $defined_types = array_keys(ImageStdParams::get_defined_type_map());  
-if (isset($current)){ 
-    if (!isset($current['selected_derivative'])){  
-      $model= $defined_types[count($defined_types)-1];
-      $selected_derivative =      $current['derivatives'][$model];
-      $template->append('current', array(
-      'selected_derivative' => $selected_derivative
-    ), true);
-
-
-    $current = $template->get_template_vars('current');
-        } 
-
-         $derivative=$current['selected_derivative'] ;
-          $imgScaledWH=$derivative->src_image->get_size();
-          $imgSizeWH  =  $derivative->get_size();	
-          $img_type  =  $derivative->get_type();	
-          $img_url  = $derivative->get_url();
-          $img_all= $derivative->get_all($derivative->src_image);
-          $scaled_size=$derivative->get_size_hr(); //792 x 441
-          $scaled_size=$derivative->get_scaled_size_htm(); // width="792" height="441"
-         //================= taille mis a l'échelle 
-          $scaled_size=$derivative->get_scaled_size(100,100); // array([0]=>100,[1]=>55)
-          $src= $derivative->src_image ;
-       
-    }
- 
-    $img_scaled_width=isset($imgScaledWH)?$imgScaledWH[0]:"480";
-    $img_scaled_height=isset($imgScaledWH)?$imgScaledWH[1]:"320";
-    $current = $template->get_template_vars('picture');
-    $picture['current']['scaled_width']=$img_scaled_width;
-    $picture['current']['scaled_height']= $img_scaled_height;
-    $picture['current']['image_url']=$src->rel_path;
-    
- }
-
-    //===============================================================
-	/*
-	*
-	*/	
-	static public function cl_autosize_affiche()
-	{
-		global $user, $picture, $template,$page,$known_script;
-		global $content, $element_info;   
-		global $infos_message,$erreur_message;
-		global  $conf,$lang ,$user,$userdata;
- if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
-		load_language('plugin.lang', AUTOSIZE_PATH);
-
-		$AUTOSIZE_PATH = dirname(__FILE__).'/';
-		 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
-			if ( isset($picture['current'])){	
-				$autosize_parametres = cl_autosize_Get_Options();
-				include (AUTOSIZE_PATH."include/affiche.php"); 
-        $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
-        $template->set_filenames(array('autosize_content_header'=> $file )); 
-        $template->concat('autosize_content', $template->parse('autosize_content_header', true));                           
-        $template->set_filenames(array('autosize_init_header'=> $file ));
-        	$theme=$user['theme'];    
-          $deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE);   
-          $defined_types = array_keys(ImageStdParams::get_defined_type_map()); 
-                         		
-				if($autosize_parametres->check_icon_v == 'on'){				 
-						$template->assign('cl_autosize_button', 
-						array(	'cl_autosize_info' => 'cl_autosize_info' ,
-                    'cl_autosize_info_1' => 'cl_autosize_info_' ,  
-								    'cl_autosize_info_2' => 'cl_autosize_info_2' ,    
-								    'URL' => $_SERVER['REQUEST_URI'] ,
-								    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
-								    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png',
-                    'ICON1' => AUTOSIZE_PATH . 'icons/button-no.png'
-								)
-
-							); 
-					$template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
-					$template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
-				}
-				 $template->set_filenames(
-						array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl',
-             'theme' => $theme   )
-					);
-			$template->concat('autosize_content', $template->parse('autosize_content_header', true));		
-      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
-        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
-        $template->func_combine_script(array('id'=>'my_script_2',
-        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
-        'require' => 'jquery'),
-        $template->smarty);
-        $template->assign(array( 
-                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
-                          ));
-					
-        $template->parse('mes_script');
-      }     
-            
-        return $template->parse( 'autosize_content', false);
-     				  }
-		}
-
-	} //public function cl_autosize_affiche
 	//===============================================================
 		/*
@@ -520,8 +682,14 @@
  			pwg_query($query);
 	  }
-	 
+    if (!isset($conf['cl_derivatives_sav']))  {    
+      $q = '
+        INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
+        VALUES ("cl_derivatives_sav","","sauvegarde derivatives")
+      ;';
+      pwg_query($q);      
+      }
  }
 
- function auto_memo_var($variables)
+ function print_var($variables)
 {
   ob_start();
Index: /extensions/Autosize/css/autosize.css
===================================================================
--- /extensions/Autosize/css/autosize.css	(revision 17502)
+++ /extensions/Autosize/css/autosize.css	(revision 17503)
@@ -44,23 +44,29 @@
 
 }
-#theImage { 
-
-   }
+#theImage {/*
+background-color: #DDE3E3;
+background-image: url('../images/quadrille_100.png');*/
+ /*height:auto;
+   */
+}
+/*
 .imageComment{
- 
+ background-color: green;
+background-image: url('../images/quadrille_100.png');
   }
 .licencetag {
-
+background-color:blue;
+background-image: url('../images/quadrille_100.png');
 }
 
 #theMainImage { 
 
-}
+} */
 #imageInfos{ 
 overflow:hidden ;
-
+ 
 
  }
- 
+
 #imageInfoBar {
 
Index: /extensions/Autosize/include/affiche.php
===================================================================
--- /extensions/Autosize/include/affiche.php	(revision 17502)
+++ /extensions/Autosize/include/affiche.php	(revision 17503)
@@ -1,59 +1,16 @@
 <?php  
-$visible=(isset($visible))?$visible:false;
 
+$visible=(isset($visible))?$visible:false; 
 $cl_version=isset($cl_version)?$cl_version:"";
 $cl_plugin=isset($cl_plugin)?$cl_plugin:"";
 $cl_visible=isset($conf['cl_auto']) ? $conf['cl_auto'] : 
-(isset($_GET['cl_visible'])?$_GET['cl_visible']:'true')
+(isset($_GET['cl_visible'])?$_GET['cl_visible']:'true'); 
+//==============================================================================
+$DEBUG_autosize = isset($_POST['cl_debug']) ? $_POST['cl_debug'] : "false" ;
+$DEBUG_autosize = isset($_GET['cl_debug']) ? $_GET['cl_debug'] : $DEBUG_autosize ;
+$DEBUG_autosize = isset($conf['cl_debug']) ? $conf['cl_debug'] : $DEBUG_autosize ; 
+//===========================================================================
+$cookies="' x '"; 
 
- ; 
-//==============================================================================
-$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
-$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
-$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
-//===========================================================================
-$cookies="' x '";
-
-$current = $template->get_template_vars('current');
-if (isset($_COOKIE['picture_deriv']))
-  {
-  if (isset($_COOKIE['theImageWidth']))
-  $cookies =  '"'.$_COOKIE['theImageWidth']." x ".  $_COOKIE['theImageHeight'] .'"';
-
-    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
-    {
-      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
-    }
-    setcookie('picture_deriv', false, 0, cookie_path() );
-  }
-  $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
-  $defined_types = array_keys(ImageStdParams::get_defined_type_map());  
-
-if (isset($current)){ 
-    if (!isset($current['selected_derivative'])){  
-      $model= $defined_types[count($defined_types)-1];
-      $selected_derivative =      $current['derivatives'][$model];
-       $img_all= $derivative->get_all($derivative->src_image);
-      $template->append('current', array(
-      'selected_derivative' => $selected_derivative
-    ), true);
-
-
-    $current = $template->get_template_vars('current');
-        } 
-         $derivative=$current['selected_derivative'] ;
-          $imgScaledWH=$derivative->src_image->get_size();
-          $imgSizeWH  =  $derivative->get_size();	
-          $img_type  =  $derivative->get_type();	
-          $img_url  = $derivative->get_url();
-          $img_all= $derivative->get_all($derivative->src_image);
-          $scaled_size=$derivative->get_size_hr(); //792 x 441
-          $scaled_size=$derivative->get_scaled_size_htm(); // width="792" height="441"
-         //================= taille mis a l'échelle 
-          $scaled_size=$derivative->get_scaled_size(100,100); // array([0]=>100,[1]=>55)
-          $src= $derivative->src_image ;
-       
-    } 
-  
 $img_width=isset($imgScaledWH)?$imgSizeWH[0]:"480";
 $img_height=isset($imgScaledWH)?$imgSizeWH[1]:"320";
@@ -61,12 +18,11 @@
 $img_scaled_width=isset($imgScaledWH)?$imgScaledWH[0]:"480";
 $img_scaled_height=isset($imgScaledWH)?$imgScaledWH[1]:"320";
-
-
  
 $src_img_h=isset($_POST['src_img_h'])?$_POST['src_img_h']: $img_height  ;
 $src_img_w= isset($_POST['src_img_w'])?$_POST['src_img_w']:  $img_width ;
+ 
+$window_height= isset($_SESSION['windowHeight'])?$_SESSION['windowHeight']: $img_scaled_height ;
+$window_width= isset($_SESSION['windowWidth'])?$_SESSION['windowWidth']: $img_scaled_width    ;
 
-$window_height= isset($_POST['window_height'])?$_POST['window_height']: $img_scaled_height ;
-$window_width= isset($_POST['window_width'])?$_POST['window_width']: $img_scaled_width    ;
 global $size ;
 $size=	array(
@@ -76,7 +32,9 @@
             'window_width' => $window_width
           );
-
+        
   $my_path = AUTOSIZE_PATH_ABS;
   $theme=$user['theme'];
+
+
   $user_status = $user['status'] ;
 
@@ -88,36 +46,25 @@
 									);	
 if (!isset($conf['prefix_thumbnail'])) $conf['prefix_thumbnail']="TN_";   
+//======================================================   
+
+//=== type possible ===
+if(isset($defined_types))
+    foreach ($defined_types as $type_size){
+      $value = $type_size;
+      $options[$value] = $type_size;    
+    }  
+
+ //===========================================
+  	$template->assign(
+  					array(  
+            'select_type' =>$select_type,
+            'select_map' =>$select_type,
+
+            'pictureDeriv' =>$pictureDeriv ,
+
+            'maxi_img' =>$maxi_img ,
+            'ratio' =>$img_scaled_width/$img_scaled_height ,          
 
 
-//======================================================   
-
-$options['Autosize'] = ''.l10n('Autosize').''; 
-foreach ($defined_types as $type_size){
-  $value = $type_size;
-  $options[$value] = $type_size;   
-}  
-//===================
-$value=0;
-$liste_type="";
-if(isset($img_all ))
-foreach ($img_all as $img_select){
-          $imgSizeWH  =  $img_select->get_size();	
-          $img_type  =  $img_select->get_type();	
-          $img_url  = $img_select->get_url();  
-
-          $liste_type .= $img_type.",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1]."|" ;
-          if(strtolower($img_type)=="original") break ;
-
-
-}  
-
-//===================================     
-     	
-  	$template->assign(
-  					array( 
-            'ratio' =>$img_scaled_width/$img_scaled_height ,
-            'cookies' =>  $cookies ,
-            'deriv_type' =>$deriv_type ,
-            'liste_type' => $liste_type ,
             'webmaster_type' => array(
                                             'OPTIONS' => $options,
@@ -150,4 +97,8 @@
 
             'theme' => $theme,
+
+            'windowHeight' => $window_height,
+            'windowWidth' =>  $window_width,
+
             'SCALED_WIDTH' => $img_scaled_width,
             'SCALED_HEIGHT' => $img_scaled_height,      
@@ -158,4 +109,5 @@
             'MINI_HEIGHT' => $autosize_parametres->mini_height,
             'MINI_WIDTH' 	=> $autosize_parametres->mini_width,
+
             'MINI_HEIGHT2' => $autosize_parametres->mini_height2,
             'MINI_WIDTH2' 	=> $autosize_parametres->mini_width2,
@@ -176,6 +128,7 @@
 
             'user_status'   => get_user_status($user_status)  ,
-'Size' => $size 
-          
+            'SRC_IMG' => $SRC_IMG,
+            'liste_type' => $liste_type ,
+            'Size' => $size        
 					
 				 )
Index: /extensions/Autosize/js/Affiche_script.js
===================================================================
--- /extensions/Autosize/js/Affiche_script.js	(revision 17502)
+++ /extensions/Autosize/js/Affiche_script.js	(revision 17503)
@@ -1,3 +1,2 @@
-
 // problème avec GMaps+diaporama:
 // corriger   gmaps_pip.class.inc.php ajouter ligne 90 if ( !isset($_GET['slideshow']))
@@ -7,14 +6,23 @@
   *  document ready
   ********************************************/
+
+
   jQuery(document).ready(function (jQuery) {
+
+
+
+
     var Type_Img;
     var theImg;
+    var Zone_image;
+
     /******************************************
     * Save_cookies
     ******************************************/
     Save_cookies = function (parametres) {
-      if (parametres.typeSave) document.cookie = 'picture_deriv=' + parametres.typeSave + ';path="' + "/" + '" ';
-      if (parametres.typeSave) jQuery.cookie('picture_deriv', parametres.typeSave, { path: "/" });
-      if (parametres.pictureMap) jQuery.cookie('picture_map', parametres.pictureMap, { path: "/" });
+      if (parametres.pictureDeriv) document.cookie = 'picture_deriv=' + parametres.pictureDeriv + ';path="' + "/" + '" ';
+
+      if (parametres.pictureDeriv) jQuery.cookie('picture_deriv', parametres.pictureDeriv, { path: "/" });
+      if (parametres.pictureMap) jQuery.cookie('picture_map', parametres.pictureDeriv, { path: "/" });
       if (parametres.imgSrc) jQuery.cookie('imgSrc', parametres.imgSrc, { path: "/" });
       if (parametres.theMainImageHeight) jQuery.cookie('theMainImageHeight', parametres.theMainImageHeight, { path: "/" });
@@ -23,10 +31,10 @@
       if (parametres.theImageWidth) jQuery.cookie('theImageWidth', parametres.theImageWidth, { path: "/" });
       if (parametres.windowHeight) jQuery.cookie('windowHeight', parametres.windowHeight, { path: "/" });
-      if (parametres.windowWidth) jQuery.cookie('windowWidth', parametres.WindowWidth, { path: "/" });
+      if (parametres.windowWidth) jQuery.cookie('windowWidth', parametres.windowWidth, { path: "/" });
     }
     //____________________ Save_cookies _____________________________
     Get_cookies = function () {
       parametres = {
-        typeSave: jQuery.cookie('picture_deriv'),
+        pictureDeriv: jQuery.cookie('picture_deriv'),
         pictureMap: jQuery.cookie('picture_map'),
         imgSrc: jQuery.cookie('imgSrc'),
@@ -116,5 +124,5 @@
     //====================================
     set_cl = function (Valid) {
-      if (typeof Valid == "undefined") Valid = options.useMap.match(RegExp("Autosize", "gi")) || false;
+      if (typeof Valid == "undefined") Valid = options.select_map.match(RegExp("Autosize", "gi")) || false;
       if (typeof options.cl_visible == "undefined") return;
       if (typeof src1 == "undefined") return;
@@ -131,5 +139,11 @@
       }
 
-      if ((typeof Zone_image != "undefined") && typeof Zone_image.image != "undefined" && Valid) {
+      if (!Valid) {
+        Zone_image.image.height = Zone_image.image_init.height;
+        Zone_image.image.width = Zone_image.image_init.width;
+        src = src6;
+      }
+      if ((typeof Zone_image != "undefined") && typeof Zone_image.image != "undefined") {
+
         Zone_image.zoom = (Zone_image.image.height / Zone_image.image_init.height);
         zoom_cl = parseInt(100 * Zone_image.zoom);
@@ -161,10 +175,12 @@
           color_back = jQuery('body').css("color");
         jQuery('#bp_cla span').css({ color: color_back, aling: "center" });
-        jQuery('#auto_details').text(" (" + Zone_image.image.width + " x " + Zone_image.image.height + ")");
-
+        if (options.src_deriv) {
+          jQuery('.auto_details').text(" (" + Zone_image.image.width + " x " + Zone_image.image.height + ") " + options.src_deriv);
+        }
         //===============================================
       } else {
         src = src6;
-        jQuery('#auto_details').text("");
+        jQuery('.auto_details').text("");
+
       }
       bp_scr = jQuery('#bp_img_cla');
@@ -195,5 +211,8 @@
         return;
       }
-      nom_map = theImg.useMap.replace("#", "");
+      if (theImg)
+        nom_map = theImg.useMap.replace("#", "");
+      else
+        nom_map = "Autosize";
       maps = jQuery("map[name='" + nom_map + "']");
       if (maps.length == 0) return;
@@ -228,4 +247,6 @@
     jQuery(window).load(function () {
       href = location.href;
+      options.old_theme = options.theme;
+
       var aff_ok = false;
       if (DEBUG_autosize == "true") {
@@ -275,15 +296,44 @@
       infos_imageInfos = jQuery(imageInfos_id).infos(true);             // information
       infos_theMainImage = jQuery(theMainImage_id).infos(true);         // Image 
-      if (infos_theMainImage.visible == false) {
-
-      }
+
       jQuery("#loading").show(0);
 
       if (options.check_desc_v) {
+        info_comments = jQuery("#comments").infos(true);
         infos_Licence = jQuery(".licencetag").infos(true);
         infos_imageComment = jQuery(imageComment_id).infos(true);
-        h01 = (infos_Licence.general.height);
-        h02 = (infos_imageComment.general.height);
-        options.marge_basse += Math.max(h01, h02);
+        h01 = info_comments.top - infos_theMainImage.bottom;
+      h02 = infos_imageComment.general.bottom - infos_theMainImage.bottom; 
+        delta_h = infos_imageInfos.bottom - infos_imageInfos.top;
+        if (options.theme.match(RegExp("blanc", "gi")) || options.theme.match(RegExp("pure", "gi")) 
+         || options.theme.match(RegExp("hr_", "gi")))  {
+    
+          h01 = infos_Licence.general.bottom-infos_theMainImage.bottom;
+          options.marge_basse += h01;
+          options.marge_gauche += 10;
+          options.marge_droite += 10;
+
+        } else {
+
+          if (options.theme != "simple")
+            if (delta_h > 5 && (infos_imageInfos.top > infos_theMainImage.bottom)) {
+              if (infos_imageComment.visible) {
+               
+              }
+            }
+
+
+          h01 = infos_Licence.general.bottom - infos_theMainImage.bottom;
+          h02 = infos_imageComment.general.bottom - infos_theMainImage.bottom;
+
+          if (Type_Img == "pamoorama") {
+            h01 = infos_Licence.general.bottom - infos_theMainImage.bottom;
+           
+            ;
+            options.marge_basse += (h01);
+          } else
+            options.marge_basse += Math.max(h01, h01);
+
+        }
       }
 
@@ -303,9 +353,15 @@
         container: {
           width: infos_theImage.general.width,
-          height: infos_window.height - (infos_theImage.top)
-        }
-      }
+          height: infos_window.height - (infos_theImage.top),
+          margesWidth: infos_window.width - infos_theImage.width + (options.marge_droite + options.marge_gauche)
+        }
+      }
+
+
       if (Type_Img == "pamoorama") {
         jQuery(theMainImage_id).width(Zone_image.container.width);
+        jQuery(theMainImage_id).height(Zone_image.container.height);
+        jQuery(theImage_id).width(Zone_image.container.width);
+        jQuery(theImage_id).height(Zone_image.container.height);
       }
 
@@ -314,18 +370,49 @@
       ***********************************************************/
       jQuery(window).resize(function (event, ui) {
+        infos_window = jQuery(window).infos();
+        infos_imageInfos = jQuery("#imageInfos").infos(true);
+        old_w = infos_theImage.width;
         infos_theImage = jQuery(theImage_id).infos(true);
-        infos_window = jQuery(window).infos();
+        if (options.set_sw) {
+          if (Type_Img == "pamoorama") {
+            if (options.set_sw == "menuSwitcher") {
+
+            } else {
+              p_width = jQuery(theImage_id).width();
+            }
+            if (infos_imageInfos.visible)
+              p_width = infos_window.width - infos_theImage.left - infos_imageInfos.width - 20;
+            else
+              p_width = infos_window.width - infos_theImage.left - 20;
+            jQuery(theImage_id).width(p_width);
+            infos_theImage = jQuery(theImage_id).infos(true);
+
+
+          }
+        }
+        if ((old_w - infos_theImage.width) != 0) {
+          Zone_image.container.width = infos_theImage.width;
+        }
+
+
         infos_body = jQuery("body").infos();
         infos_content = jQuery(content_id).infos();
 
+
+        // imageInfos
+
+
+
         infos_theImageAndInfos = jQuery(theImageAndInfos_id).infos();  // Cadre general 
-        Zone_image.container = { height: infos_window.height - (infos_theImage.top),
-          width: infos_theImage.width
+        //=============================================================
+
+        Zone_image.container = {
+          height: infos_window.height - (infos_theImage.top),
+          width: Zone_image.container.width,
+          margesWidth: infos_window.width - infos_theImage.width
         };
 
         if (options.theme.match(RegExp("simple", "gi"))) {
           jQuery(theMainImage_id).css({ maxWidth: "none" });
-          Zone_image.container.height = infos_window.height - infos_theImage.top - infos_content.general.marges.height - (infos_theImage.general.marges.height);
-          //jQuery("#menubar").css("margin-right", "0");
           infos_menubar = jQuery("#menubar").infos(true);
           if (infos_menubar.visible == true) {
@@ -335,8 +422,9 @@
 
         jQuery(theImage_id).height(Zone_image.container.height + 2);
+
+        if (DEBUG_autosize == "no") return;
+
+        Autosize_resize(true, options);
         jQuery("#loading").hide(fade_in);
-        if (DEBUG_autosize == "no") return;
-        Autosize_resize(true, options);
-
       });
       //_____________ widow.resize _______________
@@ -352,10 +440,10 @@
       infos_llgboh2 = jQuery("#llgboh2").infos();
       marges_llgbo = 0;
-      //==========================================================================================
-      jQuery("#loading").show(0);
-      if (DEBUG_autosize != "no")
-        init_gen();
+      //========================================================================================== 
+
+      init_gen();
       jQuery(window).resize();
       jQuery(window).resize();
+
     });
     //__________________window.onload_________________
@@ -370,11 +458,9 @@
         if (typeof theMainImage_id != "undefined") {
           infos_window = jQuery(window).infos(true);
-          infos_theImage = jQuery("#" + infos_theImage.id).infos(true);
-          infos_theMainImage = jQuery("#" + theMainImage.id).infos(true);
-          useMap = options.useMap;
-
+          infos_theImage = jQuery(theImage_id).infos(true);
+          infos_theMainImage = jQuery(theMainImage_id).infos(true);
           Save_cookies({
             pictureMap: cookies.pictureMap,
-            typeSave: cookies.typeSave,
+            pictureDeriv: cookies.pictureDeriv,
             windowHeight: infos_window.height,
             windowWidth: infos_window.width,
@@ -408,5 +494,4 @@
     options = jQuery.extend(Autosize_options, options);
     var defaults = {
-      useMap: '#Autosize',
       imageAutosizeMargin: 0,
       imageAutosize: false,
@@ -417,6 +502,5 @@
     options = jQuery.extend(defaults, options);
 
-    options.liste_type = options.liste_type.split("|");
-    options.liste_type.pop();
+
     for (i = 0; i < options.liste_type.length; i++) {
       options.liste_type[i] = options.liste_type[i].split(",");
@@ -447,5 +531,6 @@
     //===================
     var cookies = Get_cookies();
-    var Zone_image;
+
+
     var theMainImage_id = "#theMainImage";
     var theImage_id = "#theImage";
@@ -459,8 +544,8 @@
     var llgbo_id = "#llgbo0";
     var marges_llgbo = 0;
-    var type_size = cookies.typeSave; // xxx
+    var pictureDeriv = cookies.pictureDeriv; // xxx
     var useMap = cookies.pictureMap; // #mapxxx
     var user_status = options.user_status;
-    var type_size_maxi = eval("options." + user_status + "_type"); //limite taille
+    var pictureDeriv_maxi = eval("options." + user_status + "_type"); //limite taille
 
 
@@ -471,13 +556,23 @@
     //=============================================================
     jQuery("#theMainImage," + theMainImage_id + ",.preload, .next1 , ").load(function (e) {
-      if (this.complete) {
-        jQuery("#loading").hide(1000);
-      }
-      //_________ theMainImage  ___________
+      jQuery("#loading").hide(1000);
+      jQuery(this).removeAttr("width");
+      jQuery(this).removeAttr("height");
+      jQuery(this).css({ height: "", width: "" });
 
       if (typeof theMainImage_id != "undefined")
-        if (init_img(this))
+        if (!init_img(this)) {
           nu_img = 0;
-    });
+        }
+
+      jQuery('#derivativeSwitchBox .switchCheck').css('visibility', 'hidden');
+      jQuery('#derivativeChecked' + options.pictureDeriv).css('visibility', 'visible');
+
+      jQuery(window).resize();
+
+
+
+    });
+    //_________ theMainImage  ___________
 
 
@@ -485,13 +580,6 @@
       location.reload();
     });
+
     var mouseLocation = new Point(-500, -500);
-    //========================================================
-    jQuery("#pamoorama").live("on", function (e) {
-      myPamoorama = window.myPamoorama;
-    });
-    jQuery("#pamoorama_inner").live("on", function (e) {
-      myPamoorama = window.myPamoorama;
-    });
-
     function Point(x, y) {
       this.x = x; this.y = y;
@@ -554,6 +642,11 @@
     //==========================================================
     jQuery("map area").mouseover(function (e) {
-      nok = theImg.useMap;
-      hok = this;
+      try {
+        nok = theImg.useMap;
+        hok = this;
+      }
+      catch (r) {
+
+      }
     });
 
@@ -623,9 +716,241 @@
 
 
+
+    // Custom Event, ON to turn on a debug.
+    jQuery('.debug').live('ON', function (e) {
+
+      nu_img = jQuery(this).text();
+      jQuery('.debug').trigger('OFF');
+      jQuery(this).addClass('debugOn');
+
+    });
+
+    // On Click = debugs On
+    jQuery('.debug').live('click', function (e) {
+      i = jQuery(this).text();
+      jQuery(this).trigger('ON');
+    });
+
+    // Custom Event, Turn off a debug
+    jQuery('.debug').live('OFF', function (e) {
+      jQuery(this).removeClass('debugOn');
+    });
+
+    // on Double Click, remove the debug from the DOM
+    jQuery('.debug').live('dblclick', function () {
+      jQuery(this).fadeOut(function () { jQuery(this).remove() });
+    });
+
+    // Add another debug to the DOM
+    jQuery('#adddebugs').click(function () {
+      i = jQuery('.debug').length;
+      jQuery('<div>' + i + '</div>')
+    .addClass('debug')
+    .appendTo('#debugsContainer');
+    });
+
+
+    /*********************************
+    *
+    ********************************/
+    jQuery("#menuSwitcher,#infoSwitcher").click(function (e) {
+      options.set_sw = this.id;
+      setTimeout(function () { jQuery(window).resize() }, 10);
+      setTimeout(function () { jQuery(window).resize() }, 12);
+      nu_img = 0;
+    });
+
+
+    //===========================================
+    // jQuery("#theImageAndInfos").trigger("ON");
+    //===========================================
+    jQuery("#theImageAndInfos").live('ON', function (e) {
+      infos_theImageAndInfos = jQuery("#theImageAndInfos").infos();
+      //   setTimeout(function () { Autosize_resize(true) }, 100);
+      nu_img = 0;
+    }); // fin click #theImageAndInfos ON
+    jQuery("#theImageAndInfos").resize(function (e) {
+
+      nu_img = 0;
+    });
+
+
+    jQuery("#linkAutosize").click(function (e) {
+      nu_img = 0;
+    });
+    //==================================
+    //
+    //===================================
+    jQuery('#derivativeCheckedAutosize').click(function () {
+      try {
+        pathnames = jQuery(this).attr("href").split(":");
+
+        //  eval(pathnames[1]);
+      } catch (e) {
+        n = false;
+      }
+    }); // fin click derivativeCheckedAutosize
+    //====================================================
+    jQuery("#derivativeSwitchBox a").click(function () {
+      theImg = document.getElementById(theMainImage_id.replace("#", ""));
+      if (theImg) {
+        pathnames = jQuery(this).attr("href").split(":")[1].toString();
+        selecteur = pathnames.split(",")[2].replace("')", "").replace("'", "").replace(" ", "");
+        if (this.name) {
+          options.select_type = this.name;
+          options.pictureDeriv = this.name;
+          options.select_map = this.name;
+          pathnames = pathnames.replace(selecteur, this.name);
+        } else {
+          options.select_type = selecteur;
+          options.pictureDeriv = selecteur;
+          options.select_map = selecteur;
+        }
+        jQuery("#derivativeSwitchBox span").removeClass("auto_details linkAutosize");
+        jQuery("#derivativeSwitchBox a").removeClass("auto_details linkAutosize");
+        if (options.select_type == "Autosize" || options.select_type == "SelMaxi") {
+          spans = jQuery("#derivativeChecked" + options.select_type).next();
+          spans.addClass("linkAutosize");
+          spans.find("span").addClass("auto_details");
+          jQuery(".auto_details").text("");
+        }
+
+        try {
+          //      eval(pathnames);
+          n = true;
+        } catch (e) {
+          n = false;
+        }
+      }
+    });
+    //__________ fin click #derivativeSwitchBox a ____________
+
+    jQuery("input").click(function () {
+      if (this.name.match(RegExp("_enabled", "gi"))) {
+        sel = "[name*=" + this.name + "]";
+        obj = jQuery("tr" + sel);
+
+        if (this.checked)
+          obj.css({ backgroundColor: "green", color: "white" });
+        else
+          obj.css({ backgroundColor: "red", color: "white" });
+        return;
+      }
+      return;
+    });
+    //____________________ set_llgbo _____________________________
+
+    //====================================
+    Autosize_init = function (name, value) {
+      img_defaut = { height: options.scaled_height, width: options.scaled_width };
+      img_reelle = { height: options.img_height, width: options.img_width };
+      img_init = { height: options.img_height, width: options.img_width };  // taille initiale
+
+      img_finale = img_init;
+
+      useMap = infos_theMainImage.useMap; // #mapmedium
+
+      useMap = cookies.pictureMap; // #mapxxx
+      pictureDeriv = cookies.pictureDeriv; //picturederiv xxx
+
+
+      old_img = cookies.imgSrc;
+      old_window_height = cookies.windowHeight || jQuery(window).height();
+      old_window_width = cookies.windowWidth || jQuery(window).width();
+      old_img_h = cookies.imgHeight;
+      old_img_w = cookies.imgWidth;
+      if (infos_theMainImage.visible == true) {
+        theImg = document.getElementById(theMainImage_id.replace("#", ""));
+        theImg.useMap = useMap;
+      }
+      fade_in = parseInt(options.fade_in || 0);
+
+    }
+    //____________________ Autosize_init _____________________
+
+    /***************************
+    * Autosize_resize
+    ***************************/
+    Autosize_resize = function (force, parametres) {
+      if (Get_dimensions(force, parametres)) {
+        jQuery(theImageAndInfos_id).css({ height: "auto" });
+        if (Type_Img == "pamoorama") {
+          Set_Pamoorama({ width: Zone_image.container.width, height: Zone_image.image.height });
+          if (nopano)
+            if (window.myPamoorama.options.autoscrollOnLoad) {
+              window.myPamoorama.startAnimRight();
+            }
+        } else {
+
+          jQuery(theMainImage_id).height(Zone_image.image.height);
+          jQuery(theMainImage_id).width(Zone_image.image.width);
+        }
+
+
+        set_cl(true);
+      } else {
+        jQuery(theImage_id).height(Zone_image.image.height + Zone_image.marges.height);
+        Set_Pamoorama({ width: Zone_image.container.width, height: Zone_image.image.height });
+        set_cl(false);
+
+      }
+
+
+      Set_llbgo(true);
+      return true;
+    };
+    //_________________Autosize ____________________________________   
+
+    /*****************
+    * changeImgSrc 
+    ******************/
+    changeImgSrc = function (url, typeSave, typeMap) {
+      theImg = document.getElementById(theMainImage_id.replace("#", ""));
+      if (theImg.src) {
+        theImg.removeAttribute("width");
+        theImg.removeAttribute("height");
+        // jQuery(theMainImage_id).eq(0).removeAttr("style");
+        jQuery('#derivativeSwitchBox .switchCheck').css('visibility', 'hidden');
+        jQuery('#derivativeChecked' + typeSave).css('visibility', 'visible');
+        pictureMap = "#map" + typeMap;
+        theImg.useMap = pictureMap;
+        src = jQuery(theImg).css("backgroundImage");
+        if (theImg.src)
+          if (theImg.src.match(RegExp(url, "gi"))) {
+            jQuery("#loading").hide(0);
+          } else {
+            jQuery("#loading").show(0);
+          } else {
+          jQuery("#loading").hide(0);
+        }
+        Zone_image.src = theImg.src;
+        theImg.src = url; // charge Image       
+        //===================================================
+        options.pictureDeriv = typeSave;
+        options.pictureMap = typeMap;
+        Save_cookies({
+          pictureDeriv: typeSave,
+          pictureMap: pictureMap,
+          imgSrc: url
+        });
+        cookies = Get_cookies();
+      }
+    }
+    //__________________ changeImgSrc ______________________
+
+    /*****************************
+    *      pamoorama
+    ******************************/
+
+    jQuery("#pamoorama").bind("on", function () { alert($(this).text()); });
+    jQuery("#pamoorama").bind("on", function (e) {
+      myPamoorama = window.myPamoorama;
+    });
+    jQuery("#pamoorama_inner").live("on", function (e) {
+      myPamoorama = window.myPamoorama;
+    });
     jQuery('#pamoorama').live('ON', function (e) {
       jQuery(jQuery('.debug').get(1)).trigger('ON');
-      if (typeof Bandeau_bas == "undefined" || Bandeau_bas.width == 0) {
-
-      }
+      jQuery(window).resize();
     });
 
@@ -635,6 +960,4 @@
     jQuery("#theImage").live('Start_right', function (e) {
       if (typeof Zone_image == "undefined") return
-      if (nu_img == "") nu_img = 7;
-      jQuery(jQuery('.debug').get(nu_img)).trigger('ON');
       test_w = window.myPamoorama.autoSlideFx.to;
       test_w = window.myPamoorama.autoScrollFx.to;
@@ -646,7 +969,4 @@
       nw = (200 * Zone_image.container.width) / window.myPamoorama.imageWidth;
       jQuery("#pamoorama_frame").width(nw);
-
-
-
     });
     //===============================================
@@ -664,255 +984,13 @@
     });
 
-    // Custom Event, ON to turn on a debug.
-    jQuery('.debug').live('ON', function (e) {
-
-      nu_img = jQuery(this).text();
-      jQuery('.debug').trigger('OFF');
-      jQuery(this).addClass('debugOn');
-
-    });
-
-    // On Click = debugs On
-    jQuery('.debug').live('click', function (e) {
-      i = jQuery(this).text();
-      jQuery(this).trigger('ON');
-    });
-
-    // Custom Event, Turn off a debug
-    jQuery('.debug').live('OFF', function (e) {
-      jQuery(this).removeClass('debugOn');
-    });
-
-    // on Double Click, remove the debug from the DOM
-    jQuery('.debug').live('dblclick', function () {
-      jQuery(this).fadeOut(function () { jQuery(this).remove() });
-    });
-
-    // Add another debug to the DOM
-    jQuery('#adddebugs').click(function () {
-      i = jQuery('.debug').length;
-      jQuery('<div>' + i + '</div>')
-          .addClass('debug')
-          .appendTo('#debugsContainer');
-    });
-
-
-    /*********************************
-    *
-    ********************************/
-    jQuery("#menuSwitcher,#infoSwitcher").click(function (e) {
-
-      setTimeout(function () { jQuery(window).resize() }, 10);
-      setTimeout(function () { jQuery(window).resize() }, 12);
-      nu_img = 0;
-    });
-
-
-    //===========================================
-    // jQuery("#theImageAndInfos").trigger("ON");
-    //===========================================
-    jQuery("#theImageAndInfos").live('ON', function (e) {
-      infos_theImageAndInfos = jQuery("#theImageAndInfos").infos();
-      //   setTimeout(function () { Autosize_resize(true) }, 100);
-      nu_img = 0;
-    }); // fin click #theImageAndInfos ON
-    jQuery("#theImageAndInfos").resize(function (e) {
-
-      nu_img = 0;
-    });
-
-
-    jQuery("#linkAutosize").click(function (e) {
-      nu_img = 0;
-    });
-    //==================================
-    //
-    //===================================
-    jQuery('#derivativeCheckedAutosize').click(function () {
-      pathnames = jQuery(this).attr("href").split(":");
-      try {
-        eval(pathnames[1]);
-      } catch (e) {
-        n = false;
-      }
-    }); // fin click derivativeCheckedAutosize
-    //====================================================
-    jQuery("#derivativeSwitchBox a").click(function () {
-      theImg = document.getElementById(theMainImage_id.replace("#", ""));
-      if (theImg) {
-        pathnames = jQuery(this).attr("href").split(":");
-
-        try {
-          eval(pathnames[1]);
-          n = true;
-        } catch (e) {
-          n = false;
-        }
-
-        infos_theMainImage = jQuery(theMainImage_id).infos();
-
-        theImg.removeAttribute("width");
-        theImg.removeAttribute("height");
-
-        var nw = "100% x 100%".split("x");
-        if (jQuery(this).text().match(RegExp("x", "gi"))) {
-          nw = jQuery(this).text().split("(")[1].split(")")[0];
-          nw = nw.split("x");
-          init_img(theImg);
-          wx = parseInt(nw[0]);
-          wh = parseInt(wx / Zone_image.image_init.rapport);
-
-          jQuery(theImg).width(wx);
-          jQuery(theImg).height(wh);
-          set_cl(useMap == "#Autosize");
-          Set_llbgo();
-        }
-
-      }
-
-    });  // fin click #derivativeSwitchBox a
-
-    jQuery("input").click(function () {
-      if (this.name.match(RegExp("_enabled", "gi"))) {
-        sel = "[name*=" + this.name + "]";
-        obj = jQuery("tr" + sel);
-
-        if (this.checked)
-          obj.css({ backgroundColor: "green", color: "white" });
-        else
-          obj.css({ backgroundColor: "red", color: "white" });
-
-        return;
-      }
-
-
-
-      return;
-
-
-
-
-    });
-    //____________________ set_llgbo _____________________________
-
-    //====================================
-    Autosize_init = function (name, value) {
-      img_defaut = { height: options.scaled_height, width: options.scaled_width };
-      img_reelle = { height: options.img_height, width: options.img_width };
-      img_init = { height: options.img_height, width: options.img_width };  // taille initiale
-
-      img_finale = img_init;
-
-      useMap = infos_theMainImage.useMap; // #mapmedium
-
-      useMap = cookies.pictureMap; // #mapxxx
-      typeSave = cookies.typeSave; //picturederiv xxx
-
-
-      old_img = cookies.imgSrc;
-      old_window_height = cookies.windowHeight || jQuery(window).height();
-      old_window_width = cookies.windowWidth || jQuery(window).width();
-      old_img_h = cookies.imgHeight;
-      old_img_w = cookies.imgWidth;
-      if (infos_theMainImage.visible == true) {
-        theImg = document.getElementById(theMainImage_id.replace("#", ""));
-        theImg.useMap = useMap;
-      }
-      fade_in = parseInt(options.fade_in || 0);
-
-    }
-    //____________________ Autosize_init _____________________
-
-    /***************************
-    * Autosize_resize
-    ***************************/
-    Autosize_resize = function (force, parametres) {
-      theImg = document.getElementById(theMainImage_id.replace("#", ""));
-      if (theImg) {
-        theImg.removeAttribute("width");
-        theImg.removeAttribute("height");
-      }
-      if (Get_dimensions(force, parametres)) {
-
-        jQuery(theImageAndInfos_id).css({ height: "auto" });
-        if (Type_Img == "pamoorama") {
-          Set_Pamoorama({ width: Zone_image.container.width - 5, height: Zone_image.image.height });
-          if (nopano)
-            if (window.myPamoorama.options.autoscrollOnLoad) {
-              window.myPamoorama.startAnimRight();
-            }
-        } else {
-
-          jQuery(theMainImage_id).height(Zone_image.image.height);
-          jQuery(theMainImage_id).width(Zone_image.image.width);
-        }
-
-
-        set_cl(true);
-      } else {
-
-        Set_Pamoorama({ width: Zone_image.container.width, height: Zone_image.image.height });
-        set_cl(false);
-      }
-
-
-      Set_llbgo(true);
-      return true;
-    };
-    //_________________Autosize ____________________________________   
-
-
-
-
-
-
-
-
-
-    /*****************
-    * changeImgSrc 
-    ******************/
-    changeImgSrc = function (url, typeSave, useMap) {
-      theImg = document.getElementById(theMainImage_id.replace("#", ""));
-      if (theImg) {
-        theImg.removeAttribute("width");
-        theImg.removeAttribute("height");
-        //  theImg.useMap = "#map" + useMap;
-        jQuery('#derivativeSwitchBox .switchCheck').css('visibility', 'hidden');
-        jQuery('#derivativeChecked' + useMap.replace("#", "")).css('visibility', 'visible');
-        options.useMap = useMap;
-        if (useMap.match("Autosize")) {
-          pictureMap = "#" + "Autosize";
-        } else {
-          pictureMap = "#map" + typeSave;
-        }
-        theImg.useMap = pictureMap;
-        if (theImg.src.match(RegExp(url, "gi"))) {
-          jQuery("#loading").hide(0);
-        } else {
-          jQuery("#loading").show(0);
-        }
-        theImg.src = url; // charge Image       
-        //===================================================
-        Save_cookies({
-          typeSave: typeSave,
-          pictureMap: pictureMap,
-          imgSrc: url
-        });
-        cookies = Get_cookies();
-      }
-    }
-    //__________________ changeImgSrc ______________________
-
     /************************************
-    *
+    * Wait_pamoorama
     ************************************/
     Wait_pamoorama = function () {
       if (Type_Img != "pamoorama") return;
-
-      // jQuery("#loading").attr("id", "theMainImage");
       tempo = 0;
-
       Wait_pamoorama_st = false;
+
+
       while (Wait_pamoorama_st == false) {
         Wait_pamoorama_st = Wait_pamoorama_time();
@@ -920,16 +998,11 @@
       }
       tempo = 0;
-
-      Wait_pamoorama_st = false;
-      while (Wait_pamoorama_st == false) {
-        Wait_pamoorama_st = Wait_pamoorama_time();
-        jQuery.noop()
-      }
-
-      if (nopano)
+      if (nopano) {
         if (window.myPamoorama.options.autoscrollOnLoad) {
           window.myPamoorama.startAnimRight();
-          jQuery.noop()
-        }
+          jQuery.noop();
+        }
+
+      }
 
     }
@@ -937,14 +1010,11 @@
 
     Wait_pamoorama_time = function () {
-
+      if (nopano == true) return true;
       if (jQuery("#pamoorama").length) {
         tempo = tempo + 1;
-
+        jQuery("#loading").show(1000);
         mypanorama = window.myPamoorama;
         if (!mypanorama) {
-          jQuery("#loading").show(5000);
-          tempo = tempo + 1;
-          if (tempo > 5000) return true;
-          nopano = false;
+          if (tempo > 500) return true;
           setTimeout("Wait_pamoorama_time()", 500);
           return false;
@@ -953,11 +1023,10 @@
 
         if (mypanorama.skipInit == false) {
-          if (tempo > 4000) return true;
+          if (tempo > 500) return true;
           setTimeout("Wait_pamoorama_time()", 500);
           return false;
         }
         //=============================================================
-        infos_pamoorama = jQuery("#pamoorama").infos();
-        if (Math.abs(infos_pamoorama.height) < 50) {
+        if (Math.abs(mypanorama.imageHeight) < 100) {
           setTimeout("Wait_pamoorama_time()", 500);
           return false;
@@ -965,5 +1034,8 @@
 
         nopano = true;
-        jQuery("#pamoorama").show(1000);
+        Zone_image.image_init = { width: mypanorama.imageWidth,
+          height: mypanorama.imageHeight
+        }
+        jQuery("#pamoorama").trigger("ON");
         return true;
 
@@ -1026,5 +1098,4 @@
         jQuery("#ret_autosize").val(infos_theMainImage.src);
         if (typeof infos_theImage == "undefined") return;
-
         jQuery("#ret_autosize").trigger('ON', {
           width: img_w,
@@ -1045,4 +1116,7 @@
     **********************/
     init_img = function (theImg) {
+      if (theImg.complete == false) {
+        return;
+      }
       name_src = theImg.src;
       img_init = { width: jQuery(theImg).width(), height: jQuery(theImg).height() }
@@ -1052,20 +1126,18 @@
       if (typeof theImg.naturalHeight != "undefined")
         img_init.height = theImg.naturalHeight;
-
       img_init.rapport = img_init.width / img_init.height;
-
-      if (typeof Zone_image.image == "undefined") Zone_image.image = { height: Zone_image.image_init.height, width: Zone_image.image_init.width }; ;
-
-      Zone_image.image_init.height = img_init.height;
-      Zone_image.image_init.width = img_init.width;
+      if (typeof Zone_image == "undefined") Zone_image = { image: {} };
+      if (typeof Zone_image.image == "undefined") Zone_image.image = { height: Zone_image.image_init.height, width: Zone_image.image_init.width };
+      theImg.width = img_init.height;
+      theImg.width = img_init.width;
+
+      Zone_image.image_init = { height: img_init.height, width: img_init.width, rapport: img_init.rapport };
       Zone_image.zoom = Zone_image.image_init.height / img_init.height;
-      Zone_image.image_init.rapport = img_init.rapport;
-      nu_img = 0;
+
       if (typeof Zone_image.src == "undefined") {
         Zone_image.src = name_src;
         return false;
       }
-      stx = name_src.match(Zone_image.src);
-      sty = infos_theMainImage.src;
+      stx = name_src.match(RegExp(Zone_image.src, "gi"));
       return stx;
     }
@@ -1201,4 +1273,51 @@
     //
     //=====================================
+    Get_Maxi = function (Maxi_image) {
+      var pt = options.liste_type;
+      if (pt.length > 0) {
+        tw = Maxi_image.width;  // valeur maxi
+        th = Maxi_image.height;  // valeur maxi
+        n = 0;
+        maxi_size = { w: Maxi_image.width, h: Maxi_image.height, idx: -1 };
+        mini_size = { w: tw, h: th, idx: 0 };
+        size_derive = { w: 0, h: 0 };
+        size_encours = { w: tw, h: th };
+        //=================================
+        jQuery(pt).each(function (i) {
+          vn = this;
+          size_derive = { w: parseInt(vn[2]), h: parseInt(vn[3]) };
+          if (vn[0] != "square" && vn[0] != "thumb" && vn[0] != "SelMaxi" && vn[0] != "Autosize") {
+            if (size_derive.h > size_encours.h) {
+              if (maxi_size.idx < 0) {
+                maxi_size = size_derive;
+                maxi_size.idx = n;
+                return false
+              }
+            }
+            if (size_derive.h < size_encours.h && size_derive.h > 10) {
+              mini_size = size_derive;
+              mini_size.idx = n;
+            }
+          }
+          n++;
+        });
+        n = maxi_size.idx;
+        if (n < 0) {
+          n = mini_size.idx;
+        }
+        if (options.select_type.match(RegExp("SelMaxi", "gi"))) {
+          n = mini_size.idx;
+
+        }
+        if (options.select_type.match(RegExp("Autosize", "gi"))) {
+
+        }
+        options.src_deriv = pt[n][0];
+        return { url: pt[n][1], pictureDeriv: pt[n][0], pictureMap: pt[n][0], width: pt[n][2], height: pt[n][3] };
+      }
+      return { imgSrc: "", pictureDeriv: "", width: "", height: "" };
+    }
+    //_______________ Get_Maxi ______
+
     Select_Image = function () {
       var pt = options.liste_type;
@@ -1207,56 +1326,31 @@
         //===== calcul Image ===
         Calcul_Image();
-        tw = Zone_image.image.width;  // valeur maxi
-        th = Zone_image.image.height;  // valeur maxi
-        n = 0;
-        maxi_size = { w: tw, h: th, idx: -1 };
-        mini_size = { w: tw, h: th, idx: 0 };
-        size_derive = { w: 0, h: 0 };
-        size_encours = { w: tw, h: th };
-
-        jQuery(pt).each(function (i) {
-          vn = this;
-          size_derive = { w: parseInt(vn[2]), h: parseInt(vn[3]) };
-          if (size_derive.h > size_encours.h) {
-            if (maxi_size.idx < 0) {
-              maxi_size = size_derive;
-              maxi_size.idx = n + 1;
-            }
-          }
-          if (size_derive.h < size_encours.h) {
-            mini_size = size_encours;
-            mini_size.idx = n;
-          }
-
-          n++;
-        });
-
-
-        // n = n - 1 ;
-        n = maxi_size.idx;
-
-        if (n > pt.length - 1) n = pt.length - 1; // format le plus grand
-        if (n < 0) n = pt.length - 1; // format le plus grand
-
-        imgSrc = pt[n][1];
-        last_map = pt[n][0];
-        //     if (Type_Img == "pamoorama") return;
+        IMg = Get_Maxi(Zone_image.image);
+        imgSrc = IMg.url;
+
+        ing_width = IMg.width;
+        ing_height = IMg.height;
+        if (Type_Img == "pamoorama") return;
+        if (options.select_type != "SelMaxi" && options.select_type != "Autosize") return;
         if (typeof Zone_image.src == "undefined") Zone_image.src = " ";
-        status = imgSrc.match(RegExp(Zone_image.src, "gi"));
+        status = imgSrc.match(RegExp(Zone_image.src, "gi")); // status = '' si ==
         status1 = (imgSrc.toString() == Zone_image.src.toString());
 
         if (status1 == true) return;
+        href_path = "javascript:changeImgSrc('" + imgSrc + "', '" + options.select_type + "', '" + options.select_type + "')";
+        jQuery(".linkAutosize").attr("href", href_path);
         theImg = document.getElementById(theMainImage_id.replace("#", ""));
-        href_path = "javascript:changeImgSrc('" + imgSrc + "', '" + last_map + "', '" + "Autosize" + "')";
-        jQuery("#linkAutosize").attr("href", href_path);
+
         if (theImg.tagName != "IMG") {
-          theImg.useMap = "#Autosize";
+          theImg.useMap = "#map" + options.select_type;
           imgSrc_i = jQuery(theImg).css("backgroundImage");
           imgSrc_j = jQuery(theImg).css("background-image");
 
         } else {
-          if (theImg.useMap.match(RegExp("map", "gi"))) return;
-          if (theImg.src.match(RegExp(imgSrc, "gi"))) return;
-          changeImgSrc(imgSrc, last_map, "#Autosize");
+
+          // if (!theImg.useMap.match(RegExp("SelMaxi", "gi"))) return;
+          //  if (!theImg.useMap.match(RegExp("Autosize", "gi"))) return;
+
+          changeImgSrc(imgSrc, options.select_type, options.select_type);
         }
         return true;
@@ -1278,18 +1372,20 @@
 
     };
-
-
     /*************************************************
     * correction pamoorama
     *************************************************/
     Set_Pamoorama = function (Format) {
+      myPamoorama = window.myPamoorama;
       if (Type_Img == "pamoorama") {
-        if (!Format) return;
-
-        myPamoorama = window.myPamoorama;
+
         if (!nopano) {
+          theMainImage_Id = "#pamoorama";
           nopano = false;
           Wait_pamoorama();
-        }
+          infos_theMainImage = jQuery(theMainImage_Id).infos();
+          //theMainImage_Id = "#pamoorama";
+        }
+
+
         if (typeof myPamoorama == "undefined") {
           return;
@@ -1297,14 +1393,21 @@
         //=========================================================  
         if (!nopano) {
+          //theMainImage_Id = "#pamoorama";
           nopano = false;
           Wait_pamoorama();
-        }
-
-        jQuery("#pamoorama").show(1000);
-        jQuery("#loading").hide(1000);
-
-        Wait_pamoorama();
-        window.myPamoorama.stopAnim();
-        infos_theMainImage = jQuery("#pamoorama").infos(true);
+          infos_theMainImage = jQuery(theMainImage_Id).infos();
+          //theMainImage_Id = "#pamoorama";
+        }
+
+
+
+        infos_pamoorama = jQuery("#pamoorama").infos();
+        infos_pamoorama_outter = jQuery("#pamoorama_outter").infos(true);
+        infos_pamoorama_inner = jQuery("#pamoorama_inner").infos();
+
+        infos_pamoorama_frame = jQuery("#pamoorama_frame").infos();
+        infos_frame = jQuery(myPamoorama.frame).infos();
+
+
         //====================================================
         jQuery("#pamoorama").css({
@@ -1313,52 +1416,38 @@
           //  height: Zone_Affichage.height + "px" , sinon déclenchement panorama sur la hauteur;
         });
-        //============================================================
-        infos_pamoorama = jQuery("#pamoorama").infos(true);
-        infos_pamoorama_outter = jQuery("#pamoorama_outter").infos();
-        infos_pamoorama_inner = jQuery("#pamoorama_inner").infos();
-        infos_pamoorama_footer = jQuery("#pamoorama_footer").infos();
-        infos_pamoorama_frame = jQuery("#pamoorama_frame").infos();
-
-        infos_frame = jQuery(myPamoorama.frame).infos();
+
         marges_w = infos_pamoorama.general.marges.width;
         marges_h = infos_pamoorama.general.marges.height;
+
+        jQuery("#pamoorama_footer").css({
+          width: Format.width + "px"
+        });
+        infos_pamoorama_footer = jQuery("#pamoorama_footer").infos();
         marges_h += infos_pamoorama_footer.general.height;
+
         jQuery("#pamoorama").css({
           width: ""
         });
 
-
-        outter_width = Format.width;
-        pos = jQuery("#theImage").offset();
-        pos.top = infos_pamoorama.top;
-        pos.left = infos_pamoorama.left;
-        outter_height = Format.height - marges_h;
-        /*
-        jQuery("#theMainImage").width(outter_width);
-        jQuery("#theMainImage").height(outter_height);
-        jQuery("#theMainImage").css({ left: pos.left, top: pos.top, margin: "auto", border: "solid 1px red"
-
+        outter_height = Format.height;
+
+        Zoom_pano = (Format.height - marges_h) / Zone_image.image_init.height;
+        new_image = { height: Math.ceil(Zone_image.image_init.height * Zoom_pano),
+          width: Math.ceil(Zone_image.image_init.width * Zoom_pano)
+        }
+
+        jQuery("#pamoorama_inner").css({
+          width: new_image.width + "px", height: new_image.height + "px", "background-size": "100%"
         });
 
-        */
-
-        Zoom_pano = outter_height / Format.height;
-        new_image = { height: Math.ceil(Format.height * Zoom_pano),
-          width: Math.ceil(Format * Zoom_pano)
-        }
-
-        jQuery("#pamoorama_inner").css({ width: new_image.width, height: new_image.height, "background-size": "100%"
-        });
-
-        //  jQuery("#pamoorama_inner").width(Zone_image.width_init * Zoom_pano);
-        //  jQuery("#pamoorama_inner").height(Zone_image.height_init * Zoom_pano);
 
 
         //---------- test largeur image 
         new_width = Format.width;
+
         if (new_width > new_image.width) {
           new_width = new_image.width;
           jQuery("#pamoorama_outter").css({
-            position: 'absolute',
+
             align: "center",
             margin: "auto"
@@ -1367,25 +1456,14 @@
         outter_width = new_width;
 
-
-        //  jQuery("#pamoorama_thumb").width(200 /  Zone_image.zoom);
-
         jQuery("#pamoorama_outter").css({
-
           align: 'center',
           margin: 'auto',
           width: outter_width + "px",
-          height: outter_height + "px"
+          height: Format.height - marges_h + "px"
         });
         //============= Mise à l'echelle ==================
-        jQuery("#pamoorama_footer").css({
-          width: Format.width + "px"
-        });
-
         window.myPamoorama.options.width = Math.ceil(Format.width);
         //==================================================================
         new_max_left = new_image.width - outter_width;
-        //   jQuery(window.myPamoorama.inner).width(Zone_image.width_init* Zoom_pano);
-        //    jQuery(window.myPamoorama.inner).height(Zone_image.height_init * Zoom_pano);
-
         if (!window.myPamoorama.outter) return;
         window.myPamoorama.outter.scrollTo(new_max_left, 0);
@@ -1398,4 +1476,8 @@
         jQuery("#pamoorama_thumb img").width(200);
         jQuery("#pamoorama_thumb img").height(nf);
+        jQuery("#pamoorama_thumb").css({
+          position: "absolute",
+          left: (Format.width - 215) + "px"
+        });
         // 200=window.myPamoorama.width 
         // frame = Zone_image.container.width
@@ -1404,17 +1486,14 @@
         jQuery("#pamoorama_frame").width(nw);
         jQuery("#pamoorama").css({
-          width: outter_width, height: "auto"
+          width: outter_width + "px", height: Format.height + "px"
         });
-        //        jQuery("#theImage").trigger("Start_right");
-        jQuery("#theImage").height(Zone_image.container.height + 1);
-
-        jQuery("#theImage").css({
-          height: Zone_image.container.height
-        });
-
-
-        return true
-      } // test img
+
+        //   jQuery("#theImage").css({ margin: "auto" });
+        //   jQuery("#theImage").width(Format.width);
+
+        jQuery("#loading").css("display", "none");
+      } //  
     } // Set_Pamoorama
+
     /*********************************************************/
 
@@ -1502,15 +1581,22 @@
       + Math.ceil(infos_theMainImage.general.marges.height);
       retrait_img.height += 2;
+     
       //===============================================================
       retrait_img.width = Math.ceil(infos_theMainImage.general.marges.width); // borderwidth+padding
       retrait_img.width += Math.ceil(options.marges_llgbo || 0);
       retrait_img.width += 2;
+    
 
       //================== Limite Format Image =====================
       container.height_interne = container.height - marge_top - marge_bottom;
       container.width_interne = container.width - marge_left - marge_right;
+
+      container.height_interne = Math.max(container.height_interne, Math.ceil(options.mini_height) + retrait_img.height),
+      container.width_interne = Math.max(container.width_interne, Math.ceil(options.mini_width) + retrait_img.width)
+
+
       image_max = {
-        height: container.height_interne - retrait_img.height,
-        width: container.width_interne - retrait_img.width
+        height: (container.height_interne - retrait_img.height),
+        width: (container.width_interne - retrait_img.width)
       }
       //=========================
@@ -1521,8 +1607,12 @@
 
       if (Type_Img == "pamoorama") {
-
+        if (height_theMainImage > container.height_interne) {
+
+        }
       } else {
 
         height_theMainImage = Math.ceil(width_theMainImage / Zone_image.image_init.rapport);
+
+
 
         if (height_theMainImage > container.height_interne) {
@@ -1544,9 +1634,13 @@
         }
 
+
+
+
       }
       //================================================================
       Zone_image.image = {
         width: width_theMainImage,
-        height: height_theMainImage
+        height: height_theMainImage,
+        rapport: width_theMainImage / height_theMainImage
       };
 
@@ -1569,20 +1663,9 @@
         Zone_image.src = infos_theMainImage.src;
       }
-
-
-      if (typeof Zone_image.image_init.rapport == "undefined") return;
-      if (force && force == true) old_window.width = 0;
-
-
-      if (infos_theMainImage.useMap.match(RegExp("Autosize", "gi")))
-        infos_theMainImage.useMap = "#Autosize";
-
-      useMap = options.useMap;
-
-
-      if (typeof useMap == "") useMap = "Autosize";
-      if (options.useMap) {
-        //  useMap = options.useMap;
-      }
+      if (typeof Zone_image.image_init.rapport == "undefined") {
+        Zone_image.image_init.rapport = Zone_image.image_init.width / Zone_image.image_init.height;
+      }
+      useMap = options.select_type;
+
       if (useMap) {
         if (!useMap.match(RegExp("Autosize", "gi"))) {
@@ -1601,10 +1684,4 @@
       var chk = eval("options." + user_status + "_enabled");
       if (chk == "") { return; }
-
-      if (!options.useMap.match(RegExp("Autosize", "gi"))) {
-
-        return;
-      }
-
       Calcul_Image();
       jQuery("#loading").hide();
@@ -1681,7 +1758,7 @@
 
         case "pamoorama":
-
+          Wait_pamoorama();
           /*
-        
+          
           infos_the_page = jQuery("#the_page").infos();
           */
@@ -1692,9 +1769,4 @@
 
 
-      //================= Vérification Taille image minimun autorisée ========
-      if ((Zone_image.image.height < options.mini_height) || (Zone_image.image.width < options.mini_width)) {
-        Zone_image.image.width = Math.ceil(Zone_image.width_init);
-        Zone_image.image.height = Math.ceil(Zone_image.image.width / Zone_image.image_init.rapport);
-      }
 
       //=================================================
@@ -1712,12 +1784,9 @@
       if (Type_Img != "pamoorama") {
         echelle_max = parseFloat(options.echelle_max, '3');
-        if (Zone_image.zoom > 1) {
-          Select_Image(); //+calcul
-        }
         if (Zone_image.zoom > echelle_max) {
           Zone_image.zoom = echelle_max;
-          Zone_image.image.width = parseInt(Zone_image.width_init * Zone_image.zoom);
+          Zone_image.image.width = parseInt(Zone_image.image_init.width * Zone_image.zoom);
           if (Zone_image.image_init.rapport > 0)
-            Zone_image.image.height = parseInt(Zone_image.width_init / Zone_image.image_init.rapport);
+            Zone_image.image.height = parseInt(Zone_image.image_init.width / Zone_image.image_init.rapport);
         }
       }
@@ -1779,30 +1848,83 @@
       options.marge_top += infos_theImage.general.marges.top + infos_content.general.marges.top + Math.ceil(options.marge_haute);
       options.marge_bottom = Math.ceil(options.marge_basse); // +infos_content.general.marges.bottom; ;
-
+      if (cookies.pictureDeriv == null)
+        options.first = true;
+      else
+        options.first = false;
       //=================== Gestion liste photos size ============================
       us = 0;
-      type_size = cookies.typeSave; // xxx
-      useMap = cookies.pictureMap; // #mapxxx
-
+      if (options.first) {
+        IMg = Get_Maxi(Zone_image.image);
+        options.src_deriv = IMg.pictureDeriv;
+        imgSrc = IMg.url;
+        width = IMg.width;
+        height = IMg.height;
+      }
       user_status = options.user_status;
-      type_size_maxi = eval("options." + user_status + "_type"); //limite taille
-      type_size = type_size || type_size_maxi;
+      pictureDeriv_maxi = eval("options." + user_status + "_type"); //limite taille
+      options.pictureDeriv_maxi = pictureDeriv_maxi;
+      pictureDeriv_maxi = options.select_type;
+
+      //==========================================================
+      href_path = "javascript:changeImgSrc('" + options.src_img + "', '" + "SelMaxi" + "', '" + "SelMaxi" + "')";
+      spans = jQuery("#derivativeCheckedSelMaxi").next();
+      spans.attr("href", href_path);
+      spans.attr("name", "SelMaxi");
+      spans = spans.find("span");
+      spans.attr("name", "SelMaxi");
+      spans.text("(" + cookies.theMainImageWidth + " x " + cookies.theMainImageHeight + ")");
+      //==========================================================
+      href_path = "javascript:changeImgSrc('" + options.src_img + "', '" + "Autosize" + "', '" + "Autosize" + "')";
+
+      spans = jQuery("#derivativeCheckedAutosize").next();
+      spans.attr("href", href_path);
+      spans.attr("name", "Autosize");
+      spans = spans.find("span");
+      spans.attr("name", "Autosize");
+      spans.text("(" + cookies.theMainImageWidth + " x " + cookies.theMainImageHeight + ")");
+      //==========================================================
+
+      Zone_image.image.width = cookies.theMainImageWidth;
+      Zone_image.image.height = cookies.theMainImageHeight;
+
+      if (options.select_type == "Autosize" || options.select_type == "SelMaxi") {
+        spans = jQuery("#derivativeChecked" + options.select_type).next();
+        spans.addClass("linkAutosize");
+        spans.find("span").addClass("auto_details");
+      }
+      pictureDeriv = pictureDeriv || pictureDeriv_maxi;
+
+      IMg = Get_Maxi(Zone_image.image);
+      imgSrc = IMg.url;
+
+      width = IMg.width;
+      height = IMg.height;
+
       n = 0;
-
       var pt = new Array();
-      jQuery("#derivativeSwitchBox .switchCheck").css('visibility', 'hidden');
+
+
+      //uyu = jQuery(uyu + " span");
+      //
+
+      // auto_details
+      //==== limite affichage selection = select_type ====
       jQuery("#derivativeSwitchBox a").css('visibility', 'hidden');
-
       jQuery("#derivativeSwitchBox a").each(function (i) {
         href_path = jQuery(this).attr("href");
         pt[i] = href_path.split("'");
         tsz = pt[i][5];
+
         jQuery(this).css('visibility', 'visible');
         //--- recherche limite ---
-        if (tsz.match(RegExp(type_size_maxi, "gi"))) {
-          return false;
+        if (tsz.match(RegExp(pictureDeriv_maxi, "gi"))) {
+          if (tsz.match(RegExp(options.select_type, "gi"))) {
+            us = n;
+          } else {
+            return false;
+          }
         }
         //--- type en cours ---
-        if (tsz.match(RegExp("^" + type_size, "gi"))) {
+        if (tsz.match(RegExp("^" + pictureDeriv, "gi"))) {
           us = n;
         }
@@ -1810,80 +1932,27 @@
         n++;
       });
-
-      jQuery("derivativeChecked" + options.type_size).css('visibility', 'visible');
+      jQuery(".switchCheck").css('visibility', 'hidden');
+      jQuery("derivativeChecked" + pictureDeriv_maxi).css('visibility', 'visible');
+      /*  */
       //==== en cours ============
-      n = pt.length - 1;
-      if (n >= 0) {
-        imgSrc = pt[n][1];
-        last_map = pt[n][5];  // dernière position
-        //=======================================
-        imgSrc = pt[us][1];
-        last_map = pt[us][5]; // taille selectionné.
-        href_path = "javascript:changeImgSrc('" + imgSrc + "', '" + last_map + "', '" + "Autosize" + "')";
-        new_html = '<br /><span class="switchCheck" id="derivativeCheckedAutosize" style="visibility:visible" >&#x2714; </span>';
-        new_html += '<a id="linkAutosize" href="' + href_path + '">';
-        new_html += 'Autosize<span class="derivativeSizeDetails" id="auto_details" > - Autosize</span>  </a>';
-        if (!type_size.match(RegExp("Autosize", "gi"))) {
-          jQuery("#derivativeSwitchBox br:last").before(new_html);
-        }
-
-        useMap = "#" + type_size_maxi; // #mapxxx
-        if (useMap == "#Autosize" && type_size_maxi == "Autosize") {
-
-        } else {
-          useMap = last_map;
-        }
-
-        typeSave = cookies.typeSave; //picturederiv xxx
-        options.type_size = useMap.replace("#", "");
-
-        type_size = options.type_size;
-        cookies.pictureMap = "#" + type_size_maxi; // #mapxxx
-        cookies.typeSave = type_size_maxi; //picturederiv xxx
-        cookies.imgSrc = imgSrc;
-        changeImgSrc(imgSrc, last_map, type_size);
-      } else {
-        type_size_maxi = cookies.pictureMap; // #mapxxx
-        type_size_maxi = cookies.typeSave; //picturederiv xxx
-        imgSrc = cookies.imgSrc;
-        last_map = type_size_maxi;
-        href_path = "";
-      }
+      cookies.pictureMap = pictureDeriv_maxi; // #mapxxx
+      cookies.pictureDeriv = pictureDeriv_maxi; //picturederiv xxx
+      cookies.imgSrc = imgSrc;
+
+      changeImgSrc(imgSrc, cookies.pictureDeriv, cookies.pictureMap);
+      imgSrc = cookies.imgSrc;
+      pictureDeriv = pictureDeriv_maxi;
+      href_path = "";
+
     };
     //_______________________ init_gen _______________________
 
-    //============= Gestion Maps ================
-    nom_map = "Autosize";
-    a_up = jQuery("map[name='" + nom_map + "'] area[rel=up]");
-    a_prev = jQuery("map[name='" + nom_map + "'] area[rel=prev]");
-    a_next = jQuery("map[name='" + nom_map + "'] area[rel=next]");
-    new_html = '<map name="' + nom_map + '" >';
-    nb_zone = jQuery("div .navigationButtons a").length;
-    Largeur_zone = (jQuery("#theMainImage").width() / nb_zone);
-    Hauteur_zone = jQuery("#theMainImage").height();
-    init_zone = 0;
-    j = 0;
-    jQuery("div .navigationButtons a").each(function (e) {
-      Hauteur_zone = jQuery("#theMainImage").height();
-      title = jQuery(this).attr("title");
-      h_ref = jQuery(this).attr("href");
-      init_zone = Largeur_zone * j;
-      if (title.match(":")) {
-        if (j == 0)
-          rel = "prev";
-        else
-          rel = "next";
-      } else {
-        rel = "up";
-        Hauteur_zone = Hauteur_zone / 4;
-      }
-      coord = init_zone + "," + 0 + "," + Math.ceil(init_zone + Largeur_zone) + "," + Hauteur_zone;
-      new_html += '<area rel="' + rel + '" title="' + title + '" href="' + h_ref + '" shape="rect" coords="' + coord + '" alt="' + title + '" />';
-
-      j++;
-    });
-    new_html += '</map>';
-    jQuery("#theImage map:last").after(new_html);
-    
-  });                                                                                                                          // ready
-
+    if (typeof changeImgSrc != "function") {
+
+    }
+  });                                                                                                                                                                                                                                       // ready
+
+
+  jQuery("#derivativeSwitchBox a").click(function (e) {
+    k1 = 0;
+  });
Index: /extensions/Autosize/js/JScript.js
===================================================================
--- /extensions/Autosize/js/JScript.js	(revision 17502)
+++ /extensions/Autosize/js/JScript.js	(revision 17503)
@@ -18,6 +18,5 @@
   }
   return yWithScroll - innerh;
-}
-
+}                   
 jQuery(document).ready(function (jQuery) {
   jQuery(window).load(function () {
Index: /extensions/Autosize/js/autosize.cookie.js
===================================================================
--- /extensions/Autosize/js/autosize.cookie.js	(revision 17502)
+++ /extensions/Autosize/js/autosize.cookie.js	(revision 17503)
@@ -1,57 +1,2 @@
-/**
- * Cookie plugin
- *
- * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
- * Dual licensed under the MIT and GPL licenses:
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.gnu.org/licenses/gpl.html
- *
- */
-
-/**
- * Create a cookie with the given name and value and other optional parameters.
- *
- * @example $.cookie('the_cookie', 'the_value');
- * @desc Set the value of a cookie.
- * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
- * @desc Create a cookie with all available options.
- * @example $.cookie('the_cookie', 'the_value');
- * @desc Create a session cookie.
- * @example $.cookie('the_cookie', null);
- * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
- *       used when the cookie was set.
- *
- * @param String name The name of the cookie.
- * @param String value The value of the cookie.
- * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
- * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
- *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
- *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
- *                             when the the browser exits.
- * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
- * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
- * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
- *                        require a secure protocol (like HTTPS).
- * @type undefined
- *
- * @name $.cookie
- * @cat Plugins/Cookie
- * @author Klaus Hartl/klaus.hartl@stilbuero.de
- */
-
-/**
- * Get the value of a cookie with the given name.
- *
- * @example $.cookie('the_cookie');
- * @desc Get the value of a cookie.
- *
- * @param String name The name of the cookie.
- * @return The value of the cookie.
- * @type String
- *
- * @name $.cookie
- * @cat Plugins/Cookie
- * @author Klaus Hartl/klaus.hartl@stilbuero.de
- */
 jQuery.cookie = function(name, value, options) {
     if (typeof value != 'undefined') { // name and value given, set cookie
Index: /extensions/Autosize/js/autosize.dimensions.js
===================================================================
--- /extensions/Autosize/js/autosize.dimensions.js	(revision 17502)
+++ /extensions/Autosize/js/autosize.dimensions.js	(revision 17503)
@@ -194,10 +194,33 @@
 
           myposition = "";
-          width = jQuery(elem).width();
-          height = jQuery(elem).height();
-          out_width = width;
-          out_height = height;
-          in_width = width; ;
-          in_height = height;
+          var myWidth = 0, myHeight = 0;
+
+          var xHeight = jQuery(document).height();
+          var x2Height = jQuery(window).height();
+
+          if (typeof (window.innerWidth) == 'number') {
+            //Non-IE
+            myWidth = window.innerWidth;
+            myHeight = window.innerHeight;
+          } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
+            //IE 6+ in 'standards compliant mode'
+            myWidth = document.documentElement.clientWidth;
+            myHeight = document.documentElement.clientHeight;
+          } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
+            //IE 4 compatible
+            myWidth = document.body.clientWidth;
+            myHeight = document.body.clientHeight;
+          }
+
+          if (myHeight != x2Height) {
+            width = myWidth;
+          }
+
+          width = myWidth;
+          height = myHeight;
+          out_width = myWidth;
+          out_height = myHeight;
+          in_width = myWidth; ;
+          in_height = myHeight;
 
         } else {
Index: /extensions/Autosize/js/autosizeDetect.js
===================================================================
--- /extensions/Autosize/js/autosizeDetect.js	(revision 17503)
+++ /extensions/Autosize/js/autosizeDetect.js	(revision 17503)
@@ -0,0 +1,34 @@
+
+function on_load() {
+  var myWidth = 0, myHeight = 0, myImgWidth =0,  myImgHeight = 0;
+  if (typeof (window.innerWidth) == 'number') {
+    //Non-IE
+    myWidth = window.innerWidth;
+    myHeight = window.innerHeight;
+  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
+    //IE 6+ in 'standards compliant mode'
+    myWidth = document.documentElement.clientWidth;
+    myHeight = document.documentElement.clientHeight;
+  } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
+    //IE 4 compatible
+    myWidth = document.body.clientWidth;
+    myHeight = document.body.clientHeight;
+  }
+
+  href = document.location.href.toString();
+
+  myWidth =parseInt( myWidth);
+  myHeight = parseInt(myHeight);
+
+  myImgWidth = (myWidth - 10);
+  myImgHeight = (myHeight - 100);
+
+  jQuery.cookie('theImageWidth', myWidth, { path: "/" });
+  jQuery.cookie('theImageHeight', myHeight, { path: "/" });
+  jQuery.cookie('autosize_reload', "ok", { path: "/" });
+
+  document.location.reload(false);
+
+ // document.location.reload(false); // from cache
+
+}
Index: /extensions/Autosize/main.inc.php
===================================================================
--- /extensions/Autosize/main.inc.php	(revision 17502)
+++ /extensions/Autosize/main.inc.php	(revision 17503)
@@ -2,5 +2,5 @@
 /*
 Plugin Name: AutoSize
-Version: 2.05
+Version: 2.06
 Description: Ajuste l'affichage des photos en fonction de la hauteur de la fenetre de navigation
 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=448
@@ -34,12 +34,22 @@
 add_event_handler('get_admin_plugin_menu_links', array(&$autosize_controler,'cl_autosize_admin')  );
 
- add_event_handler('loc_after_page_header', array(&$autosize_controler, 'cl_autosize_script_1'),  EVENT_HANDLER_PRIORITY_NEUTRAL   );	
 
-add_event_handler('loc_after_page_header', array(&$autosize_controler, 'cl_autosize_affiche'), EVENT_HANDLER_PRIORITY_NEUTRAL+21  );
-
-add_event_handler('loc_end_page_tail',array(&$autosize_controler, 'cl_autosize_script_3'),  EVENT_HANDLER_PRIORITY_NEUTRAL-1);
+// init cl_autosize_script_1 cl_autosize_affiche 
 
 
-add_event_handler('render_element_content', array(&$autosize_controler, 'autosize_calcContent'),40,2);
+add_event_handler('render_element_content',  array(&$autosize_controler,'init'),EVENT_HANDLER_PRIORITY_NEUTRAL,2  );
+
+//avant pamooramics
+add_event_handler('render_element_content', array(&$autosize_controler, 'autosize_calcContent'),40,2); 
+
+add_event_handler('loc_after_page_header', array(&$autosize_controler, 'cl_autosize_script_2'),  EVENT_HANDLER_PRIORITY_NEUTRAL   );
+
+add_event_handler('loc_after_page_header', array(&$autosize_controler, 'cl_autosize_script_1'),  EVENT_HANDLER_PRIORITY_NEUTRAL   );
+
+add_event_handler('loc_after_page_header',array(&$autosize_controler, 'cl_autosize_script_3'),  EVENT_HANDLER_PRIORITY_NEUTRAL  );
+
+add_event_handler('loc_after_page_header', array(&$autosize_controler, 'cl_autosize_affiche'), EVENT_HANDLER_PRIORITY_NEUTRAL +21    );
+
+
 
 ?>
Index: /extensions/Autosize/maintain.inc.php
===================================================================
--- /extensions/Autosize/maintain.inc.php	(revision 17502)
+++ /extensions/Autosize/maintain.inc.php	(revision 17503)
@@ -30,8 +30,5 @@
 {
  global $conf;
-
-  if (!isset($conf['cl_autosize']))
-  {
-    
+  if (!isset($conf['cl_autosize'])){    
   $q = '
     INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
@@ -46,6 +43,5 @@
 
 
-function plugin_uninstall()
-{
+function plugin_uninstall(){
   global $conf;
   if (isset($conf['cl_autosize']))
@@ -61,3 +57,57 @@
  }
 
+ function plugin_deactivate(){
+ global $conf ;
+ if (isset($conf['cl_derivatives_sav']))  {    
+    $arr = @unserialize($conf['cl_derivatives_sav']);         
+      if(isset($arr['d'])){ 
+        $query = '
+    		UPDATE '.CONFIG_TABLE.'
+    		  SET value="'.addslashes(serialize($arr)).'"
+    		WHERE param = "derivatives"
+    		LIMIT 1';
+ 			  pwg_query($query);
+
+        $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param="cl_derivatives_sav"   ;';
+     pwg_query($q);
+       }
+    }     
+ }
+
+function plugin_activate(){
+ global $conf ;
+ if (isset($conf['derivatives']))  {    
+    $arr = @unserialize($conf['derivatives']);  
+     if(isset($arr['d'])){ 
+       if (!isset($conf['cl_derivatives_sav'])){   
+            $q = 'INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
+            VALUES ("cl_derivatives_sav","","derivatives save")
+            ;';
+            pwg_query($q);
+       
+            $query = '
+            UPDATE '.CONFIG_TABLE.'
+              SET value="'.addslashes(serialize($arr)).'"
+            WHERE param = "cl_derivatives_sav"
+            LIMIT 1';
+            pwg_query($query);       
+ 
+            $arr = @unserialize($conf['derivatives']);
+            if(!isset($arr['d']['Autosize'])){    
+                  $arr['d']['SelMaxi']=ImageStdParams::get_custom(9,9); 
+                  $arr['d']['Autosize']=ImageStdParams::get_custom(10, 10);  
+                  $conf['derivatives']=serialize($arr);
+                  $arr = @unserialize($conf['derivatives']);       
+                  $query = '
+                      UPDATE '.CONFIG_TABLE.'
+                      SET value="'.addslashes(serialize($arr)).'"
+                      WHERE param = "derivatives"
+                      LIMIT 1';
+                  pwg_query($query);              
+            }   
+        }
+     }
+   }      
+ }
+
 ?>
Index: /extensions/Autosize/template/autosize.tpl
===================================================================
--- /extensions/Autosize/template/autosize.tpl	(revision 17502)
+++ /extensions/Autosize/template/autosize.tpl	(revision 17503)
@@ -2,12 +2,9 @@
 {html_head} <!-- autosize/template/autosize.tpl  -->
  <script type="text/javascript">
- 
 var  Autosize_options={ldelim}
-    
-    cookies :{$cookies} ,
-    deriv_type :'{$deriv_type}' ,
-    liste_type:'{$liste_type}'   ,
-
-    type_size:'{$deriv_type}' ,
+        select_type:'{$select_type}',
+        maxi_img:'{$maxi_img}',       
+        pictureDeriv :'{$pictureDeriv}' ,
+        liste_type:new Array()   , 
       DEBUG_autosize:'{$DEBUG_autosize}',
      theme:'{$theme}',
@@ -23,6 +20,6 @@
      img_height : '{ $IMG_HEIGHT }',
 
-     cookie_width:'{$COOKIE_WIDTH }',
-     cookie_height : '{ $COOKIE_HEIGHT }',
+     windowWidth:'{$windowWidth }',            
+     windowHeight : '{ $windowHeight}',
 
      marge_basse:'{ $MARGE_BASSE }',
@@ -50,6 +47,22 @@
      user_status:'{$user_status}',   
      check_auto_w : '{$check_auto_w}',     
-     check_desc_v :  '{$check_desc_v}' 
+     check_desc_v :  '{$check_desc_v}' ,
+     Size : new Array() 
     } ;
+      
+       
+     {if not empty($liste_type)}   
+            {foreach from=$liste_type item=cl_size key=value}           
+         Autosize_options.liste_type.push('{$cl_size}'  )       
+        {/foreach}
+     {/if}
+    
+
+     {if not empty($Size )}   
+            {foreach from=$Size item=cl_size key=value}
+         Autosize_options.Size.push( {ldelim}'{$value}':{$cl_size}}  )       
+        {/foreach}
+     {/if}
+    
 
  </script>
Index: /extensions/Autosize/template/header.tpl
===================================================================
--- /extensions/Autosize/template/header.tpl	(revision 17502)
+++ /extensions/Autosize/template/header.tpl	(revision 17503)
@@ -1,2 +1,3 @@
+
 {if not empty($pamoorama)}
 {combine_script id="conflit_script"  load="header" path = $AUTOSIZE_PATH|@cat:"js/conflit.js" require="jquery" }
@@ -4,6 +5,6 @@
 {combine_script id="autosize.dimensions" path = $AUTOSIZE_PATH|@cat:"js/autosize.dimensions.js" require="jquery"}
 {combine_script id="conflit_script1" load="footer" path = $AUTOSIZE_PATH|@cat:"js/conflit_2.js" require="jquery" }
+{else}
 
-{else}
 {/if}
 
Index: /extensions/Autosize/template/picture_1.tpl
===================================================================
--- /extensions/Autosize/template/picture_1.tpl	(revision 17502)
+++ /extensions/Autosize/template/picture_1.tpl	(revision 17503)
@@ -1,3 +1,7 @@
+
+{if $select_type=="Autosize" || $select_type=="Selmaxi" }{/if} 
 {combine_script id="Affiche_script" path= $AUTOSIZE_PATH|@cat:"js/Affiche_script.js" require='jquery,autosize.dimensions'  }
+
+
 {if $theme != "elegant"}
 {combine_script id="autosize.cookie" path = $AUTOSIZE_PATH|@cat:"js/autosize.cookie.js" require="jquery"  }{/if} 
