Index: extensions/Autosize/js/Affiche_script.js
===================================================================
--- extensions/Autosize/js/Affiche_script.js	(revision 22248)
+++ extensions/Autosize/js/Affiche_script.js	(revision 22292)
@@ -86,5 +86,5 @@
     **************************************************************************/
     Get_type_img = function (e) {
-      // ====== détection du type d'images ======
+      // ====== détection du type d'images ======   
       if (jQuery("#charlie").length > 0) {
         Type_Img = "charlie";
@@ -104,18 +104,28 @@
 
         if (jQuery("#theImage" + " object").length > 0) {
-
           type_src = "object";
-
         } else if (jQuery("#theImage" + " embed").length > 0) {
-
           type_src = "embed";
-
         } else {
-
           type_src = "iframe";
         }
-        nbf = jQuery("#theImage" + " " + type_src).length;
-        frm1 = jQuery("#theImage" + " " + type_src).get(0);
-        Type_Img = "iframe";
+        iframes = jQuery("#theImage" + " " + type_src);
+        var st_frame = true;
+        nbf = iframes.length;
+        jQuery("#theImage" + " " + type_src).each(function (i) {
+          if (this.src.match(RegExp("http", "gi")) || this.src.match(RegExp("javascript", "gi"))) {
+
+          } else {
+            st_frame = false;
+            frm1 = this;
+          }
+        });
+        if (!st_frame) {
+          Type_Img = type_src;
+        } else {
+          Type_Img = "img";
+          type_src = "div";
+          return;
+        }
         // 'fb - xfbml - like - button
         objs = jQuery("#theImage" + " div").get(0);
@@ -126,5 +136,5 @@
           } else {
             if (nbf > 1) {
-              jQuery(frm1).attr("id", "charlie");
+              frm1.attr("id", "charlie");
             } else {
               // Type_Img = "img";
@@ -332,19 +342,11 @@
           theMainImage_id = "charlie";
           options.valide = true;
-
-
         } else if (Type_Img == "iframe") {
-
           infos_theMainImage = jQuery("#iframe").infos(true);
-
           options.valide = true;
-
           infos_theMainImage.width = infos_theImage.general.width;
           infos_theMainImage.height = infos_window.height - infos_theImage.top - options.marge_basse;
           jQuery("#iframe").width(infos_theMainImage.width);
           jQuery("#iframe").height(infos_theMainImage.height);
-
-
-
         } else {
           jQuery("img").each(function (i) {
@@ -465,4 +467,5 @@
     **************************************************************************/
     jQuery(window).unload(function () {
+   
       // return;
     });
@@ -509,5 +512,4 @@
     OptionsCookie = jQuery.extend({}, { path: options.COOKIE_PATH, expires: 1 });
     var cookies = Get_cookies();
-
     fade_in = options.fade_in || 0;
     imageComment_id = ".imageComment";
@@ -518,5 +520,5 @@
       jQuery("#content").css({ marginLeft: 'auto' }); // monblanc
     }
-    Get_type_img();
+
     var theMainImage_id = "#theMainImage";
     var theImage_id = "#theImage";
@@ -573,5 +575,17 @@
     }
     options.liste_type = new_liste;
-
+    XImg = jQuery(theMainImage_id);
+    if (XImg.length > 0)
+      if (jQuery(theMainImage_id)
+         .html()
+         .match(RegExp("charlie_", "gi"))
+         ) {
+        Xdiv = jQuery(theMainImage_id + " div");
+        Xid = jQuery(Xdiv).attr("id");
+        if (typeof Xid == "undefined") {
+          jQuery(Xdiv).attr("id", "charlie");
+        }
+      }
+    Get_type_img();
     // auto_details
     // ==== limite affichage selection = select_type ====
@@ -864,5 +878,5 @@
         theImg.useMap = useMap;
       }
-      fade_in = parseInt(options.fade_in || 0);
+
 
     };
@@ -873,4 +887,5 @@
     **************************************************************************/
     Autosize_resize = function (force, parametres) {
+
       if (!force) {
         cookis = Get_cookies();
@@ -933,5 +948,4 @@
           }
 
-        // jQuery(theMainImage_id).height(Zone_image.image.height);
       } else if (Type_Img == "panorama") {
         // jQuery("#pamoorama").width(img_finale.width);
@@ -946,18 +960,12 @@
             jQuery(theMainImage_id).height(Zone_image.image.height);
             r1 = infos_theImage.width / infos_theImage.height;
-            // jQuery(theMainImage_id).width(Zone_image.image.width/r1);
             jQuery(theMainImage_id).css("margin-top", options.marge_haute);
-
-
           } else {
             jQuery(theMainImage_id).width(Zone_image.image_init.width);
             jQuery(theMainImage_id).height(Zone_image.image_init.height);
           }
-
-
         if (Type_Img == "charlie" || Type_Img == "iframe") {
           init_w1 = Zone_image.image.width;
           init_h1 = Zone_image.image.height;
-
           if (pictureSelType_user != "Autosize" && pictureSelType_user != "SelMaxi") {
             init_w1 = Autosize_options.ideal_size_width;
@@ -981,4 +989,8 @@
               h01 = Math.ceil(w01 / Zone_image.image.rapport);
             // ==== Zone Affichage =====
+            if (h01 > png_h) {
+              h01 = png_h;
+              w01 = Math.ceil(h01 * Zone_image.image.rapport);
+            }
             jQuery("#theMainImage").height(png_h);
             jQuery("#theMainImage").width(w01 + wpng);
@@ -1008,5 +1020,5 @@
             jQuery("#" + Type_Img).attr("height", init_h1 - (infos_theMainImage.borderwidth.top + infos_theMainImage.borderwidth.bottom));
           }
-          jQuery("#" + Type_Img).show(options.fade_in);
+          jQuery("#" + Type_Img).show(fade_in);
         }
 
@@ -1024,14 +1036,8 @@
     * 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');
       Autosize_resize(true, options);
+      jQuery("#pamoorama").fadeTo(fade_in + 20, 1);
     });
 
@@ -1072,6 +1078,4 @@
       tempo = 0;
       Wait_pamoorama_st = false;
-
-
       while (Wait_pamoorama_st == false) {
         Wait_pamoorama_st = Wait_pamoorama_time();
@@ -1084,9 +1088,5 @@
           jQuery.delay(100);
         }
-
-
-
-      }
-
+      }
     };
     // __________________ Wait_pamoorama ______________________
@@ -1101,5 +1101,4 @@
       if (jQuery("#pamoorama").length) {
         tempo = tempo + 1;
-
         mypanorama = window.myPamoorama;
         if (!mypanorama) {
@@ -1107,15 +1106,18 @@
           setTimeout("Wait_pamoorama_time()", 500);
           return false;
-
-        }
-
-        if (mypanorama.skipInit == false) {
+        }
+       /* if (mypanorama.skipInit == false) {
           if (tempo > 500) return true;
-          setTimeout("Wait_pamoorama_time()", 500);
+          setTimeout(function () {
+            Wait_pamoorama_time();
+          }, 500);
           return false;
-        }
+        }*/
+       
         // =============================================================
-        if (Math.abs(mypanorama.imageHeight) < 100) {
-          setTimeout("Wait_pamoorama_time()", 500);
+        if(typeof mypanorama.imageHeight=="undefined"){
+          setTimeout(function () {
+            Wait_pamoorama_time();
+          }, 500);
           return false;
         }
@@ -1153,12 +1155,4 @@
 
     Wait_Affichage_time = function () {
-      if (typeof fade_in == "undefined") fade_in = 1000;
-      fade_in = parseInt(fade_in);
-      /*
-      * if (!Autosize_resize()) { setTimeout("Wait_Affichage()", 500); return }
-      * nu_img++;
-      */
-      if (typeof fade_in == "undefined") fade_in = 0;
-
       // if (nu_img > 1) return;
       if (typeof stb != "undefined")
@@ -1394,18 +1388,6 @@
           return true;
         } else {
-          last_id = IMg.pictureDeriv;
-          // eval(href_path);
-          data_src = jQuery(theImg).attr("data-src");
-          if (typeof data_src != "undefined") {
-            changeImgSrc(data_src + "&loadajax=true",
-           last_id,
-           IMg.pictureMap,
-           options.COOKIE_PATH);
-          } else {
-            changeImgSrc(imgSrc.replace("./", ""),
-           last_id,
-           IMg.pictureMap,
-           options.COOKIE_PATH);
-          }
+          eval(href_path);
+
         }
         theImg.useMap = "#map" + IMg.pictureMap;
@@ -1450,5 +1432,4 @@
       myPamoorama = window.myPamoorama;
       if (Type_Img == "pamoorama") {
-
         if (!nopano) {
           theMainImage_Id = "#pamoorama";
@@ -1456,8 +1437,5 @@
           Wait_pamoorama();
           infos_theMainImage = jQuery(theMainImage_Id).infos();
-          // theMainImage_Id = "#pamoorama";
-        }
-
-
+        }
         if (typeof myPamoorama == "undefined") {
           return;
@@ -1465,9 +1443,7 @@
         // =========================================================
         if (!nopano) {
-          // theMainImage_Id = "#pamoorama";
           nopano = false;
           Wait_pamoorama();
           infos_theMainImage = jQuery(theMainImage_Id).infos();
-          // theMainImage_Id = "#pamoorama";
         }
 
@@ -1499,5 +1475,5 @@
         });
         // ---------- test largeur image
-        new_width = Format.width - (options.marge_right + options.marge_left);
+        new_width = Format.width; // -(options.marge_right + options.marge_left);
 
         if (new_width > new_image.width) {
@@ -1529,5 +1505,5 @@
         window.myPamoorama.imageHeight = new_image.height;
         nf = jQuery("#pamoorama_thumb").height();
-        jQuery("#pamoorama_thumb img").width(180);
+        jQuery("#pamoorama_thumb img").width(200);
         jQuery("#pamoorama_thumb img").height(nf);
 
@@ -1587,9 +1563,13 @@
       if (Type_Img == "img") {
         Zone_image.src = jQuery(theMainImage_id).attr("src");
-        if (Zone_image.src.match(RegExp(Zone_image.name, "gi"))) {
-          Zone_image.path = infos_theMainImage.src;
-        } else
-          return "Wait";
-
+        if (typeof Zone_image.src != "undefined") {
+          if (Zone_image.src.match(RegExp(Zone_image.name, "gi"))) {
+            Zone_image.path = infos_theMainImage.src;
+          } else
+            return "Wait";
+        } else {
+          Zone_image.src = "";
+          Zone_image.path = "";
+        }
       } else {
         Zone_image.src = jQuery(theMainImage_id).attr("src");
@@ -1677,5 +1657,4 @@
       if (!options.check_desc_v)
         options.marge_bottom_2 = 0;
-
 
       marge_bottom = options.marge_bottom_2 + options.marge_bottom;
@@ -1757,8 +1736,6 @@
       options.theImageRight = (new_win.width - new_dim.right);
       options.marge_bottom_2 = Math.ceil(new_dim.out.bottom - new_img.out.bottom);
-
-      if (Type_Img == "iframe") { }
+      options.marge_top_2 = options.marge_top_2 | 0;
       new_dim.out.bottom = new_win.height - options.marge_bottom_2;
-
       options.theImageBottom = new_win.height - new_dim.out.bottom;
       if (options.slideshow) {
@@ -1818,4 +1795,6 @@
         case "charlie":
           Zone_image.zoom = 1;
+          Zone_image.image.width = options.theImageWidth;
+          Zone_image.image.height = options.theImageHeight;
           break;
         case "iframe":
@@ -1900,8 +1879,6 @@
       pos_top = pAll.Top; ;
       pos_bottom = pAll.Bottom; ;
-
       if (infos_llgbo.top > 0) {
         pos_top = infos_llgbo.top;
-
         options.marge_top = infos_theMainImage.top - infos_theImage.top;
         options.marge_bottom = Math.ceil(options.marge_basse + options.marge_top);
@@ -1913,4 +1890,9 @@
 
       options.pos_top = pos_top;
+      new_img = jQuery(theMainImage_id).infos({ absolute: true });
+      new_dim = jQuery(theImage_id).infos({ absolute: true });
+      options.marge_top += Math.ceil(new_img.top - new_dim.top);
+
+
       options.marge_left = infos_theImage.general.marges.left + Math.ceil(options.marge_gauche);
       options.marge_right = infos_theImage.general.marges.right + Math.ceil(options.marge_droite);
@@ -1919,4 +1901,5 @@
                            Math.ceil(options.marge_haute);
 
+
       if (options.pictureDeriv == null)
         options.first = true;
@@ -1924,5 +1907,4 @@
         options.first = false;
       // =================== Gestion liste photos size
-      // ============================
       us = 0;
       if (!options.theMainImageWidth) options.theMainImageWidth = options.scaledWidth;
@@ -1989,5 +1971,5 @@
       Autosize_resize(true, options);
       Autosize_resize(true, options);
-      jQuery("#" + Type_Img).show(options.fade_in);
+      jQuery("#" + Type_Img).show(fade_in);
     };
     // _______________________ init_gen _______________________
@@ -2183,5 +2165,5 @@
     } // Debug_pos
     // ==========================================================
-  });                                                                                                                                                                   // ready
+  });                                                                                                                                                                                                    // ready
   jQuery("#derivativeSwitchBox a").click(function (e) {
     k1 = 0;
Index: extensions/Autosize/main.inc.php
===================================================================
--- extensions/Autosize/main.inc.php	(revision 22248)
+++ extensions/Autosize/main.inc.php	(revision 22292)
@@ -2,5 +2,5 @@
 /*
  Plugin Name: AutoSize
-Version: 3.1.2
+Version: 3.1.3
 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
