!function(e){e.fn.image_compare=function(a){a=e.extend({default_offset_pct:.5,orientation:"horizontal",before_label:"Before",after_label:"After",no_overlay:!1,move_slider_on_hover:!1,move_with_handle_only:!0,click_to_move:!1},a);return this.each(function(){var t=a.default_offset_pct,i=e(this),o=a.orientation,n="vertical"===o?"down":"left",r="vertical"===o?"up":"right";if(i.wrap("<div class='image-compare-wrapper image-compare-"+o+"'></div>"),!a.no_overlay){i.append("<div class='image-compare-overlay'></div>");var c=i.find(".image-compare-overlay");c.append("<div class='image-compare-before-label' data-content='"+a.before_label+"'></div>"),c.append("<div class='image-compare-after-label' data-content='"+a.after_label+"'></div>")}var s=i.find("img:first"),l=i.find("img:last");i.append("<div class='image-compare-handle'></div>");var d=i.find(".image-compare-handle");d.append("<span class='image-compare-"+n+"-arrow'></span>"),d.append("<span class='image-compare-"+r+"-arrow'></span>"),i.addClass("image-compare-container"),s.addClass("image-compare-before"),l.addClass("image-compare-after");var p=function(e){var a,t,n,r=(a=e,t=s.width(),n=s.height(),{w:t+"px",h:n+"px",cw:a*t+"px",ch:a*n+"px"});d.css("vertical"===o?"top":"left","vertical"===o?r.ch:r.cw),function(e){"vertical"===o?(s.css("clip","rect(0,"+e.w+","+e.ch+",0)"),l.css("clip","rect("+e.ch+","+e.w+","+e.h+",0)")):(s.css("clip","rect(0,"+e.cw+","+e.h+",0)"),l.css("clip","rect(0,"+e.w+","+e.h+","+e.cw+")")),i.css("height",e.h)}(r)},f=function(e,a){var t,i,n;return t="vertical"===o?(a-v)/g:(e-m)/h,i=0,n=1,Math.max(i,Math.min(n,t))};e(window).on("resize.image_compare",function(e){p(t)});var m=0,v=0,h=0,g=0,_=function(e){(e.distX>e.distY&&e.distX<-e.distY||e.distX<e.distY&&e.distX>-e.distY)&&"vertical"!==o?e.preventDefault():(e.distX<e.distY&&e.distX<-e.distY||e.distX>e.distY&&e.distX>-e.distY)&&"vertical"===o&&e.preventDefault(),i.addClass("active"),m=i.offset().left,v=i.offset().top,h=s.width(),g=s.height()},u=function(e){i.hasClass("active")&&(t=f(e.pageX,e.pageY),p(t))},w=function(){i.removeClass("active")},b=a.move_with_handle_only?d:i;b.on("movestart",_),b.on("move",u),b.on("moveend",w),a.move_slider_on_hover&&(i.on("mouseenter",_),i.on("mousemove",u),i.on("mouseleave",w)),d.on("touchmove",function(e){e.preventDefault()}),i.find("img").on("mousedown",function(e){e.preventDefault()}),a.click_to_move&&i.on("click",function(e){m=i.offset().left,v=i.offset().top,h=s.width(),g=s.height(),t=f(e.pageX,e.pageY),p(t)}),e(window).trigger("resize.image_compare")})}}(jQuery);