/*! jQThumb V2.1.5 Copyright (c) 2013-2014 Dual licensed under the MIT and GPL licenses. Author : Pak Cheong Version : 2.1.5 Repo : https://github.com/pakcheong/jqthumb Demo : http://pakcheong.github.io/jqthumb/ Last Updated : Friday, September 26th, 2014, 4:19:54 PM Requirements : jQuery >=v1.3.0 or Zepto (with zepto-data plugin) >=v1.0.0 */ !function(a,b,c){function d(a,c){b.console&&"undefined"!=typeof a&&a&&"undefined"!=typeof c&&c&&(a=a.toLowerCase(),"error"==a?console.error(c):"log"==a?console.log(c):console.error('"'+a+'" is not supported as console type.'))}function e(a){return a.toString().match(/\d+/)[0]}function f(a,b){var c=a.toString().match(/(-*)+\d+/)[0];return"px"==g(a)?0>a?0:a>b?b:a:"%"==g(a)?0>c?"0%":c>100?"100%":a:void 0}function g(b){var c=b.toString().match(/\d+(.*)/i);if(c)switch(a.trim(c[1])){case"":return"px";case"px":return"px";case"%":return"%"}}function h(b,c){this.element=b,this.settings=a.extend({},n,c),this.settings.width=this.settings.width.toString().replace(/px/gi,""),this.settings.height=this.settings.height.toString().replace(/px/gi,""),this.settings.position.y=f(this.settings.position.y,this.settings.width),this.settings.position.x=f(this.settings.position.x,this.settings.height),this.settings.zoom=this.settings.zoom<0?0:this.settings.zoom,"string"==typeof c?"kill"==c.toLowerCase()&&this.kill(this.element):this.init()}var i=function(){{var a=c.createElement("div"),b="Khtml Ms O Moz Webkit".split(" ");b.length}return function(c){if(c in a.style)return!0;c=c.replace(/^[a-z]/,function(a){return a.toUpperCase()});for(var d in b)if(b[d]+c in a.style)return!0;return!1}}(),j="jqthumb",k=j+"-resize",l=j+"-original-styles",m={outputElems:[],inputElems:[]},n={classname:j,width:100,height:100,position:{x:"50%",y:"50%"},source:"src",responsive:20,zoom:1,show:!0,method:"auto",before:function(){},after:function(){},done:function(){}};h.prototype={init:function(){var a=this.settings.method.toLowerCase();"auto"==a?i("backgroundSize")===!1?this.native(this.element,this.settings):this.modern(this.element,this.settings):"modern"==a?this.modern(this.element,this.settings):"native"==a?this.native(this.element,this.settings):d("error",'Invalid method. Only "auto", "modern" and "native" are allowed.')},kill:function(c){var e=a(c);if(e.data(j)){var f=[],g=e.prev();if(g.data(j)!==j)return d("error","Could not find the element. It is probably due to one or more element has been added right before the image element after the plugin initialization or it was removed."),!1;f=[],a.each(m.outputElems,function(b,c){a(c)[0]!=g[0]&&f.push(m.outputElems[b])}),m.outputElems=f,f=[],a.each(m.inputElems,function(b,c){a(c)[0]!=e[0]&&f.push(m.inputElems[b])}),m.inputElems=f,g.data(k)&&(a(b).unbind("resize",g.data(k)),g.removeData(k)),g.remove(),e.removeAttr("style"),"undefined"!=typeof e.data(l)&&(e.attr("style",e.data(l)),e.removeData(l)),"undefined"!=typeof e.data(j)&&e.removeData(j)}},"native":function(c,d){d.before.apply(c,[c]);var f=this,h=a(c),i=a("");h.data(l,h.attr("style")),h.hide(),i.bind("load",function(){var l={obj:i,size:{width:this.width,height:this.height}},m=(g(d.width),g(d.height),d.responsive),n=a(l.obj),o=a("
"),p=0,q=function(){setTimeout(function(){r()},m)},r=function(){var b=n.parent(),c=b.height(),f=b.width(),h=d.zoom,i=d.position.x,j=d.position.y;if(l.size.width>l.size.height?(n.css({width:"auto","max-height":99999999,"min-height":0,"max-width":99999999,"min-width":0,height:c+"px"}),p=n.height()/n.width(),n.css(n.width()"),m=d.width.toString(),o=d.height.toString(),q=g(m),r=g(o);k.css({width:parseFloat(e(m)*d.zoom)+q,height:parseFloat(e(o)*d.zoom)+r,position:"relative",overflow:"hidden"}).appendTo(n.parent()),n.appendTo(k)}n.css({position:"absolute",left:function(){var a=0;return"%"==g(i)?(a=parseFloat((n.width()-n.parent().width())/100*e(i)),0>=a?a+"px":"-"+a+"px"):"px"==g(i)||isNaN(i)===!1?e(i)+"px":void 0}(),top:function(){var a=0;return"%"==g(j)?(a=parseFloat((n.height()-n.parent().height())/100*e(j)),0>=a?a+"px":"-"+a+"px"):"px"==g(j)||isNaN(j)===!1?e(j)+"px":void 0}()})};o.insertBefore(h).append(n).css({position:"relative",overflow:"hidden",width:e(d.width)+g(d.width),height:e(d.height)+g(d.height)}).data(j,j),r(),!isNaN(m)&&m>0&&(o.data(k,q),a(b).bind("resize",o.data(k))),o.hide().addClass(d.classname),d.show===!0&&o.show(),d.after.apply(c,[o]),f.updateGlobal(c,o,d)}).attr("src",h.attr(d.source))},modern:function(b,c){c.before.apply(b,[b]);var d=this,f=a(b),h=a("").attr("src",f.attr(c.source));f.data(l,f.attr("style")),f.hide(),a.each(h,function(h,i){var k=a(i);k.one("load",function(){var h=c.width,i=c.height,k=c.zoom,l=c.position.x,m=c.position.y,n=null,o=null;n=a("
").css({width:e(h)+g(h),height:e(i)+g(i),display:"none",position:"relative",overflow:"hidden"}).addClass(c.classname).data(j,j),o=a("
").css({width:"100%",height:"100%","background-image":'url("'+f.attr(c.source)+'")',"background-repeat":"no-repeat","background-position":e(l)+g(l)+" "+e(m)+g(m),"background-size":"cover"}).appendTo(n),n.insertBefore(a(b)),n.show(),o.css({width:parseFloat(100*k)+"%",height:parseFloat(100*k)+"%",position:"absolute"}).css({top:function(){var a=n.height(),b=o.height();return"%"==g(m)?"-"+parseFloat((b-a)/a*100/(100/e(m)))+"%":void 0}(),left:function(){var a=n.width(),b=o.width();return"%"==g(l)?"-"+parseFloat((b-a)/a*100/(100/e(l)))+"%":void 0}()}),n.hide(),c.show===!0&&n.show(),c.after.apply(b,[n]),d.updateGlobal(b,n,c)})})},updateGlobal:function(b,c,d){b.global.outputElems.push(a(c)[0]),b.global.elemCounter++,m.outputElems.push(a(c)[0]),b.global.elemCounter==b.global.inputElems.length&&d.done.apply(b,[b.global.outputElems])}},a.fn[j]=function(b){var c={},e={elemCounter:0,outputElems:[],inputElems:function(b){for(var c=a(b),d=c.length,e=[],f=0;d>f;f++)e.push(c.get(f));return e}(a(this))};return c[j]=function(b){return"undefined"==typeof b?void d("error","Please specify an action like $."+j+'("killall")'):(b=b.toLowerCase(),void("killall"==b&&a.each(m.inputElems,function(){new h(this,"kill")})))},a.extend(a,c),this.each(function(){var c=a(this);this.global=e,m.inputElems.push(c),"string"==typeof b?new h(this,b):c.data(j)?(new h(this,"kill"),c.data(j,new h(this,b))):c.data(j,new h(this,b))})}}(window.jQuery||window.Zepto,window,document);