Index: extensions/Autosize/js/Affiche_script.js
===================================================================
--- extensions/Autosize/js/Affiche_script.js	(revision 18949)
+++ extensions/Autosize/js/Affiche_script.js	(revision 18975)
@@ -246,4 +246,6 @@
         }
       }
+      Affiche_limite(pictureSelType_user);
+      jQuery("#derivativeChecked" + options.pictureDeriv).css({ visibility: 'visible'      });
 
     }
@@ -438,9 +440,4 @@
       jQuery(window).resize(function (event, ui) {
         Autosize_resize(true, options);
-
-        return;
-
-
-
       });
       //_____________ widow.resize _______________
@@ -457,10 +454,6 @@
       marges_llgbo = 0;
       //========================================================================================== 
-      if (options.valide) {
-
-        init_gen();
-
-
-      }
+      init_gen();
+
 
     });
@@ -502,21 +495,16 @@
 
     options = jQuery.extend(defaults, options);
-
-
-    for (i = 0; i < options.liste_type.length; i++) {
-      options.liste_type[i] = options.liste_type[i].split(",");
-    }
-
     options.theMainImageWidth = options.theMainImageWidth;
     options.theMainImageHeight = options.theMainImageHeight;
-
+    jQuery("#the_page").append("<div id='form_autosize_picture' ></div>");
     jQuery("#form_autosize_picture").addClass("Autosize");
     //===== marges suplémentaires en fonction theme ===
     options.valide = jQuery(".Autosize").css("display") != "none";
-
     options.marge_haute = jQuery(".Autosize").Get_Val_int(jQuery(".Autosize").css("top"));
     options.marge_basse = jQuery(".Autosize").Get_Val_int(jQuery(".Autosize").css("bottom"));
     options.marge_gauche = jQuery(".Autosize").Get_Val_int(jQuery(".Autosize").css("left"));
     options.marge_droite = jQuery(".Autosize").Get_Val_int(jQuery(".Autosize").css("right"));
+    jQuery(".Autosize").hide();
+
     fade_in = options.fade_in || 0;
     imageComment_id = ".imageComment";
@@ -546,7 +534,10 @@
     var useMap = options.pictureMap; // #mapxxx
     var user_status = options.user_status;
+    var chk = eval("options." + user_status + "_enabled");
+    if (chk == "") { options.valide = false; }
 
     var pictureDeriv = options.pictureDeriv; // xxx
     var pictureSelType_user = eval("options." + user_status + "_type"); //limite taille
+
     if (Type_Img == "pamoorama")
       options.pictureSelType = "Autosize";
@@ -566,5 +557,57 @@
     }
 
-
+    for (i = 0; i < options.liste_type.length; i++) {
+      options.liste_type[i] = options.liste_type[i].split(",");
+    }
+
+
+    // auto_details
+    //==== limite affichage selection = select_type ====
+    var path_names = new Array();
+
+    Affiche_limite = function (pictureSelType_Maxi) {
+      n = 0;
+      var pt = new Array();
+      path_names = new Array();
+      jQuery("#derivativeSwitchBox a").css('visibility', 'hidden');
+      jQuery(".switchCheck").css('visibility', 'hidden');
+      var maxi_display = false;
+      jQuery("#derivativeSwitchBox a").each(function (i) {
+        href_path = jQuery(this).attr("href");
+        patname = href_path.replace("javascript\:", "");
+        path_names.push(patname);
+        pt[i] = href_path.split("','");
+        tsz = pt[i][2].replace("')", "");
+        if (!maxi_display)
+          jQuery(this).css('visibility', 'visible');
+        else {
+          jQuery(this).next().next().remove();
+          jQuery(this).next().remove();
+          jQuery(this).remove();
+        }
+        //--- recherche limite ---
+
+        if (!options.valide && (tsz == "Autosize" || tsz == "SelMaxi")) {
+          jQuery(this).next().next().remove();
+          jQuery(this).next().remove();
+          jQuery(this).remove();
+        } else {
+          if (tsz == "Original" && (pictureSelType_Maxi != "Autosize" && pictureSelType_Maxi != "SelMaxi")) {
+            maxi_display = true;
+          }
+          if (tsz == pictureSelType_Maxi && (pictureSelType_Maxi != "Autosize" && pictureSelType_Maxi != "SelMaxi")) {
+            maxi_display = true;
+
+          }
+
+        }
+        //--- type en cours ---
+        if (tsz.match(RegExp("^" + options.pictureDeriv, "gi"))) {
+          us = n;
+        }
+
+        n++;
+      });
+    }
     //=============================================================
     // REPONSE ACTION
@@ -715,11 +758,16 @@
     if (typeof decode_href != 'function') {
       function decode_href(myObj) {
-        href_path = jQuery(myObj).attr("href");
-        pt = href_path.split("(");
-        pt = pt[1].split(")");
-        pt = pt[0].replace(RegExp("'", "g"), "");
+        hrefPath = jQuery(myObj).attr("href");
+        if (hrefPath.indexOf("changeImg") == 0) {
+          pt = hrefPath;
+        } else {
+          pt = hrefPath.split("(");
+          pt = pt[1].split(")");
+          pt = pt[0].replace(RegExp("'", "g"), "");
+        }
         pt = pt.replace(RegExp(" ", "g"), "");
         pt = pt.split(",");
         source = pt[0];
+
         pictureDeriv = pt[1];
         pictureMap = pt[2];
@@ -738,4 +786,5 @@
 
     jQuery("#derivativeSwitchBox a").click(function (e) {
+      Affiche_limite(pictureSelType_user);
       retour = decode_href(this);
       theImg = document.getElementById(theMainImage_id.replace("#", ""));
@@ -750,4 +799,5 @@
           n = Get_dimensions(true, options);
         } else {
+
         }
 
@@ -812,12 +862,10 @@
     ***************************/
     Autosize_resize = function (force, parametres) {
-      n = Get_dimensions(true, options);
-      if (n == false) return;
+      nAuto = Get_dimensions(true, options);
+
       Save_cookies(options);
-      if (options.pictureSelType != "Autosize" && options.pictureSelType != "SelMaxi") {
-        /**/
+      if (!options.valide || nAuto == false || (options.pictureSelType != "Autosize" && options.pictureSelType != "SelMaxi")) {
         jQuery(theImg).width(Zone_image.image_init.width);
         jQuery(theImg).height(Zone_image.image_init.height);
-
         set_cl("no");
         Set_llbgo(true);
@@ -892,5 +940,5 @@
             jQuery("#theMainImage").height(png_h);
             jQuery("#" + Type_Img).height(png_h);
-          
+
 
           } else {
@@ -922,4 +970,7 @@
         if (url.match(RegExp("i.php", "gi"))) {
           urls = url.split("?");
+          urls = urls[1].split("?");
+          //   Set_images(urls);
+
         }
       }
@@ -947,8 +998,8 @@
       options.pictureDeriv = typeSave;
       document.cookie = 'picture_deriv=' + typeSave + ';path=' + COOKIE_PATH;
-
-
-
-      jQuery("#theMainImage").removeAttr("width height").attr("src", url)
+      jQuery("#theMainImage").attr("src", url);
+
+      // jQuery("#theMainImage," + theMainImage_id + ",.preload, .next1 , ")
+      jQuery("#theMainImage").removeAttr("width height")
       .load(function (i) {
         if (!init_img(this)) {
@@ -958,57 +1009,60 @@
 
       })
-      .live("ON", function (e) {
-        theMainImage_st = this.complete;
+      .error(function (e) {
         imgsrc = this.src;
-        // alert(this.src + ' Image does not exist !!');
-      }).error(function (i) {
-        imgsrc = this.src;
-      });
-      /***********************
-      *
-      **********************/
-      jQuery("#theMainImage," + theMainImage_id + ",.preload, .next1 , ")
-         .error(function (e) {
-           if (!this.complete) {
-             // le fichier n'est pas present 
-             src = jQuery(this).attr("src").replace("./_data/i/", "", 1);
-             src = this.src.split("/_data/i")[1];
-             url = 'i.php?' + src + "&ajaxload=true";
-             jQuery(theMainImage_id).attr("src", url);
-             /*
-             jQuery.ajax({
-             type: 'GET',
-             url: 'i.php?' + src + "&ajaxload=true",
-             dataType: 'json',
-             success: (function (data) {
-             j = data.url;
-             //  jQuery(theMainImage_id).attr("src", data.url);
+        if (!this.complete) {
+          // le fichier n'est pas present 
+          imgsrc = jQuery(this).attr("src");
+
+          return false;
+
+          imgsrc = jQuery(this).attr("src").replace("./_data/i/", "", 1);
+          imgsrc = this.src.split("/_data/i")[1];
+          if (typeof imgsrc == "undefined") return false;
+          url = 'i.php?' + imgsrc + "&ajaxload=true";
+          jQuery(theMainImage_id).attr("src", url);
+          //  getDerivativeUrls(imgsrc);
+        }
+
+      })
+           .live("Success", function (e) {
+             if (typeof imageInfos_id == "undefined") return false;
+           })
+
+            .live("Error", function (data) {
+              if (typeof imageInfos_id == "undefined") return;
+
+            })
+             .live("fail", function (data) {
+               if (typeof imageInfos_id == "undefined") return;
 
              })
-
-             });
-             */
-
-
-
-           }
+              .live("Progress", function (data) {
+                if (typeof imageInfos_id == "undefined") return;
+
+              })
+              .live("IsRejected", function (data) {
+                if (typeof imageInfos_id == "undefined") return;
+
+              })
+         .live("Finish", function (e, data) {
+           if (typeof imageInfos_id == "undefined") return;
 
          })
-         .bind("Finish", function (e, data) {
-           if (typeof imageInfos_id == "undefined") return;
-
+         .live("change", function (e) {
+           theMainImage_st = this.complete;
+           imgsrc = this.src;
          })
-          .bind("ON", function (e, data) {
-            if (data.status != "ok") {
-              popup = jQuery(".errors");
-              if (popup.length == 0) {
-                jQuery("#theImage").append("<div class='errors'><span></span></div>");
+            .live("Complete", function (e, data) {
+              if (data.statusText != "OK") {
+                popup = jQuery(".errors");
+                if (popup.length == 0) {
+                  jQuery("#theImage").append("<div class='errors'><span></span></div>");
+                }
+                jQuery(".errors").text("Erreur : [" + data.done + "] " + data.src);
+                jQuery(".errors").show().delay(10000).hide(2000);
+                return;
               }
-              jQuery(".errors").text("Erreur : [" + data.done + "] " + data.responseText);
-              jQuery(".errors").show().delay(10000).hide(2000);
-              return;
-            }
-            if (data.src) {
-              if (typeof imageInfos_id == "undefined") return;
+              if (data.src) { }
               if (options.pictureDeriv == "Original" && data.src.match(RegExp("\-.." + ".jpg", "gi"))) {
                 Autosize_resize(true, options);
@@ -1018,6 +1072,14 @@
 
               }
-            }
-          });
+              type = options.pictureSelType;
+              typeSave = options.pictureDeriv;
+              jQuery('#derivativeSwitchBox .switchCheck').css('visibility', 'hidden');
+              if (typeof type != "undefined" && (type == "Autosize" || type == "SelMaxi")) {
+                jQuery('#derivativeChecked' + type).css('visibility', 'visible');
+              } else {
+                jQuery('#derivativeChecked' + typeSave).css('visibility', 'visible');
+              }
+
+            });
       //_________ theMainImage  ___________
 
@@ -1100,8 +1162,4 @@
     //__________________ Wait_pamoorama ______________________
     jQuery(".pwg-icon-clock-minus, .pwg-icon-clock-plus").click(function (i) {
-
-
-
-
 
     }).mouseover(function (i) {
@@ -1290,6 +1348,7 @@
         jQuery(pt).each(function (i) {
           vn = this;
-          size_derive = { w: parseInt(vn[2]), h: parseInt(vn[3]) };
-          if (vn[0] == options.pictureSelType || vn[0] == "Original") {
+          v_pictureDeriv = vn[0]; v_imgSrc = vn[1]; v_width = parseInt(vn[2]); v_height = parseInt(vn[3]);
+          size_derive = { w: v_width, h: v_height };
+          if (v_pictureDeriv == options.pictureSelType || v_pictureDeriv == "Original") {
             maxi_size = size_derive;
             maxi_size.idx = n;
@@ -1297,5 +1356,5 @@
           }
 
-          if (vn[0] != "square" && vn[0] != "thumb" && vn[0] != "SelMaxi" && vn[0] != "Autosize") {
+          if (v_pictureDeriv != "square" && v_pictureDeriv != "thumb" && v_pictureDeriv != "SelMaxi" && v_pictureDeriv != "Autosize") {
             if (size_derive.h > size_encours.h) {
               if (maxi_size.idx < 0) {
@@ -1337,5 +1396,6 @@
             last_id = this.id.replace("derivativeChecked", "");
           }
-          if (last_id.match(RegExp(pictureDeriv, "gi"))) return false;
+          if (last_id == pictureDeriv)
+            return false;
         });
 
@@ -1388,5 +1448,6 @@
         identique = Zone_image.src.match(RegExp(imgSrc, "gi"));
         if (identique) return;
-        href_path = "javascript:changeImgSrc('" + imgSrc + "', '" + IMg.pictureDeriv + "', '" + IMg.pictureMap + "', '" + options.pictureSelType + "')";
+        href = get_href(IMg.pictureDeriv);
+        href_path = "javascript:" + href;
         jQuery(".linkAutosize").attr("href", href_path);
         theImg = document.getElementById(theMainImage_id.replace("#", ""));
@@ -1398,5 +1459,6 @@
         } else {
           last_id = IMg.pictureDeriv;
-          changeImgSrc(imgSrc, last_id, IMg.pictureMap, options.pictureSelType);
+          eval(href);
+          //changeImgSrc(imgSrc, last_id, IMg.pictureMap, options.pictureSelType);
         }
 
@@ -1421,4 +1483,20 @@
     };  //_______________ Select_Image ______
 
+    get_href = function (NewpictureDeriv) {
+      for (i = 0; i < path_names.length; i++) {
+        newHref = path_names[i];
+        match = ",'" + NewpictureDeriv;
+        newHref_ind = newHref.indexOf(match);
+        if (newHref_ind > 0) {
+          href = newHref;
+          if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi") {
+            href = href.replace("')", "','" + options.pictureSelType + "')");
+          }
+          break;
+        }
+
+      }
+      return href;
+    };
 
     /*************************************************
@@ -1567,5 +1645,5 @@
       marge_right = options.marge_right | 0;
       marge_top = options.marge_top | 0;
-      marge_bottom = options.marge_bottom | 0;
+
 
       //==========================================================
@@ -1615,5 +1693,6 @@
       //========== Format Image ==============  
       retrait_img.height = Math.ceil(options.marges_llgbo || 0)
-      + Math.ceil(infos_theMainImage.general.marges.height);
+      + Math.ceil(infos_theMainImage.general.marges.height) +
+      +Math.ceil(options.marges_llgbo || 0);
       retrait_img.height += 2;
 
@@ -1625,6 +1704,6 @@
       retrait_img.width += 2;
       if (!options.check_desc_v)
-        marge_bottom = 0;
-
+        options.marge_bottom_2 = 0;
+      marge_bottom = options.marge_bottom_2 + options.marge_bottom;
       //================== Limite Format Image =====================
       container.height_interne = container.height - marge_top - marge_bottom;
@@ -1702,18 +1781,16 @@
       options.theImageLeft = new_dim.left;
       options.theImageRight = (new_win.width - new_dim.right);
-      options.marge_bottom = Math.ceil(new_dim.out.bottom - new_img.out.bottom);
+      options.marge_bottom_2 = Math.ceil(new_dim.out.bottom - new_img.out.bottom);
       if (Type_Img == "iframe") { }
-      new_dim.out.bottom = new_win.height - options.marge_bottom;
+      new_dim.out.bottom = new_win.height - options.marge_bottom_2;
 
       options.theImageBottom = new_win.height - new_dim.out.bottom;
       options.marge_top = Math.ceil(new_img.top - new_dim.top);
 
-      if (options.theImageBottom < 0) {
-        options.theImageBottom = 0;
+      if (options.theImageBottom_2 < 0) {
+        options.theImageBottom_2 = 0;
       }
       options.theImageWidth = new_win.width - options.theImageLeft - options.theImageRight;
       options.theImageHeight = new_win.height - options.marge_top - options.theImageBottom - options.theImageTop;
-      var chk = eval("options." + user_status + "_enabled");
-      if (chk == "") { return; }
 
       if (Type_Img != "map" && Type_Img != "iframe")
@@ -1722,23 +1799,4 @@
       Zone_image.src = infos_theMainImage.src;
       useMap = options.pictureSelType;
-      /*
-      if (useMap) {
-      if (!useMap.match(RegExp("Autosize", "gi"))) {
-      if (typeof img_height != "undefined") {
-      jQuery(theImg).height(img_height);
-      jQuery(theImg).width(img_width);
-      }
-      return;
-      }
-      }
-
-      if (options.imageAutosize) {
-      return true; //stripped
-      }
-
-      if (typeof options.cl_visible == "undefined") return;
-      if (!options.cl_visible == true) { return; }
-      */
-
       //=================================================================
       switch (Type_Img) {
@@ -1763,5 +1821,5 @@
         case "img_autre":
           if (!theMainImage_id) {
-            if (DEBUG_autosize.match("true", gi)) alert("The_MainImage=null");
+            if (DEBUG_autosize.match("true", "gi")) alert("The_MainImage=null");
             return;
 
@@ -1871,6 +1929,10 @@
 
         options.marge_top = infos_theMainImage.top - infos_theImage.top;
-      } else
+        options.marge_bottom = Math.ceil(options.marge_basse + options.marge_top);
+
+      } else {
         pos_top = infos_theImageAndInfos.top;
+        options.marge_bottom = Math.ceil(options.marge_basse);
+      }
 
       options.pos_top = pos_top;
@@ -1878,5 +1940,5 @@
       options.marge_right = infos_theImage.general.marges.right + Math.ceil(options.marge_droite);
       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 (options.pictureDeriv == null)
         options.first = true;
@@ -1913,6 +1975,12 @@
         pictureSelType = options.pictureSelType;
       }
+      Affiche_limite(pictureSelType_user);
+
       //=================== 2==================================
-      href_path = "javascript:changeImgSrc('" + options.imgSrc + "', '" + options.pictureDeriv + "', '" + options.pictureDeriv + "', '" + "SelMaxi" + "')";
+      sav_p = options.pictureSelType;
+      options.pictureSelType = "SelMaxi";
+      href = get_href(options.pictureDeriv);
+      href_path = "javascript:" + href;
+
       spans = jQuery("#derivativeCheckedSelMaxi").next();
       spans.attr("href", href_path);
@@ -1922,5 +1990,7 @@
       spans.text("(" + options.theMainImageWidth + " x " + options.theMainImageHeight + ")");
       //==========================================================
-      href_path = "javascript:changeImgSrc('" + options.imgSrc + "', '" + options.pictureDeriv + "', '" + options.pictureDeriv + "', '" + "Autosize" + "')";
+      options.pictureSelType = "Autosize";
+      href = get_href(options.pictureDeriv);
+      href_path = "javascript:" + href;
 
       spans = jQuery("#derivativeCheckedAutosize").next();
@@ -1931,4 +2001,5 @@
       spans.text("(" + options.theMainImageWidth + " x " + options.theMainImageHeight + ")");
       //==========================================================
+      options.pictureSelType = sav_p;
 
       if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi") {
@@ -1940,4 +2011,5 @@
       Autosize_resize(true, options);
       Autosize_resize(true, options);
+
     };
     //_______________________ init_gen _______________________
@@ -2147,5 +2219,6 @@
 
 
-  });                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     // ready
+  });                           // ready
+
 
 
