!function(t){"use strict";t.jscroll={defaults:{debug:!1,autoTrigger:!0,autoTriggerUntil:!1,loadingHtml:"Loading...",loadingFunction:!1,padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:!1}};var n=function(n,e){var l=n.data("jscroll"),o="function"==typeof e?{callback:e}:e,r=t.extend({},t.jscroll.defaults,o,l||{}),i="visible"===n.css("overflow-y"),c=n.find(r.nextSelector).first(),a=t(window),s=t("body"),d=i?a:n,f=t.trim(c.attr("href")+" "+r.contentSelector),g=function(){var n=t(r.loadingHtml).filter("img").attr("src");if(n){var e=new Image;e.src=n}},u=function(){n.find(".jscroll-inner").length||n.contents().wrapAll('
')},p=function(t){var n;r.pagingSelector?t.closest(r.pagingSelector).hide():(n=t.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide(),n.length||t.wrap('
').parent().hide())},j=function(){return d.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()},h=function(){if(n.is(":visible")){u();var t=n.find("div.jscroll-inner").first(),e=n.data("jscroll"),l=parseInt(n.css("borderTopWidth"),10),o=isNaN(l)?0:l,c=parseInt(n.css("paddingTop"),10)+o,a=i?d.scrollTop():n.offset().top,s=t.length?t.offset().top:0,f=Math.ceil(a-s+d.height()+c);if(!e.waiting&&f+r.padding>=t.outerHeight())return w("info","jScroll:",t.outerHeight()-f,"from bottom. Loading next request..."),m()}},v=function(t){return t=t||n.data("jscroll"),t&&t.nextHref?(b(),!0):(w("warn","jScroll: nextSelector not found - destroying"),j(),!1)},b=function(){var e=n.find(r.nextSelector).first();if(e.length)if(r.autoTrigger&&(r.autoTriggerUntil===!1||r.autoTriggerUntil>0)){p(e);var l=s.height()-n.offset().top,o=n.height()0?a.height()-(n.offset().top-t(window).scrollTop()):a.height();o<=i&&h(),d.unbind(".jscroll").bind("scroll.jscroll",function(){return h()}),r.autoTriggerUntil>0&&r.autoTriggerUntil--}else d.unbind(".jscroll"),e.bind("click.jscroll",function(){return p(e),m(),!1})},m=function(){var e=n.find("div.jscroll-inner").first(),l=n.data("jscroll");return l.waiting=!0,e.append('
').children(".jscroll-added").last().html('
'+r.loadingHtml+"
").promise().done(function(){r.loadingFunction&&r.loadingFunction()}),n.animate({scrollTop:e.outerHeight()},0,function(){e.find("div.jscroll-added").last().load(l.nextHref,function(e,o){if("error"===o)return j();var i=t(this).find(r.nextSelector).first();l.waiting=!1,l.nextHref=!!i.attr("href")&&t.trim(i.attr("href")+" "+r.contentSelector),t(".jscroll-next-parent",n).remove(),v(),r.callback&&r.callback.call(this),w("dir",l)})})},w=function(t){if(r.debug&&"object"==typeof console&&("object"==typeof t||"function"==typeof console[t]))if("object"==typeof t){var n=[];for(var e in t)"function"==typeof console[e]?(n=t[e].length?t[e]:[t[e]],console[e].apply(console,n)):console.log.apply(console,n)}else console[t].apply(console,Array.prototype.slice.call(arguments,1))};return n.data("jscroll",t.extend({},l,{initialized:!0,waiting:!1,nextHref:f})),u(),g(),b(),t.extend(n.jscroll,{destroy:j}),n};t.fn.jscroll=function(e){return this.each(function(){var l,o=t(this),r=o.data("jscroll");r&&r.initialized||(l=new n(o,e))})}}(jQuery);