(function(c,a,b){a.infinitescroll=function(d,b,c){this.element=a(c);this._create(d,b)};a.infinitescroll.defaults={callback:function(){},debug:false,binder:a(c),nextSelector:"div.navigation a:first",loadingImg:"http://www.infinite-scroll.com/loading.gif",loadingText:"<em>Loading the next set of posts...</em>",loadingStart:null,loadingEnd:null,donetext:"<em>Congratulations, you've reached the end of the internet.</em>",navSelector:"div.navigation",contentSelector:null,loadMsgSelector:null,loadingMsgRevealSpeed:"fast",extraScrollPx:150,itemSelector:"div.post",animate:false,pathParse:b,dataType:"html",appendCallback:true,bufferPx:40,orientation:"height",errorCallback:function(){},currPage:1,infid:0,isDuringAjax:false,isInvalidPage:false,isDestroyed:false,isDone:false,isPaused:false,pixelsFromNavToBottom:b,pagesLoaded:null,path:b,loadingMsg:b};a.infinitescroll.prototype={_create:function(c,e){if(!this._validate(c))return false;var b=this.options=a.extend({},a.infinitescroll.defaults,c);b.contentSelector=b.contentSelector||this.element;b.loadMsgSelector=b.loadMsgSelector||b.contentSelector;var f=/(.*?\/\/).*?(\/.*)/,d=a(b.nextSelector).attr("href");if(!d){this._debug("Navigation selector not found");return}b.path=this._determinepath(d);b.loadingMsg=a('<div id="infscr-loading"><img alt="Loading..." src="'+b.loadingImg+'" /><div>'+b.loadingText+"</div></div>");(new Image).src=b.loadingImg;b.pixelsFromNavToBottom=a(document).height()-a(b.navSelector).offset().top;b.callback=e||function(){};this.binding("bind")},_debug:function(){if(this.options.debug)return c.console&&console.log.call(console,arguments)},_determinepath:function(b){var c=this.options;if(a.isFunction(c.pathParse)){this._debug("pathParse");return[b]}else if(b.match(/^(.*?)\b2\b(.*?$)/))b=b.match(/^(.*?)\b2\b(.*?$)/).slice(1);else if(b.match(/^(.*?)2(.*?$)/)){if(b.match(/^(.*?page=)2(\/.*|$)/)){b=b.match(/^(.*?page=)2(\/.*|$)/).slice(1);return b}b=b.match(/^(.*?)2(.*?$)/).slice(1)}else if(b.match(/^(.*?page=)1(\/.*|$)/)){b=b.match(/^(.*?page=)1(\/.*|$)/).slice(1);return b}else{this._debug("Sorry, we couldn't parse your Next (Previous Posts) URL. Verify your the css selector points to the correct A tag. If you still get this error: yell, scream, and kindly ask for help at infinite-scroll.com.");c.isInvalidPage=true}this._debug("determinePath",b);return b},_error:function(a){var b=this.options;if(a!=="destroy"&&a!=="end")a="unknown";this._debug("Error",a);a=="end"&&this._showdonemsg();b.isDone=true;b.currPage=1;b.isPaused=false;this.binding("unbind")},_loadcallback:function(f,d){var b=this.options,h=this.options.callback,j=b.isDone?"done":!b.appendCallback?"no-append":"append",e;switch(j){case"done":this._showdonemsg();return false;break;case"no-append":if(b.dataType=="html"){d="<div>"+d+"</div>";d=a(d).find(b.itemSelector)}break;case"append":var g=f.children();if(g.length==0)return this._error("end");e=document.createDocumentFragment();while(f[0].firstChild)e.appendChild(f[0].firstChild);this._debug("contentSelector",a(b.contentSelector)[0]);a(b.contentSelector)[0].appendChild(e);d=g.get()}b.loadingMsg.fadeOut("normal");if(b.animate){var i=a(c).scrollTop()+a("#infscr-loading").height()+b.extraScrollPx+"px";a("html,body").animate({scrollTop:i},800,function(){b.isDuringAjax=false})}if(!b.animate)b.isDuringAjax=false;h.call(a(b.contentSelector)[0],d)},_nearbottom:function(){var b=this.options,d=0+a(document).height()-b.binder.scrollTop()-a(c).height();this._debug("math:",d,b.pixelsFromNavToBottom);return d-b.bufferPx<b.pixelsFromNavToBottom},_showdonemsg:function(){var b=this.options;b.loadingMsg.find("img").hide().parent().find("div").html(b.donetext).animate({opacity:1},2e3,function(){a(this).parent().fadeOut("normal")});b.errorCallback()},_validate:function(c){for(var b in c){if(b.indexOf&&b.indexOf("Selector")>-1&&a(c[b]).length===0){this._debug("Your "+b+" found no elements.");return false}return true}},binding:function(a){var b=this;if(a!=="bind"&&a!=="unbind"){this._debug("Binding value  "+a+" not valid");return false}if(a=="unbind")this.options.binder.unbind("smartscroll.infscr."+b.options.infid);else this.options.binder[a]("smartscroll.infscr."+b.options.infid,function(){b.setup()});this._debug("Binding",a)},destroy:function(){this.options.isDestroyed=true;return this._error("destroy")},pause:function(a){var b=this.options;a!=="pause"&&a!=="resume"&&a!=="toggle"&&a!==null&&this._debug("Invalid argument. Toggling pause value instead");a=a&&(a=="pause"||a=="resume")?a:"toggle";switch(a){case"pause":b.isPaused=true;break;case"resume":b.isPaused=false;break;case"toggle":b.isPaused=!b.isPaused}this._debug("Paused",b.isPaused);return false},retrieve:function(g){var c=this,b=c.options,h=b.path,e,k,f,d,i,g=g||null,j=!!g?g:b.currPage;if(b.isDestroyed){this._debug("Instance already destroyed");return false}b.isDuringAjax=true;b.loadingMsg.appendTo(b.loadMsgSelector).show(b.loadingMsgRevealSpeed,function(){a(b.navSelector).hide();b.currPage++;c._debug("heading into ajax",h);e=a(b.contentSelector).is("table")?a("<tbody/>"):a("<div/>");f=a.isFunction(b.pathParse)?b.pathParse(h.join("2"),b.currPage):h.join(b.currPage);d=b.dataType=="html"||b.dataType=="json"?b.dataType:"html+callback";if(b.appendCallback&&b.dataType=="html")d+="+callback";switch(d){case"html+callback":c._debug("Using HTML via .load() method");e.load(f+" "+b.itemSelector,null,function(a){c._loadcallback(e,a.responseText)});break;case"html":case"json":c._debug("Using "+d.toUpperCase()+" via $.ajax() method");a.ajax({url:f,dataType:b.dataType,complete:function(a,b){i=typeof a.isResolved!=="undefined"?a.isResolved():b==="success"||b==="notmodified";i?c._loadcallback(e,a.responseText):c._error("end")}})}})},setup:function(){var a=this.options;if(a.isDuringAjax||a.isInvalidPage||a.isDone||a.isDestroyed||a.isPaused)return;if(!this._nearbottom())return;this.retrieve()}};a.fn.infinitescroll=function(b,c){var d=typeof b;switch(d){case"string":var e=Array.prototype.slice.call(arguments,1);this.each(function(){var c=a.data(this,"infinitescroll");if(!c)return false;if(!a.isFunction(c[b])||b.charAt(0)==="_")return false;c[b].apply(c,e)});break;case"object":this.each(function(){var d=a.data(this,"infinitescroll");!d&&a.data(this,"infinitescroll",new a.infinitescroll(b,c,this))})}return this};var e=a.event,d;e.special.smartscroll={setup:function(){a(this).bind("scroll",e.special.smartscroll.handler)},teardown:function(){a(this).unbind("scroll",e.special.smartscroll.handler)},handler:function(c,a){var b=this,e=arguments;c.type="smartscroll";d&&clearTimeout(d);d=setTimeout(function(){jQuery.event.handle.apply(b,e)},a==="execAsap"?0:100)}};a.fn.smartscroll=function(a){return a?this.bind("smartscroll",a):this.trigger("smartscroll",["execAsap"])}})(window,jQuery);
