!function(t) {
  function e() {
    var t, e = this.parentNode, o = arguments.length;
    if (e) for (o || e.removeChild(this); o--;) 'object' != typeof (t = arguments[o]) ? t = this.ownerDocument.createTextNode(t) : t.parentNode && t.parentNode.removeChild(t), o ? e.insertBefore(t, this.previousSibling) : e.replaceChild(t, this);
  }
  Element.prototype.replaceWith || (Element.prototype.replaceWith = e), CharacterData.prototype.replaceWith || (CharacterData.prototype.replaceWith = e), DocumentType.prototype.replaceWith || (DocumentType.prototype.replaceWith = e);
  const o = {};
  t.fn.imageZoom = function(e) {
    let i = t.extend({
      zoom: 225,
    }, e);

    if ($( window ).width() < 768) {
        i.zoom = 350;
    }else{
        i.zoom = 225;
    }

    var loadImage = 'https://img.edel-optics.com/frontend/Spinner@1x-1.0s-200px-200px.svg';
    $('#containerZoom').css('background-size', '64px 64px');
    $('#containerZoom').css('background-image', `url(${loadImage})`);
    $('#imageZoom').attr('src', loadImage);

    document.zoom = this;
    document.zoom_setting = i;

    function r(e) {
      let o, i, r, a, n = e.currentTarget;
      try {
          r = e.offsetX ? e.offsetX : e.touches[0].pageX, a = e.offsetY ? e.offsetY : e.touches[0].pageX, o = r / n.offsetWidth * 100, i = a / n.offsetHeight * 100, t(n).css({
              'background-position': `${o}% ${i}%`,
          });
      }catch (e) {

          /* @todo mitte setzen */
          t(n).css({
              'background-position': '50% 50%',
          });

      }
    }

    o.template = `\n\t\t\t<figure class="containerZoom" id="containerZoom" style="background-image:url(${this.attr('src')}); background-size: ${i.zoom}%;">\n\t\t\t\t<img id="imageZoom" src="${this.attr('src')}" alt="${this.attr('alt')}" />\n\t\t\t</figure>\n\t\t`;
    let a = t(this).replaceWith(o.template);
    var n;

    return n = t('.containerZoom')[t('.containerZoom').length - 1], (n = t(n)).on('click', function(e) {
          console.log('on click touchstart called', e);
          console.log('settings bigImageSrc', i.bigImageSrc);

          var img = new Image();
          img.src = i.bigImageSrc + '?imgeng=/pass_true';
          img.onload = function() {
              console.log('img.onload called');
              $('#imageZoom').attr('src', img.src);

              $('#containerZoom').css('background-image', `url(${img.src})`);
              if(img.src.includes('-d')){
                      i.zoom = 370;
              }else{
                if ($( window ).width() < 768) {
                      i.zoom = 350;
                  }else{
                      i.zoom = 225;
                  }
              }

              $('#containerZoom').css('background-size', `${i.zoom}%`);
        };

        'zoom' in o == 0 && (o.zoom = !1), o.zoom ? (o.zoom = !1, t(this).removeClass('active')) : (o.zoom = !0, t(this).addClass('active'), r(e));

        if ('zoom' in o == 0 && (o.zoom = !1), o.zoom) {
            console.log('rein');
            $('.sbox22').hide();
            $('.sbox1').hide();
            $('.eoProductsDetailImageToolbarZoom').addClass('active');
        } else {
            console.log('raus');
            $('.sbox22').show();
            $('.sbox1').show();
            $('.eoProductsDetailImageToolbarZoom').removeClass('active');
        }
    }), n.on('mousemove', function(t) {
      console.log('mouse move called');
      o.zoom && r(t);
    }), n.on('mouseleave', function() {
      console.log('mouse leave called');
      o.zoom = !1, t(this).removeClass('active'); $('.eoProductsDetailImageToolbarZoom').removeClass('active');
    }), a;
  };
}(jQuery);
