(function(e) {
"use strict";
e.fn.pin = function(t) {
var n = 0,
r = [],
i = false,
s = e(window);
t = t || {};
var o = function() {
for(var n = 0, o = r.length; n < o; n++) {
var u = r[n];
if(t.minwidth && s.width() <= t.minwidth) {
if(u.parent().is(".pin-wrapper")) {
u.unwrap()
}
u.css({
width: "",
left: "",
top: "",
position: ""
});
if(t.activeclass) {
u.removeclass(t.activeclass)
}
i = true;
continue
} else {
i = false
}
var a = t.containerselector ? u.closest(t.containerselector) : e(document.body);
var f = u.offset();
var l = a.offset();
var c = u.offsetparent().offset();
if(!u.parent().is(".pin-wrapper")) {
u.wrap("
")
}
var h = e.extend({
top: 0,
bottom: 0
}, t.padding || {});
u.data("pin", {
pad: h,
from: (t.containerselector ? l.top : f.top) - h.top,
to: l.top + a.height() - u.outerheight() - h.bottom,
end: l.top + a.height(),
parenttop: c.top
});
u.css({
width: u.outerwidth()
});
u.parent().css("height", u.outerheight())
}
};
var u = function() {
if(i) {
return
}
n = s.scrolltop();
var o = [];
for(var u = 0, a = r.length; u < a; u++) {
var f = e(r[u]),
l = f.data("pin");
if(!l) {
continue
}
o.push(f);
var c = l.from - l.pad.bottom,
h = l.to - l.pad.top;
if(c + f.outerheight() > l.end) {
f.css("position", "");
continue
}
if(c < n && h > n) {
!(f.css("position") == "fixed") && f.css({
left: f.offset().left,
top: l.pad.top
}).css("position", "fixed");
if(t.activeclass) {
f.addclass(t.activeclass)
}
} else if(n >= h) {
f.css({
left: "",
top: h - l.parenttop + l.pad.top
}).css("position", "absolute");
if(t.activeclass) {
f.addclass(t.activeclass)
}
} else {
f.css({
position: "",
top: "",
left: ""
});
if(t.activeclass) {
f.removeclass(t.activeclass)
}
}
}
r = o
};
var a = function() {
o();
u()
};
this.each(function() {
var t = e(this),
n = e(this).data("pin") || {};
if(n && n.update) {
return
}
r.push(t);
e("img", this).one("load", o);
n.update = a;
e(this).data("pin", n)
});
s.scroll(u);
s.resize(function() {
o()
});
o();
s.load(a);
return this
}
})(jquery)