!(function (e) {
    "use strict";
    var t = function (e, t) {
        this.init("magnify", e, t);
    };
    t.prototype = {
        constructor: t,
        init: function (t, n, r) {
            var i = "mousemove",
                s = "mouseleave";
            this.type = t;
            this.$element = e(n);
            this.options = this.getOptions(r);
            this.nativeWidth = 0;
            this.nativeHeight = 0;
            this.$element.wrap('<div class="magnify" >');
            this.$element.parent(".magnify").append('<div class="magnify-large" >');
            this.$element.siblings(".magnify-large").css("background", "url('" + this.$element.attr("src") + "') no-repeat");
            this.$element.parent(".magnify").on(i + "." + this.type, e.proxy(this.check, this));
            this.$element.parent(".magnify").on(s + "." + this.type, e.proxy(this.check, this));
        },
        getOptions: function (t) {
            t = e.extend({}, e.fn[this.type].defaults, t, this.$element.data());
            t.delay && typeof t.delay == "number" && (t.delay = { show: t.delay, hide: t.delay });
            return t;
        },
        check: function (t) {
            var n = e(t.currentTarget),
                r = n.children("img"),
                i = n.children(".magnify-large");
            if (!this.nativeWidth && !this.nativeHeight) {
                var s = new Image();
                s.src = r.attr("src");
                this.nativeWidth = s.width;
                this.nativeHeight = s.height;
            } else {
                var o = n.offset(),
                    u = t.pageX - o.left,
                    a = t.pageY - o.top;
                u < n.width() && a < n.height() && u > 0 && a > 0 ? i.fadeIn(100) : i.fadeOut(100);
                if (i.is(":visible")) {
                    var f = Math.round((u / n.width()) * this.nativeWidth - i.width() / 2) * -1,
                        l = Math.round((a / n.height()) * this.nativeHeight - i.height() / 2) * -1,
                        c = f + "px " + l + "px",
                        h = u - i.width() / 2,
                        p = a - i.height() / 2;
                    i.css({ left: h, top: p, backgroundPosition: c });
                }
            }
        },
    };
    e.fn.magnify = function (n) {
        return this.each(function () {
            var r = e(this),
                i = r.data("magnify"),
                s = typeof n == "object" && n;
            i || r.data("tooltip", (i = new t(this, s)));
            typeof n == "string" && i[n]();
        });
    };
    e.fn.magnify.Constructor = t;
    e.fn.magnify.defaults = { delay: 0 };
    e(window).on("load", function () {
        e('[data-toggle="magnify"]').each(function () {
            var t = e(this);
            t.magnify();
        });
    });
})(window.jQuery);