// problème avec GMaps+diaporama:
// corriger   gmaps_pip.class.inc.php ajouter ligne 90 if ( !isset($_GET['slideshow']))
//==============================================================  
  jQuery.Affiche_script = { version: '2.0.0' };
  /********************************************
  *  document ready
  ********************************************/
  jQuery(document).ready(function (jQuery) {
    var Type_Img;
    var theImg;
    var Zone_image;

    /******************************************
    * test_theme("mont,pur") ...
    ******************************************/

    test_theme = function (param) {
      if (!param) return
      if (!options.theme) return;

      regx = new RegExp(param, "gi");
      return (options.theme.match(regx))

    }
    /******************************************
    * Save_cookies
    ******************************************/
    Save_cookies = function (parametres) {
      parametres.windowHeight = jQuery(window).height();
      parametres.windowWidth = jQuery(window).width();
      try {
        if (parametres.pictureDeriv) jQuery.cookie('picture_deriv', parametres.pictureDeriv, { path: COOKIE_PATH });
        if (parametres.pictureSelType) jQuery.cookie('picture_sel_type', parametres.pictureSelType, { path: COOKIE_PATH });
        if (parametres.pictureMap) jQuery.cookie('picture_map', parametres.pictureMap, { path: COOKIE_PATH });
        if (parametres.imgSrc) jQuery.cookie('img_src', parametres.imgSrc, { path: COOKIE_PATH });
        if (parametres.theMainImageHeight) jQuery.cookie('theMainImageHeight', parametres.theMainImageHeight, { path: COOKIE_PATH });
        if (parametres.theMainImageWidth) jQuery.cookie('theMainImageWidth', parametres.theMainImageWidth, { path: COOKIE_PATH });
        if (parametres.theImageHeight) jQuery.cookie('theImageHeight', parametres.theImageHeight, { path: COOKIE_PATH });
        if (parametres.theImageWidth) jQuery.cookie('theImageWidth', parametres.theImageWidth, { path: COOKIE_PATH });
        if (parametres.windowHeight) jQuery.cookie('windowHeight', parametres.windowHeight, { path: COOKIE_PATH });
        if (parametres.windowWidth) jQuery.cookie('windowWidth', parametres.windowWidth, { path: COOKIE_PATH });
        if (parametres.theImageTop) jQuery.cookie('theImageTop', parametres.theImageTop, { path: COOKIE_PATH });
        if (parametres.theImageLeft) jQuery.cookie('theImageLeft', parametres.theImageLeft, { path: COOKIE_PATH });
        if (parametres.theImageRight) jQuery.cookie('theImageRight', parametres.theImageRight, { path: COOKIE_PATH });
        if (parametres.theImageBottom) jQuery.cookie('theImageBottom', parametres.theImageBottom, { path: COOKIE_PATH });
        if (parametres.theImageMargeZone) {
          jQuery.cookie('theImageMargeWidth', parametres.theImageMargeZone.width, { path: COOKIE_PATH });
          jQuery.cookie('theImageMargeHeight', parametres.theImageMargeZone.height, { path: COOKIE_PATH });
        }
      } catch (e) {
        n = 1;
      }


    }
    //____________________ Save_cookies _____________________________
    /************************************************
    *  Get COOKIE
    *************************************************/
    Get_cookies = function () {
      parametres = {
        pictureDeriv: jQuery.cookie('picture_deriv'),
        pictureMap: jQuery.cookie('picture_map'),
        pictureSelType: jQuery.cookie('picture_sel_type'),

        imgSrc: jQuery.cookie('img_src'),
        theMainImageHeight: jQuery.cookie('theMainImageHeight'),
        theMainImageWidth: jQuery.cookie('theMainImageWidth'),

        windowHeight: jQuery.cookie('windowHeight'),
        windowWidth: jQuery.cookie('windowWidth'),

        theImageHeight: jQuery.cookie('theImageHeight'),
        theImageWidth: jQuery.cookie('theImageWidth'),
        theImageTop: jQuery.cookie('theImageTop'),
        theImageLeft: jQuery.cookie('theImageLeft'),
        theImageBottom: jQuery.cookie('theImageBottom'),
        theImageRight: jQuery.cookie('theImageRight'),
        theImageMargeZone: { width: jQuery.cookie('theImageMargeWidth'),
          height: jQuery.cookie('theImageMargeHeight')
        }


      }
      return parametres;
    }
    //____________________ Get_cookies _____________________________



    /*************************************************
    * Recupère le Type d'mage
    *************************************************/
    Get_type_img = function (e) {
      //====== détection du type d'images ======

      if (jQuery("#charlie").length > 0) {
        Type_Img = "charlie";
      } else if (jQuery("#Panorama").length > 0) {
        Type_Img = "panorama";

      } else if (jQuery("#pamoorama").length > 0) {
        Type_Img = "pamoorama";
        options.valide = true;

        infos_pamoorama = jQuery("#pamoorama").infos({ absolute: true });

      } else if (jQuery("#map").length > 0 || jQuery("#mapPicture").length > 0) {
        Type_Img = "map";
      } else if (jQuery("#Panorama").length) {
        Type_Img = "panorama";
      } else if ((jQuery("#theImage" + " iframe").length + jQuery("#theImage" + " object").length + jQuery("#theImage" + " embed").length) > 0) {

        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";
        //'fb - xfbml - like - button
        objs = jQuery("#theImage" + " div").get(0);
        if (jQuery(objs).length > 0) {
          id_0 = jQuery(objs).attr("id");
          if (id_0 == "") {
            jQuery(objs).attr("id", "charlie");
          } else {
            if (nbf > 1) {
              jQuery(frm1).attr("id", "charlie");
            } else {
              //  Type_Img = "img";
            }
          }
        } else {
          jQuery(frm1).attr("id", "iframe");
          jQuery(frm1).wrap('<div id="' + "theMainImage" + '" style="border:1px solid Transparent" />');
        }


      } else if (jQuery("#theImage").find("img").length > 0) {
        Type_Img = "img";
      } else if (jQuery("#theImage" + "Box").find("img").length > 0) {
        Type_Img = "img";
        Parent = Parent + "Box";
      } else if (jQuery("img").length > 0) {
        Type_Img = "img_autre";
        return;
      } else {
        return;
      }
    }
    //____________________ Get_type_img _____________________________

    //====================================
    //  set_cl
    //====================================
    set_cl = function (Valid) {

      if (typeof Valid == "undefined") Valid = options.pictureSelType.match(RegExp("Autosize", "gi")) || false;
      if (typeof options.cl_visible == "undefined") return;
      if (typeof src1 == "undefined") return;
      if (options.cl_visible) src = src1;
      else src = src2;

      if (typeof options.pictureSelType != "undefined" && (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi")) {
        if (options.pictureSelType == "SelMaxi") src = src6;
      } else {
        Valid = false;
        src = src2;
        jQuery("#bp_cla span").text("");
      }
      if (options.cl_visible) {
        src_info = src3;
        src_infos_1 = src3;
      } else {
        src_info = src4;
        src_infos_1 = src5;
      }
      src_info = options.pictureDeriv;
      if (!Valid) {
        Zone_image.image.height = Zone_image.image_init.height;
        Zone_image.image.width = Zone_image.image_init.width;

      }

      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) + "%"; ;
        if (!Valid) {
          if (options.pictureSelType == "SelMaxi")
            zoom_cl = options.pictureSelType + " [" + options.pictureDeriv + "]";
          else {
            zoom_cl = "";
            src_info = options.pictureDeriv;
          }
        }
        if (Type_Img == "pamoorama" || Type_Img == "iframe" || Type_Img == "charlie") {
          zoom_cl = "";
          src_info = "";
          src = src2;
        }

        jQuery('#bp_cla').attr('alt', src_info);
        jQuery('#bp_cla').attr('title', src_info);
        jQuery('#bp_cla').attr('Stitle', src_info);
        jQuery('#bp_cla').attr('Stip', zoom_cl);
        r = { width: jQuery("#theMainImage").width(), height: jQuery("#theMainImage").height(),
          rap: jQuery("#theMainImage").width() / jQuery("#theMainImage").height(),
          rap_init: Zone_image.image_init.rapport
        }
        jQuery('#bp_cla span').text(zoom_cl);
        color_back = jQuery('#imageToolBar').css("backgroundColor");
        try {
          if (color_back.match(new RegExp("rgb", "gi"))) {
            color_back = color_back.split("(")[1].split(")")[0].split(",");
            color_back = "rgb(" + Math.abs(255 - color_back[0]) + ","
                + Math.abs(255 - color_back[1]) + ","
                + Math.abs(255 - color_back[2]) + ")";
          }
          else if (color_back.match(new RegExp("#", "gi")))
            color_back = Math.abs("#65536" - color_back);
          else
            color_back = jQuery('body').css("color");
          jQuery('#bp_cla span').css({ color: color_back, aling: "center" });
        } catch (e) {

        }
        jQuery("#derivativeSwitchBox span").removeClass("auto_details linkAutosize");
        jQuery("#derivativeSwitchBox a").removeClass("auto_details linkAutosize");
        if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi") {
          spans = jQuery("#derivativeChecked" + options.pictureSelType).next();
          spans.addClass("linkAutosize");
          spans.find("span").addClass("auto_details");
          jQuery(".auto_details").text("");
        }
        if (options.pictureDeriv) {
          if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi")
            jQuery("#derivativeChecked" + options.pictureSelType).css("visibility", "visible");
          else
            jQuery("#derivativeChecked" + options.pictureDeriv).css("visibility", "visible");
          jQuery('.auto_details').text(" (" + Zone_image.image.width + " x " + Zone_image.image.height + ") " + options.pictureDeriv);
        }
        //===============================================
      } else {
        src = src6;
        jQuery('.auto_details').text("");

      }
      bp_scr = jQuery('#bp_img_cla');
      if (bp_scr.length > 0) {
        src_enc = bp_scr.attr("src");
        if (!src_enc.match(src)) {
          bp_scr.get(0).src = src;
          jQuery('#bp_img_cla').attr('alt', src_info);
          jQuery('#bp_img_cla').attr('title', src_info);
        }
      }
      Affiche_limite(pictureSelType_user);
    }
    //____________________ set_cl _____________________________

    /********************************
    * Set__llbgo
    *********************************/
    Set_llbgo = function (Force) {

      if (options.marges_llgbo == 0) return;
      if (Type_Img == "pamoorama") {

      }
      if (Force)
        if (typeof LlgboFr_Resize == "function") {
          LlgboFr_Resize();
        }
      if (Type_Img == "pamoorama" || Type_Img == "charlie") {
        return;
      }
      if (!theImg) return;

      if (theImg.useMap)
        nom_map = theImg.useMap.replace("#", "");
      else
        nom_map = "Autosize";

      maps = jQuery("map[name='" + nom_map + "']");
      if (maps.length == 0) return;
      // nom_map = maps[0].name;
      maps = jQuery("map[name='" + nom_map + "']  area");
      nb_zone = maps.length;
      Largeur_zone = (Zone_image.image.width / nb_zone);
      Hauteur_zone = (Zone_image.image.height);
      init_zone = 0;
      j = 0;
      maps.each(function (e) {
        init_zone = Largeur_zone * j;
        rel = jQuery(this).attr("rel");
        title = jQuery(this).attr("title");
        alt = jQuery(this).attr("alt");
        H = Hauteur_zone;
        if (rel == "up") {
          H = Hauteur_zone / 4;
        }
        coord = { x0: init_zone, y0: 0, x1: Math.ceil(init_zone + Largeur_zone), y1: Hauteur_zone };
        jQuery(this).attr({ coords: "'" + coord.x0 + "," + coord.y0 + "," + coord.x1 + "," + coord.y1 + "'" });
        j++;
      });

      return;
    }
    //__________  Set_llbgo _______________
    var wpng = 0;
    /********************************************
    *  window LOAD
    ********************************************/
    jQuery(window).load(function () {
      location_href = location.href;
      var aff_ok = false;
      //=======================================================================
      infos_theImage = jQuery(theImage_id).infos({ absolute: true });
      infos_theMainImage = jQuery(theMainImage_id).infos({ absolute: true });
      infos_theImageAndInfos = jQuery(theImageAndInfos_id).infos();  // Cadre general
      the_mainImage_obj = "theMainImage_obj";
      infos_theMainImage_obj = jQuery("#" + the_mainImage_obj).infos({ absolute: true });

      infos_theMainImage_obj.rapport = infos_theMainImage_obj.width / infos_theMainImage_obj.height;
      if (infos_theMainImage.width == 0) {
        if (Type_Img == "pamoorama") {
          infos_theMainImage = jQuery("#pamoorama").infos(true);
          theMainImage_id = "#pamoorama";
          options.valide = true;
        } else if (Type_Img == "charlie") {
          infos_theMainImage = jQuery("#charlie").infos(true);
          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) {
            imgSrc = options.imgSrc;
          });
          infos_theMainImage = jQuery("#theImage img").infos();
        }
        if (infos_theMainImage.id == "")
          jQuery("#theImage img").attr("id", "theMainImage");
        infos_theMainImage = jQuery(theMainImage_id).infos();
      }

      infos_theImage = jQuery(theImage_id).infos(true);                 // conteneur
      if (options.pictureSelType != "Autosize" && options.pictureSelType != "SelMaxi") {
        jQuery('#derivativeSwitchLink').show();
      }
      if (test_theme("simple")) {
        jQuery(theMainImage_id).css({ maxWidth: "none" });
        theImageAndInfos_id = "#content";
        infos_theImageAndInfos = jQuery(theImageAndInfos_id).infos();  // Cadre general
        infos_theImage.height = infos_window.height - infos_theImage.top;
        //  jQuery(theImage_id).height(infos_theImage.height);

      } else {
        infos_theImageAndInfos = jQuery(theImageAndInfos_id).infos();  // Cadre general
        if (infos_theImageAndInfos.visible == false)
          theImageAndInfos_id = "#imageContainer";
      }


      imageInfos_id = "#imageInfos";

      content_id = "#content";
      infos_content = jQuery(content_id).infos(true);                 // conteneur
      infos_theImage = jQuery(theImage_id).infos(true);                 // conteneur
      infos_imageInfos = jQuery(imageInfos_id).infos(true);             // information
      infos_theMainImage = jQuery(theMainImage_id).infos(true);         // Image 
      infos_copyright = jQuery("#copyright").infos(true);


      if (infos_theImage.top > infos_window.height) {
        zheight = infos_window.height - infos_content.top;
      } else {
        zheight = infos_window.height - (infos_theImage.top);
      }


      if (options.check_desc_v) { }

      infos_comments = jQuery("#comments").infos(true);
      infos_Licence = jQuery(".licencetag").infos(true);
      infos_imageComment = jQuery(imageComment_id).infos(true);



      if (test_theme("simple")) {


      } else {
        if (test_theme("stripped")) {

        } else

          if (test_theme("blanc , pure, hr_ ")) {
            options.marge_gauche += 10;
            options.marge_droite += 10;
          }
      }


      Zone_image = { image_init: {
        width: infos_theMainImage.width,
        height: infos_theMainImage.height,
        rapport: infos_theMainImage.width / infos_theMainImage.height
      },
        image: {
          width: infos_theImage.general.width,
          height: infos_window.height - infos_theImage.top - options.marge_basse,
          rapport: infos_theMainImage.width / infos_theMainImage.height
        },
        container: {
          width: infos_theImage.general.width,
          height: zheight,
          margesWidth: infos_window.width - infos_theImage.width
        }, marges: {
          height: 0,
          width: 0
        }
      }


      Zone_image.zoom = (Zone_image.image.height / Zone_image.image_init.height);




      /***********************************************************
      *  RESIZE (une fois document chargé)
      ***********************************************************/
      var new_dim;
      jQuery(window).resize(function (event, ui) {
        Autosize_resize(true, options);
      });
      //_____________ widow.resize _______________

      type_src = "div";
      old_window = { width: 0, height: 0 };
      List_autosize = new Array();
      nu_img = 0;
      tempo = 0;


      infos_llgbo = jQuery(llgbo_id).infos(true);
      infos_llgboh2 = jQuery("#llgboh2").infos(true);
      marges_llgbo = 0;
      //========================================================================================== 
      init_gen();


    });
    //__________________window.onload_________________

    /********************************************
    *  window unLOAD
    ********************************************/
    jQuery(window).unload(function () {
      //  return;
    });
    //_________ unload ___________

    //===================
    // VARIABLES  


    //===================
    // options 
    //=========================================================
    if (typeof (options) == "undefined") {
      options = { imageAutosize: false }
    }
    options = jQuery.extend(Autosize_options, options);


    var defaults = {
      imageAutosizeMargin: 0,
      imageAutosize: false,
      marge_basse: options.imageAutosizeMargin || 0,
      DEBUG_autosize: false
    };

    options = jQuery.extend(defaults, options);
    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 = Math.max(
  jQuery(".Autosize").Get_Val_int(jQuery(".Autosize").css("bottom")),
  options.marge_basse
  );

    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();
    DEBUG_autosize = options.DEBUG_autosize;
    var COOKIE_PATH = options.COOKIE_PATH;
    var cookies = Get_cookies();

    fade_in = options.fade_in || 0;
    imageComment_id = ".imageComment";
    if (test_theme("simple")) {
      jQuery("#theImage p").addClass("imageComment");
    }
    if (test_theme("mont")) {
      jQuery("#content").css({ marginLeft: 'auto' }); //monblanc
    }


    Get_type_img();

    var infos_theMainImage_obj;
    var theMainImage_id = "#theMainImage";
    var theImage_id = "#theImage";
    var theImageAndInfos_id = "#theImageAndInfos";
    var infos_window = jQuery(window).infos();
    var infos_theImageAndInfos = jQuery(theImageAndInfos_id).infos();  // Cadre general
    var infos_content;
    var infos_body;
    var infos_the_page = jQuery("#the_page").infos(true);
    var nopano;
    var llgbo_id = "#llgbo0";
    var marges_llgbo = 0;

    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 (pictureSelType_user != "Autosize" && pictureSelType_user != "SelMaxi") {
      if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi") {
        options.pictureSelType = pictureSelType_user;
        options.pictureDeriv = pictureSelType_user;
      }
    }
    if (!cookies.pictureDeriv) Save_cookies(options);

    if (pictureSelType_user != options.pictureSelType) {
      if (pictureDeriv == null)
        pictureDeriv = pictureDeriv_user;
      else
        pictureDeriv_user = pictureDeriv;
    }

    if (!options.valide) {

      pictureDeriv = "medium";
      pictureDeriv_user = pictureDeriv;
      options.pictureDeriv = pictureDeriv;
    }
    if (Type_Img == "pamoorama" || Type_Img == "iframe" || Type_Img == "charlie") {
      options.pictureSelType = "Autosize";
    }
    new_liste = new Array();
    for (i = 0; i < options.liste_type.length; i++) {
      liste_types = options.liste_type[i].split(",");
      new_liste.push(options.liste_type[i].split(","));
      if (liste_types[0] == pictureSelType_user) {
        break;
      }
    }
    options.liste_type = new_liste;

    // 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");
        if (!href_path) {
          href_path = jQuery(this).html();
          return;
        }
        pt = href_path.replace(/(javascript|changeImgSrc)|[('):]/gi, "");

        patname = href_path.replace("javascript\:", "");
        if (typeof old_path == "undefined") old_path = patname;
        pt = pt.split(",");
        tsz = pt[pt.length - 1];
        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;
          } else if (tsz == pictureSelType_Maxi && (pictureSelType_Maxi != "Autosize" && pictureSelType_Maxi != "SelMaxi")) {
            maxi_display = true;

          } else if (tsz == "Autosize" || tsz == "SelMaxi") {
            patname = old_path.replace("')", "','" + tsz + "')");
          } else
            old_path = patname;
          path_names.push(patname);

        }
        //--- type en cours ---
        if (tsz.match(RegExp("^" + options.pictureDeriv, "gi"))) {
          us = n;
        }

        n++;
      });
    }
    //=============================================================
    // REPONSE ACTION
    //=============================================================
    theMainImage_st = false;
    jQuery("#reset").click(function () {
      location.reload();
    });


    //===========================================================
    //  REPONSE TRIGGER 
    //===========================================================
    jQuery('#ret_autosize').live('ON', function (e) {
      if (nu_img == "") nu_img = 8;
      jQuery(jQuery('.debug').get(nu_img)).trigger('ON');

    });

    //==========================================================
    jQuery("map area").mouseover(function (e) {
      try {
        nok = theImg.useMap;
        hok = this;
      }
      catch (r) {

      }
    });

    //==================================
    // jQuery("#llgbo").trigger("ON");
    //==================================
    jQuery(llgbo_id).live('ON', function (e) {
      n_id = this;
      infos_llgbo = jQuery(llgbo_id).infos();
      if (infos_llgbo.visible == false) return;

      marges_llgbo = 0;
      if (infos_llgbo.height > 0) {
        infos_llgboframe1 = jQuery(llgbo_id + " div:last").infos();
        infos_llgboframe31 = jQuery(llgbo_id + "  div:first").infos();
        //=============================================
        ll2 = infos_llgboframe1.width; // llgboframe1 interieur
        ll1 = infos_llgboframe31.exterieur.width; // llgboframe31 avec border width
        options.marges_llgbo = (ll1 - ll2);
        infos_llgboh2 = jQuery("#llgboh2").infos();
      }
    });
    //==============================
    // jQuery("#mapPicture").trigger("ON");
    //==============================
    jQuery("#mapPicture").live('ON', function (e) {
      p2 = jQuery("#infoSwitcher").infos();
    });
    //==============================
    // jQuery("#map").trigger("ON");
    //==============================
    jQuery("#map").live('ON', function (e) {
      p2 = jQuery("#map").infos();
    });
    //===================================
    // jQuery("#theImage").trigger("ON");
    //===================================
    jQuery("#imageInfos").live('on', function (e) {
      target = e.target.id;
    });

    //===================================
    // jQuery("#theImage").trigger("ON");
    //===================================
    jQuery("#theImage").live('ON', function (e) {
      target = e.target.id;

      id = this.id;
      Select_Image(); //+calcul
    });




    //=================================================================
    jQuery(document).live('gallyInterfaceReady', function (e) {
      i = jQuery(this).text();
      jQuery(this).trigger('ON');
    }

          );


    /*********************************
    *
    ********************************/
    var old_width;

    jQuery("#theImage").resize(function (e) {

    });



    jQuery("#menuSwitcher,#infoSwitcher").click(function (e) {
      options.set_sw = this.id;
      setTimeout(function () { div_resize() }, 10);
      nu_img = 0;
    });

    div_resize = function (i) {

      jQuery("#theImage").trigger("resize");
      /* 
      if (jQuery("#theImage").width() != old_width) {
      setTimeout(function () { div_resize() }, 10);
      }
      */
    }
    //===========================================
    // 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) {

    });


    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
    //====================================================
    if (typeof decode_href != 'function') {
      function decode_href(myObj) {
        hrefPath = jQuery(myObj).attr("href");
        if (hrefPath.indexOf("changeImgSrc") < 0) {
          pt = hrefPath;
        } else {
          pt = hrefPath.replace(/(javascript|phpWGOpenWindow|javascript|changeImgSrc)|[('):]/gi, "");

        }
        pt = pt.split(",");
        source = pt[0];
        if (hrefPath.indexOf("phpWGOpenWindow") < 0) {
          pictureDeriv = pt[1];
          pictureMap = pt[2];
          pictureSelType = pt[pt.length - 1];
        } else {
          pictureDeriv = options.pictureDeriv;
          pictureMap = options.pictureMap;
          pictureSelType = options.pictureSelType;
        }
        return { source: source,
          pictureDeriv: pictureDeriv,
          pictureMap: pictureMap,
          pictureSelType: pictureSelType
        }
      }
    }

    jQuery("#derivativeSwitchBox a").click(function (e) {
      Affiche_limite(pictureSelType_user);
      retour = decode_href(this);
      theImg = document.getElementById(theMainImage_id.replace("#", ""));
      if (theImg) {
        // options.pictureDeriv = retour.pictureDeriv;
        options.pictureSelType = retour.pictureSelType;
        options.pictureDeriv = retour.pictureDeriv;
        options.pictureMap = retour.pictureDeriv;

        if (this.name) {
          options.pictureSelType = this.name;
          n = Get_dimensions(true, options);
        } else {

        }
        Autosize_resize(true, options);
      }
    });
    //__________ 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;
    });


    //====================================
    Autosize_init = function (name, value) {
      img_defaut = { height: options.scaled_height, width: options.scaled_width };
      img_reelle = { height: options.theImageHeight, width: options.theImageWidth };
      img_init = { height: options.theImageHeight, width: options.theImageWidth };  // taille initiale

      img_finale = img_init;

      useMap = infos_theMainImage.useMap; // #mapmedium

      useMap = options.pictureMap; // #mapxxx
      pictureDeriv = options.pictureDeriv; //picturederiv xxx


      old_img = options.imgSrc;
      old_window_height = options.windowHeight || jQuery(window).height();
      old_window_width = options.windowWidth || jQuery(window).width();
      old_img_h = options.imgHeight;
      old_img_w = options.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) {

      nAuto = Get_dimensions(true, options);

      Save_cookies(options);
      if (!options.valide || nAuto == false || (options.pictureSelType != "Autosize" && options.pictureSelType != "SelMaxi")) {
        if (options.imageAutosize == true) {
          options.pictureSelType = options.pictureDeriv;
          Zone_image.image_init.width = jQuery(theImg).width();
          Zone_image.image_init.height = jQuery(theImg).height();
          set_cl("no");
          Set_llbgo(true);
          return;
        }
        jQuery(theImg).width(Zone_image.image_init.width);
        jQuery(theImg).height(Zone_image.image_init.height);
        set_cl("no");
        Set_llbgo(true);
        return;

      }
      infos_theImage = jQuery(theImage_id).infos(true);
      if (typeof img_finale == "undefined") img_finale = { width: Zone_image.image.width, height: Zone_image.image.height };
      if (img_finale.width && (img_finale.width != Zone_image.image.width || img_finale.height != Zone_image.image.height)) {
        img_finale = { width: Zone_image.image.width, height: Zone_image.image.height };
      }
      r1 = Zone_image.image.width / Zone_image.image.height;
      //======================================================

      affiche_debug({

        Debug1: Debug_info(1, "Cont:" + infos_theImage.width
    + " X " + infos_theImage.height
    + " IMG: " + img_finale.width
    + " X " + img_finale.height
    + " mgw : " + Zone_image.marges.width
    , "->")
      });

      if (Type_Img == "pamoorama") {// img_finale.width
        jQuery("#pamoorama").width(img_finale.width);
        jQuery("#pamoorama").height(img_finale.height);


        infos_pamoorama = jQuery("#pamoorama").infos({ absolute: true });

        Set_Pamoorama({ width: img_finale.width, height: img_finale.height });
        if (nopano)
          if (window.myPamoorama.options.autoscrollOnLoad) {
            window.myPamoorama.startAnimRight();
          }

        //jQuery(theMainImage_id).height(Zone_image.image.height);
      } else {
        if (options.imageAutosize == false)
          if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi") {
            jQuery(theMainImage_id).height(Zone_image.image.height );
            jQuery(theMainImage_id).width(Zone_image.image.width);
           
            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;
            init_h1 = Autosize_options.ideal_size_height;
          }
          if (Type_Img == "charlie") {
            dp1 = jQuery("#charlie").offset();
            dp = jQuery("#" + the_mainImage_obj).offset();
            if (dp) {
              if (wpng == 0)
                wpng = Math.abs(dp.left - dp1.left) * 2;
            }
            png_h = init_h1;
            w01 = init_w1 - wpng;

            jQuery("#" + "theImage").css({ padding: 0 });
            if (!png_h) {
              png_h = jQuery("#theMainImage").height();
              h01 = png_h;
            } else
              h01 = Math.ceil(w01 / Zone_image.image.rapport);
            //==== Zone Affichage =====
            jQuery("#theMainImage").height(png_h);
            jQuery("#theMainImage").width(w01 + wpng);
            jQuery("#theMainImage").css({ verticalAlign: "middle", align: "center", textAlign: "center", margin: "auto" });

            jQuery("#" + the_mainImage_obj).attr("width", w01);
            jQuery("#" + the_mainImage_obj).attr("height", h01);

            jQuery("#theMainImage_emb").attr("width", w01); //firefox opera
            jQuery("#theMainImage_emb").attr("height", h01);

            if (jQuery("#theMainImage_vid").length > 0) {
              jQuery("#theMainImage_vid").attr("width", w01);
              jQuery("#theMainImage_vid").attr("height", h01);
            }
            if (jQuery("video").length > 0) {
              jQuery("video").attr("width", w01);
              jQuery("video").attr("height", h01);
            }
            jQuery("#" + Type_Img).height(png_h);
            jQuery("#" + Type_Img + " div").width(w01);
            jQuery("#theImage").css({ height: "auto" });
          } else {
            jQuery("#theImage").css({ height: "auto" });
            jQuery("#theMainImage").css({ width: "auto", height: "auto" });
            jQuery("#" + Type_Img).attr("width", init_w1 - (infos_theMainImage.borderwidth.left + infos_theMainImage.borderwidth.right));
            jQuery("#" + Type_Img).attr("height", init_h1 - (infos_theMainImage.borderwidth.top + infos_theMainImage.borderwidth.bottom));
          }
          jQuery("#" + Type_Img).show(options.fade_in);
        }


      }

      set_cl();
      Set_llbgo(true);
      return true;
    };
    //_________________Autosize ____________________________________   

    /*****************
    * changeImgSrc 
    ******************/
    changeImgSrc = function (url, typeSave, typeMap, type) {

      if (COOKIE_PATH == type) {
        type = options.pictureSelType;
      }
      if (typeof type != "undefined") {
        options.pictureSelType = type;
      } else {
        type = options.pictureSelType;
      }
      options.pictureDeriv = typeSave;
      typeMap = typeSave;
      options.pictureMap = typeMap;
      options.pictureDeriv = typeSave;
      jQuery.cookie('picture_deriv', typeSave, { path: COOKIE_PATH });

      url_old = jQuery("#theMainImage").attr("src");
      if (url != url_old) {
        jQuery("#theMainImage").attr("src", url);
      }
      jQuery('#derivativeSwitchBox .switchCheck').css('visibility', 'hidden');
      if (typeof type != "undefined" && (type == "Autosize" || type == "SelMaxi")) {
        jQuery('#derivativeChecked' + type).css('visibility', 'visible');
        jQuery.cookie('picture_sel_type', type, { path: COOKIE_PATH });
      } else {

        jQuery('#derivativeChecked' + typeSave).css('visibility', 'visible');
        jQuery.cookie('picture_sel_type', typeSave, { path: COOKIE_PATH });
      }

      // jQuery("#theMainImage," + theMainImage_id + ",.preload, .next1 , ")
      jQuery("#theMainImage").removeAttr("width height")
      .load(function (i) {
        if (!init_img(this)) {
          return;
        }
        //=======================================================================    

      })
      .error(function (e) {
        imgsrc = this.src;
        if (!this.complete) {
          // le fichier n'est pas present 
          imgsrc = jQuery(this).attr("src");
          return false;
        }

      })
           .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;

         })
         .live("change", function (e) {
           theMainImage_st = this.complete;
           imgsrc = this.src;
         })
            .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;
              }
              if (data.src) { }
              if (options.pictureDeriv == "Original" && data.src.match(RegExp("\-.." + ".jpg", "gi"))) {
                //    Autosize_resize(true, options);
              } else if (data.src.match(RegExp(options.pictureDeriv.substr(0, 2) + ".jpg", "gi"))) {
                //    Autosize_resize(true, options);
              } else {

              }

            });
      //_________ theMainImage  ___________

    }

    //__________________ 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');
      Autosize_resize(true, options);
    });

    //===============================================
    // jQuery("#theImage").trigger("Start_right");
    //===============================================
    jQuery("#theImage").live('Start_right', function (e) {
      if (typeof Zone_image == "undefined") return
      test_w = window.myPamoorama.autoSlideFx.to;
      test_w = window.myPamoorama.autoScrollFx.to;
      nf = jQuery("#pamoorama_thumb").height();
      jQuery("#pamoorama_thumb img").width(200);
      jQuery("#pamoorama_thumb img").height(nf);
      // 200=window.myPamoorama.imageWidth 
      // frame = Zone_image.container.width
      nw = (200 * Zone_image.image.width) / window.myPamoorama.imageWidth;
      jQuery("#pamoorama_frame").width(nw);
    });
    //===============================================
    // jQuery("#theImage").trigger("Start_left");
    //===============================================
    jQuery("#theImage").live('Start_left', function (e) {
      if (typeof Zone_image == "undefined") return
      jQuery("#theImage").show(0);
      window.myPamoorama.autoSlideFx.to = 0;
      test_w = window.myPamoorama.autoSlideFx.to;
      test_w = window.myPamoorama.autoScrollFx.to;
      nf = jQuery("#pamoorama_thumb").height();
      jQuery("#pamoorama_thumb img").width(200);
      jQuery("#pamoorama_thumb img").height(nf);
    });

    /************************************
    * Wait_pamoorama
    ************************************/
    Wait_pamoorama = function () {
      if (Type_Img != "pamoorama") return;
      tempo = 0;
      Wait_pamoorama_st = false;


      while (Wait_pamoorama_st == false) {
        Wait_pamoorama_st = Wait_pamoorama_time();
        jQuery.noop();
      }
      tempo = 0;
      if (nopano) {
        if (window.myPamoorama.options.autoscrollOnLoad) {
          window.myPamoorama.startAnimRight();
          jQuery.delay(100);
        }



      }

    }
    //__________________ Wait_pamoorama ______________________
    jQuery(".pwg-icon-clock-minus, .pwg-icon-clock-plus").click(function (i) {

    }).mouseover(function (i) {

    });

    Wait_pamoorama_time = function () {
      if (nopano == true) return true;
      if (jQuery("#pamoorama").length) {
        tempo = tempo + 1;

        mypanorama = window.myPamoorama;
        if (!mypanorama) {
          if (tempo > 500) return true;
          setTimeout("Wait_pamoorama_time()", 500);
          return false;

        }

        if (mypanorama.skipInit == false) {
          if (tempo > 500) return true;
          setTimeout("Wait_pamoorama_time()", 500);
          return false;
        }
        //=============================================================
        if (Math.abs(mypanorama.imageHeight) < 100) {
          setTimeout("Wait_pamoorama_time()", 500);
          return false;
        }

        if (jQuery(".infos").length > 0) {
          jQuery(".infos").empty();
          jQuery(".infos").hide();
        }

        nopano = true;

        Zone_image = { image_init: { width: mypanorama.imageWidth,
          height: mypanorama.imageHeight
        }
        }
        jQuery("#pamoorama").trigger("ON");
        return true;

      }
    }
    //__________________ Wait_pamoorama time______________________

    /**********************
    *
    ***********************/
    Wait_Affichage = function () {
      Wait_Affichage_st = false;
      while (Wait_Affichage_st == false) {
        jQuery.noop();
        Wait_Affichage_st = Wait_Affichage_time();
      }
    }
    //__________________ Wait_Affichage ______________________


    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")
        stb.stop().fadeTo(3500, 0);
      if (typeof theMainImage_id == "undefined") return true;

      if (theMainImage_id.selector) {
        theMainImage_id = theMainImage_id.selector;
      }
      if (theMainImage_id == null) return;

      if (jQuery(theMainImage_id).length == 0) {
        if (jQuery("#pamoorama_inner").length > 0) {
          return true;
        }
        //=== attente Image chargée ===
        if (tempo > 100) return true;
        tempo++;
        setTimeout("Wait_Affichage_time()", 500);
        return false;

      } else {

        img_h = jQuery(theMainImage_id).height();
        img_w = jQuery(theMainImage_id).width();

        if (typeof infos_theImage == "undefined") return;
        jQuery("#ret_autosize").trigger('ON', {
          width: img_w,
          height: img_h,
          theImage: theMainImage_id,
          img_src: infos_theMainImage.src,
          window_height: infos_theImage.height,
          window_width: infos_theImage.width
        });
      }
      return true;
    }
    //______________ Wait_affichage ______


    /***********************
    *
    **********************/
    init_img = function (theImg) {
      if (theImg.complete == false) {
        return;
      }
      name_src = theImg.src;
      img_init = { width: jQuery(theImg).width(), height: jQuery(theImg).height() }

      if (typeof theImg.naturalWidth != "undefined")
        img_init.width = theImg.naturalWidth;
      if (typeof theImg.naturalHeight != "undefined")
        img_init.height = theImg.naturalHeight;
      img_init.rapport = img_init.width / img_init.height;
      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.height = 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;

      if (typeof Zone_image.src == "undefined") {
        Zone_image.src = name_src;
        return false;
      }
      stx = name_src.match(RegExp(Zone_image.src, "gi"));
      return stx;
    }
    //___________ init_img _______



    //===========================================
    //
    //===========================================
    Set_Map = function (nds) {
      p0 = jQuery("#map").offset();
      if (!p0) return;
      infos_mapPicture = jQuery("#mapPicture").infos({ absolute: true });
      infos_theImage = jQuery("#theImage").infos({ absolute: true });
      jQuery("#map").removeAttr("height");
      jQuery("#map").removeAttr("width");
      jQuery("#map").width(infos_theImage.width - (infos_mapPicture.width));
      jQuery("#map").height(jQuery(window).height() - infos_theImage.top - infos_theImage.general.marges.height);
      return true;
    }

    jQuery("map [name='#Autosize'] area").mouseover(function (e) {
      return;
    });
    //___ Set_Map ___

    //=====================================
    //
    //=====================================
    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;
          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;
            return false
          }

          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) {
                maxi_size = size_derive;
                maxi_size.idx = n;
                if (options.pictureSelType == "SelMaxi" || options.pictureSelType == "Autosize")
                  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.pictureSelType.match(RegExp("SelMaxi", "gi"))) {
          n = mini_size.idx;

        }
        if (options.pictureSelType.match(RegExp("Autosize", "gi"))) {

        }

        pictureDeriv = pt[n][0];
        last_id = pt[n][0];
        jQuery(".switchCheck").each(function (i) {

          if (!this.id.match(RegExp("Original", "gi"))) {
            if (this.id.match(RegExp("SelMaxi", "gi"))) return false;
            last_id = this.id.replace("derivativeChecked", "");
          }
          if (last_id == pictureDeriv)
            return false;
        });

        options.pictureDeriv = last_id;

        return { url: pt[n][1], pictureDeriv: last_id, pictureMap: last_id, width: pt[n][2], height: pt[n][3] };
      }
      return { imgSrc: "", pictureDeriv: "", width: "", height: "" };
    }
    //_______________ Get_Maxi ______

    /********************
    *
    ********************/
    Select_Image = function () {
      var pt = options.liste_type;


      if (pt.length > 0) {
        //===== calcul Image ===
        if (typeof imageInfos_id == "undefined") return;
        Calcul_Image();
        options.theImageMargeZone = Zone_image.marges;
        if (Type_Img != 'charlie') {
          IMg = Get_Maxi(Zone_image.image);
          imgSrc = IMg.url;
          if (options.imgSrc.match(RegExp(imgSrc, "gi")))
            options.imgSrc = imgSrc;

          img_width = IMg.width;
          img_height = IMg.height;

          Zone_image.image_init = { height: IMg.height,
            width: IMg.width,
            rapport: IMg.width / IMg.height

          };
          if (typeof Zone_image.image == "undefined")
            Zone_image.image = { height: IMg.height,
              width: IMg.width,
              rapport: IMg.width / IMg.height

            };
        } else {
          return;
        }
        Zone_image.zoom = Zone_image.image.height / Zone_image.image_init.height;
        if (typeof Zone_image.src == "undefined") Zone_image.src = " ";

        identique = Zone_image.src.match(RegExp(imgSrc, "gi"));
        if (identique) return;
        href_path = get_href(IMg.pictureDeriv);
        jQuery(".linkAutosize").attr("href", "javascript:" + href_path);
        theImg = document.getElementById(theMainImage_id.replace("#", ""));

        if ((theImg == null) || theImg.tagName != "IMG") {
          imgSrc_i = jQuery(theImg).css("backgroundImage");
          imgSrc_j = jQuery(theImg).css("background-image");
          return;
        } else {
          last_id = IMg.pictureDeriv;
          eval(href_path);
          // changeImgSrc(imgSrc.replace("./",""), last_id, IMg.pictureMap, options.pictureSelType);
        }

        theImg.useMap = "#map" + IMg.pictureMap;
        return true;


        theImg = document.getElementById(theMainImage_id.replace("#", ""));
        if (init_img(theImg)) {

          return true;
        }
        return false;

      } else {


        return false;
      }


    };  //_______________ Select_Image ______

    get_href = function (NewpictureDeriv) {
      ref = path_names[0];
      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") {
            ref = href.replace("')", "','" + options.pictureSelType + "')");
          } else {
            ref = href;
          }
          break;
        }

      }


      return ref;
    };

    /*************************************************
    * correction pamoorama
    *************************************************/

    Set_Pamoorama = function (Format) {
      myPamoorama = window.myPamoorama;
      if (Type_Img == "pamoorama") {

        if (!nopano) {
          theMainImage_Id = "#pamoorama";
          nopano = false;
          Wait_pamoorama();
          infos_theMainImage = jQuery(theMainImage_Id).infos();
          //theMainImage_Id = "#pamoorama";
        }


        if (typeof myPamoorama == "undefined") {
          return;
        }
        //=========================================================  
        if (!nopano) {
          //theMainImage_Id = "#pamoorama";
          nopano = false;
          Wait_pamoorama();
          infos_theMainImage = jQuery(theMainImage_Id).infos();
          //theMainImage_Id = "#pamoorama";
        }


        infos_pamoorama_outter = jQuery("#pamoorama_outter").infos({ absolute: true });
        infos_pamoorama_inner = jQuery("#pamoorama_inner").infos({ absolute: true });
        infos_pamoorama_frame = jQuery("#pamoorama_frame").infos({ absolute: true });
        infos_frame = jQuery(myPamoorama.frame).infos({ absolute: true });


        //====================================================
        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;
        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%"
        });
        //---------- test largeur image 
        new_width = Format.width - (options.marge_right + options.marge_left);

        if (new_width > new_image.width) {
          new_width = new_image.width;
          jQuery("#pamoorama_outter").css({

            align: "center",
            margin: "0"
          });
        }
        outter_width = new_width;

        jQuery("#pamoorama_outter").css({
          align: 'center',
          margin: 'auto',
          width: outter_width + "px",
          height: Format.height - marges_h + "px"
        });
        //============= Mise à l'echelle ==================
        window.myPamoorama.options.width = Math.ceil(Format.width);
        //==================================================================
        new_max_left = new_image.width - outter_width;
        if (!window.myPamoorama.outter) return;
        window.myPamoorama.outter.scrollTo(new_max_left, 0);

        if (typeof window.myPamoorama.autoScrollFx != "undefined") window.myPamoorama.autoScrollFx.to = new Array(new_max_left, 0);
        window.myPamoorama.ratio = Math.ceil(new_image.width / 200);
        window.myPamoorama.imageWidth = new_image.width;
        window.myPamoorama.imageHeight = new_image.height;
        nf = jQuery("#pamoorama_thumb").height();
        jQuery("#pamoorama_thumb img").width(180);
        jQuery("#pamoorama_thumb img").height(nf);

        jQuery("#pamoorama_thumb").css({
          /*   position: "absolute", */
          left: (Format.width - 215) + "px"

        });
        jQuery("#pamoorama_thumb img").css({

        });
        // 200=window.myPamoorama.width 
        // frame = Zone_image.container.width

        nw = (window.myPamoorama.image.width * Format.width) / window.myPamoorama.imageWidth;
        jQuery("#pamoorama_frame").width(nw);


      } //  
    } // Set_Pamoorama

    /*********************************************************/

    Toggle_bp = function () {
      options.cl_visible = !options.cl_visible;
      Autosize_resize();
      Wait_Affichage();

    }

    //====================================
    // 
    //====================================
    Calcul_Image = function () {

      /****************************************/
      if (typeof imageInfos_id == "undefined") return;
      infos_imageInfos = jQuery(imageInfos_id).infos({ absolute: true });             // information
      infos_theMainImage = jQuery(theMainImage_id).infos({ absolute: true });         // Image   
      // commentContent
      // copyright 

      if (options.slideshow) {


      } else {

      }


      pos_top = options.pos_top;
      //    pos_top = infos_theImage.top;

      pos = jQuery(theImage_id).offset();
      infos_theImage = jQuery(theImage_id).infos(true);   // container 
      infos_window = jQuery(window).infos(true);   // window
      w = infos_theImage.general.marges.width

      container = {
        height: infos_window.height - options.theImageTop,
        width: infos_window.width - options.theImageLeft - options.theImageRight
      }
      marge_left = options.marge_left | 0;
      marge_right = options.marge_right | 0;
      marge_top = options.marge_top | 0;


      //==========================================================
      if (test_theme("stripped")) {
        infos_the_page.margin.left = 20;  //taille fleche
        infos_the_page.margin.right = 20;

      } else if (test_theme("kardon")) {

      } else if (test_theme("elegant")) {

        if (infos_imageInfos.visible == true) {
          //  marge_right += infos_imageInfos.general.width; ;

        } else {
          marge_right += 0;

        }
        marge_right += 1;
        marge_left += 1;

      } else if (test_theme("stripped")) {

      } else if (test_theme("simple")) {
        infos_menubar = jQuery("#menubar").infos({ absolute: true });
        infos_imageInfoBar = jQuery("#imageInfoBar").infos({ absolute: true });

        jQuery("#theImage").width(infos_imageInfoBar.left - infos_theImage.left - 2);
        marge_left += 0;
        marge_right += 0;

      } else if (test_theme("OS")) {

      } else if (test_theme("pur")) {
        marge_right += 0;
        // marge_right += 25;
      } else if (test_theme("mont")) {
        marge_right += 0;

        // marge_right += 25;


      } else {



      }


      retrait_img = {};
      //========== Format Image ==============  
      retrait_img.height = Math.ceil(options.marges_llgbo || 0)
      + Math.ceil(infos_theMainImage.general.marges.height) +
      +Math.ceil(options.marges_llgbo || 0);
      retrait_img.height += 2;


      //===============================================================
      retrait_img.width = Math.ceil(infos_theMainImage.general.marges.width); // borderwidth+padding
      retrait_img.width = Math.ceil(infos_theImage.general.marges.width); // borderwidth+padding
      retrait_img.width += Math.ceil(options.marges_llgbo || 0);
      retrait_img.width += 2;
      if (!options.check_desc_v)
        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;
      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)
      }
      //=========================
      // test débordement
      //=========================
      height_theMainImage = Math.ceil(image_max.height);
      width_theMainImage = Math.ceil(image_max.width);

      if (typeof Zone_image.image_init.rapport == "undefined") {
        Zone_image.image_init.rapport = options.ratio;
      }
      if (Type_Img == "charlie") {
        width_theMainImage = height_theMainImage * options.ratio;
        Zone_image.image_init.rapport = options.ratio;

      } else if (Type_Img == "pamoorama") {
        if (height_theMainImage > container.height_interne) {
          n = options.pictureSelType;
        }
      } else {

        height_theMainImage = Math.ceil(width_theMainImage / options.ratio);



        if (height_theMainImage > container.height_interne) {
          image_max.height = container.height_interne;
          image_max.width = image_max.height * Zone_image.image_init.rapport;
          width_theMainImage = Math.ceil(image_max.width);
          height_theMainImage = Math.ceil(image_max.height);
        }
        if (width_theMainImage > container.width_interne) {
          image_max.width = container.width_interne;
          image_max.height = image_max.width / Zone_image.image_init.rapport;
          width_theMainImage = Math.ceil(image_max.width);
          height_theMainImage = Math.ceil(image_max.height);

        } else if (width_theMainImage > container.width) {

        } else {

        }
      }
      //=================================================================
      Zone_image.image = {
        width: width_theMainImage,
        height: height_theMainImage,
        rapport: width_theMainImage / height_theMainImage
      };
      Zone_image.marges = { width: marge_left + marge_right + retrait_img.width,
        height: marge_top + marge_bottom + retrait_img.height
      }
      Zone_image.src = jQuery(theMainImage_id).attr("src");
    }

    /*********************************************
    * Calcul les dimensions.
    *********************************************/
    Get_dimensions = function (force, parametres) {
      new_img = jQuery(theMainImage_id).infos({ absolute: true });
      new_dim = jQuery(theImage_id).infos({ absolute: true });
      new_win = jQuery(window).infos({ absolute: true }); // avec ascenseur    
      options.theImageTop = new_dim.top;
      options.theImageLeft = new_dim.left;
      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") { }
      new_dim.out.bottom = new_win.height - options.marge_bottom_2;

      options.theImageBottom = new_win.height - new_dim.out.bottom;
      if (options.slideshow) {
        options.marge_top = 0;
      } else {
        options.marge_top_2 = Math.ceil(new_img.top - new_dim.top) + options.marge_top;
      }

      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;

      if (Type_Img != "map" && Type_Img != "iframe")
        Select_Image();
      infos_theMainImage = jQuery(theMainImage_id).infos({ absolute: true });
      Zone_image.src = infos_theMainImage.src;
      useMap = options.pictureSelType;
      //=================================================================
      switch (Type_Img) {
        case "map":
          if (Set_Map(true)) return false;
          break
        case "panorama":
          if (!theMainImage_id) {

          }
          infos_theImage = jQuery(theMainImage_id).infos();
          infos_the_page = jQuery("#the_page").infos();
          img_finale.height = infos_theImage.height;
          break
        case "img":





          break
        case "img_autre":
          if (!theMainImage_id) {
            if (DEBUG_autosize.match("true", "gi")) alert("The_MainImage=null");
            return;

          }

          infos_the_page = jQuery("#the_page").infos();


          break
        case "embed":
          //
          if (infos_theMainImage.width == 0)
            infos_theMainImage = jQuery("#thePicturePage").infos();
          if (infos_theMainImage.width == 0)
            infos_theMainImage = jQuery("#the_page").infos();


          iph1 = jQuery("#theImage div").infos();

          break
        case "charlie":

          Zone_image.zoom = 1;

          break

        case "iframe":
          wpng = 0;
          Zone_image.image.width = options.theImageWidth;
          Zone_image.image.height = options.theImageHeight;
          Zone_image.zoom = 1;
          break
        case "pamoorama":
          Wait_pamoorama();
          break
      }



      //=================================================
      if (Zone_image.image.height < options.mini_height2) {
        Zone_image.image.height = parseInt(options.mini_height2);
        Zone_image.image.width = Math.ceil(Zone_image.image.height * Zone_image.image_init.rapport);
      }
      if (Zone_image.image.width < options.mini_width2) {
        Zone_image.image.width = parseInt(options.mini_width2);
        Zone_image.image.height = Math.ceil(Zone_image.image.width / Zone_image.image_init.rapport);
      }
      //==================================================
      //   ImageWidthidth largeur à atteindre
      //   Calcul du rapport d'agrandissement

      echelle_max = parseFloat(options.echelle_max, '3');
      if (Zone_image.zoom > echelle_max) {
        Zone_image.zoom = echelle_max;
        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.image_init.width / Zone_image.image_init.rapport);
      }
      if (Type_Img != "pamoorama") {
        mxi = Math.ceil(Zone_image.image.height + Zone_image.marges.height);
        Zone_image.container.height = Math.max(Zone_image.container.height, mxi);
      }
      img_finale = { width: Zone_image.image.width, height: Zone_image.image.height };
      return true;
    }
    //________________ Get_dimensions ___________________


    /*****************************
    *  init_gen
    *****************************/
    init_gen = function (e) {
      theImg = document.getElementById(theMainImage_id.replace("#", ""));
      //==================================================
      marges_llgbo = 0;
      options.marges_llgbo = 0;
      if (jQuery(llgbo_id).length > 0) {
        infos_llgbo = jQuery(llgbo_id).infos(true);
        if (infos_llgbo.visible == true) {
          if (infos_llgbo.height > 0) {
            infos_llgboframe1 = jQuery(llgbo_id + " div:last").infos();
            infos_llgboframe31 = jQuery(llgbo_id + "  div:first").infos();
            //=============================================
            ll2 = infos_llgboframe1.width; // llgboframe1
            ll1 = infos_llgboframe31.general.width; // llgboframe31
            options.marges_llgbo = (ll1 - ll2);
            infos_llgboh2 = jQuery("#llgboh2").infos();
          }
        }

        marges_llgbo = options.marges_llgbo;
      }

      //========= Récupération des informations =============  

      options.marge_top = 0;
      pAll = jQuery(llgbo_id).absoluteAll({ absolute: true });
      infos_llgbo.top = pAll.Top;
      infos_llgbo.bottom = pAll.Bottom;
      pAll = jQuery(theMainImage_id).absoluteAll({ absolute: true });
      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);

      } else {
        pos_top = infos_theImageAndInfos.top;
        options.marge_bottom = Math.ceil(options.marge_basse);
      }

      options.pos_top = pos_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);
      options.marge_top += infos_theImage.general.marges.top + infos_content.general.marges.top + Math.ceil(options.marge_haute);

      if (options.pictureDeriv == null)
        options.first = true;
      else
        options.first = false;
      //=================== Gestion liste photos size ============================
      us = 0;
      if (!options.theMainImageWidth) options.theMainImageWidth = options.scaledWidth;
      if (!options.theMainImageHeight) options.theMainImageHeight = options.scaledHeight;

      if (options.first) {
        if (options.pictureDeriv) {

          pictureSelType = options.pictureSelType;
          options.pictureMap = options.pictureDeriv;

        } else {
          IMg = Get_Maxi(Zone_image.image);
          options.pictureDeriv = IMg.pictureDeriv;
          imgSrc = IMg.url;
          width = IMg.width;
          height = IMg.height;
          options.pictureDeriv = IMg.pictureDeriv;
          options.pictureMap = IMg.pictureMap;
        }
      }
      if (pictureSelType_user != options.pictureSelType) {
        /*
        user_status = options.user_status;
        pictureSelType_user = eval("options." + user_status + "_type"); //limite taille
        */
        pictureDeriv_user = options.pictureDeriv;
        options.pictureDeriv_user = pictureDeriv_user;
        pictureSelType = options.pictureSelType;
      }
      Affiche_limite(pictureSelType_user);

      //=================== 2==================================
      sav_p = options.pictureSelType;
      options.pictureSelType = "SelMaxi";
      href_path = get_href(options.pictureDeriv);
      spans = jQuery("#derivativeCheckedSelMaxi").next();
      spans.attr("href", "javascript:" + href_path);
      spans.attr("name", "SelMaxi");
      spans = spans.find("span");
      spans.attr("name", "SelMaxi");
      spans.text("(" + options.theMainImageWidth + " x " + options.theMainImageHeight + ")");
      //==========================================================
      options.pictureSelType = "Autosize";
      href_path = get_href(options.pictureDeriv);
      spans = jQuery("#derivativeCheckedAutosize").next();
      spans.attr("href", "javascript:" + href_path);
      spans.attr("name", "Autosize");
      spans = spans.find("span");
      spans.attr("name", "Autosize");
      spans.text("(" + options.theMainImageWidth + " x " + options.theMainImageHeight + ")");
      //==========================================================
      options.pictureSelType = sav_p;
      jQuery('#derivativeSwitchBox .switchCheck').css('visibility', 'hidden');
      if (options.pictureSelType == "Autosize" || options.pictureSelType == "SelMaxi") {
        //  jQuery('#derivativeChecked' + options.pictureSelType).css('visibility', 'visible');
        spans = jQuery("#derivativeChecked" + options.pictureSelType).next();
        spans.addClass("linkAutosize");
        spans.find("span").addClass("auto_details");
      } else {
        //  jQuery('#derivativeChecked' + options.pictureDeriv).css('visibility', 'visible');
      }
      pictureDeriv = options.pictureDeriv;
      Autosize_resize(true, options);
      Autosize_resize(true, options);
      jQuery("#" + Type_Img).show(options.fade_in);
    };
    //_______________________ init_gen _______________________


    /*********************************************
    * DEBUG ....
    *********************************************/
    /*
    if (DEBUG_autosize.match("true",gi))   {
    for (var i = 0; i < 10; i++) {
    jQuery('#adddebugs').click();
    }
    jQuery(jQuery('.debug').get(i - 1)).click();
    }
    */

    // 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');
    });



    if (DEBUG_autosize.match("mouse", "gi")) {
      var mouseLocation = new Point(-500, -500);
      function Point(x, y) {
        this.x = x; this.y = y;
      }
      register_position();

      function register_position() {
        mouse_x = 0;
        mouse_y = 0;
        //  document.onmousemove = position;

      }

      function position(evt) {
        if (!evt) evt = window.event;
        mouseLocation.x = evt.clientX;
        mouseLocation.y = evt.clientY;
      }

      jQuery("div,a,img").mousemove(function (evt) {

        if (!evt) evt = window.event;
        mouseLocation.x = evt.clientX;
        mouseLocation.y = evt.clientY;
        Context = jQuery(this).context.nodeName;
        obj_id = "#" + this.id.toString();
        infos_g = jQuery(obj_id).infos(true);
        infos_g.top = jQuery(obj_id).absoluteTop();
        wg = jQuery("body").width() - infos_g.right;

        affiche_debug({

          Debug1: Debug_info(1, "x:" + mouseLocation.x
    + " y: " + mouseLocation.y
    + " id: " + obj_id
    + " top: " + infos_g.top,
    +" Node: " + Context
    , "->")
    ,
          Debug2: Debug_info(2, "W:" + infos_g.general.width
    + " H: " + infos_g.general.height
    + " right: " + (wg)
    + " left: " + infos_g.left
    + " Node: " + Context
    , "->")
        });

      });

    }


    //=======================================================================================
    Debug_info = function (index, infos, Nom_str) {
      if (typeof infos == "undefined") return;
      width_g = Math.ceil(jQuery("body").width() / 5) - 10;
      if (typeof infos.height != "undefined") {
        message = " -- > Info : " + Nom_str + " " + infos.id + "\n" +
                         "Info nodeName: " + infos.nodeName + "\n" +
                         "Info width: " + infos.width + "\n" +
                         "Info height: " + infos.height + "\n" +
                         "Info top: " + infos.top + "\n" +
                         "Info left: " + infos.left + "\n" +
                         "Info position: " + infos.position + "\n";

        myDebug = { id: "Debug" + index, texte: message,
          css: {
            color: "black",
            opacity: "1",
            position: "absolute",
            height: infos.height || pos_top - 30 + "px",
            width: infos.width || width_g + "px",
            left: infos.left || 0 + "px",
            border: "solid 1px green",
            top: infos.top + "px"
          }
        }
        return myDebug;

      } else {
        if (typeof old_messages == "undefined") {
          old_messages = new Array();

        }
        if (infos != "" && infos != "undefined") {
          nc0 = old_messages[index] || "";
          if (typeof nc0 != "undefined") {
            nc0 = nc0.toString().split("<br />");
            if (nc0.length > 4) nc0.shift();
            old_messages[index] = nc0.join("<br />");
          }
          old_messages[index] += "" + Nom_str + "->" + infos + "<br />";
          message = old_messages[index];
          colors = Array('black', 'white', 'white', 'white', 'white', 'white', 'red');
          myDebug = { id: "Debug" + index, texte: message,
            css: { display: "block",
              color: colors[index - 1],
              opacity: "1",
              position: "absolute",
              align: "left",
              height: 80 + "px",
              width: width_g + "px",
              left: ((index - 1) * width_g) + "px",
              border: "solid 1px green",
              top: 0 + "px"
            }
          }
          return myDebug;
        }
      }


    } //Debug_info
    //====================================================
    affiche_debug = function (aff_infos) {
      jQuery(jQuery("[id ^='Debug']")).each(function (i) {
        if (aff_infos[this.id]) {
          if (aff_infos[this.id].css) {
            jQuery("#" + this.id).css(aff_infos[this.id].css);
            jQuery("#" + this.id).html(aff_infos[this.id].texte);
          }
        }
      });
      return;
    }
    //___________ affiche_debug ____
    //====================================================
    function Debug_pos() {
      return;
      if (DEBUG_autosize.match("true", gi)) {

        jQuery("[id ^='Debug']").show();
        /*
        Debug2  background-color:yellow
        Debug3 background-color:blue
        Debug4 background-color:green
        Debug5 background-color:red

        */

        affiche_debug({
          Debug5: Debug_info(5, infos_theMainImage, "infos_theMainImage")
        });
      }
    } // Debug_pos
    //==========================================================









  });                                                                                                                // ready



  jQuery("#derivativeSwitchBox a").click(function (e) {
    k1 = 0;
  });