$(document).ready(function() {
  // Galeries photo produits
  if ($("div.galerie").length) {
    $("div.galerie a").fancybox({
      overlayShow: true
      ,overlayOpacity: 0.75
/*      ,itemLoadCallback: function() {
        $("#fancy_img").noContext();
      }*/
    });
    // Sur l'image affichée, désactivation du click droit
    $("body").noContext();
  }
  // Présence internationale
  if ($("#presence-internationale").length) {
    var precedent = null;
    $("area").mouseover(
      function() {
        $(precedent).css("display", "none");
        $("#div-" + $(this).attr("id")).css("display", "block");
        $("#mappemonde-img").attr({src:"/design/fre/images/presence-internationale/" + $(this).attr("id") + ".png"});
        precedent = "#div-" + $(this).attr("id");
      }
    ).mouseout(
      function() {
        /*
        $("#div-" + $(this).attr("id")).css("display", "none");
        $("#mappemonde-img").attr({src:"/design/fre/images/presence-internationale/transparent.png"});
        */
      }
    );
  }
  // Carrières
  if ($("#carrieres").length) {
    $("a.ouvrir-annonce").click(
      function() {
        if (!$("div#progress").length) {
          $('<div id="progress"><img src="/design/fre/images/progress.gif"/></div>').appendTo("body");
        }
        $("div#annonce").fadeTo("normal", 0.33)
        // Centré sur la page
        //$("div#progress").css({"left": (($(window).width() - 40) / 2 + $(window).scrollLeft()), "top": (($(window).height() - 40) / 2 + $(window).scrollTop())}).show();
        // Centré sur la zone de contenu
        $("div#progress").css({"left": (($(window).width() - 40) / 2 + $(window).scrollLeft() + 95), "top": (($(window).height() - 40) / 2 + $(window).scrollTop())}).show();
        $("div#annonce").load(
          $(this).attr("href") + " div#contenu-annonce", function() {
            $("div#progress").hide();
            $("div#annonce").fadeTo("normal", 1);
          }
        );
        return false;
      }
    );
  }
  // Validation formulaire Postuler
  if ($("#candidatureForm").length) {
    $("#candidatureForm").validate();
  }
  // Menu horizontal produits
  if ($("#menu-produits").length) {
    $("#liste-produits").supermenu({
      selected: true,
      selectedClass: 'selected',
      oClass: '-horizontal'
    });
    $(".supermenu-horizontal").mousewheel(function(eventA, deltaA) {
        if (deltaA > 0) $("#liste-produits").trigger("left",[10]);
        else if (deltaA < 0) $("#liste-produits").trigger("right",[10]);
        eventA.stopPropagation();
        eventA.preventDefault();
    })
    /*MOUSEOVER & MOUSEOUT*/
    $("#scroll-g").bind("mouseover",function() {
      var offset_ = 2;
      this.interval_ = window.setInterval(function() {
        offset_ = (offset_) +(offset_-1);
        $("#liste-produits").trigger("left",[offset_]);
      },100);
    }).bind("mouseout",function() {
      window.clearInterval(this.interval_);
      this.offset_ = 0;
    });
    $("#scroll-d").bind("mouseover",function() {
      var offset_ = 2;
      this.interval_ = window.setInterval(function() {
        offset_ = (offset_) +(offset_-1);
        $("#liste-produits").trigger("right",[offset_]);
      },100);
    }).bind("mouseout",function() {
      window.clearInterval(this.interval_);
      this.offset_ = 0;
    });
  }

  // Outils / Club des distributeurs
  // http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
  if ($("#outils").length) {
    //var tooltipImage = new Image();
    $('a.tooltip').tooltip({
      delay: 250,
      showURL: false,
      bodyHandler: function() {
        return $("<img/>").attr("src", $(this).attr("rev"));
        //return '<img src="' + $(this).attr("rev")  + '"/>';
        //tooltipImage.src = $(this).attr("rev");
        //return tooltipImage;
      }
    });
  }
});

