/*
// Infinite Scroll jQuery plugin
// copyright Paul Irish, licensed GPL & MIT
// version 1.5.110124

// home and docs: http://www.infinite-scroll.com
*/
(function(a){a.fn.infinitescroll=function(s,k){function d(){if(b.debug){window.console&&console.log.call(console,arguments)}}function o(C){for(var B in C){if(B.indexOf&&B.indexOf("Selector")>-1&&a(C[B]).length===0){d("Your "+B+" found no elements.");return false}return true}}function h(B){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}d("Trying backup next selector parse technique. Treacherous waters here, matey.");B=B.match(/^(.*?)2(.*?$)/).slice(1)}else{if(B.match(/^(.*?page=)1(\/.*|$)/)){B=B.match(/^(.*?page=)1(\/.*|$)/).slice(1);return B}if(a.isFunction(b.pathParse)){return[B]}else{d("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.");j.isInvalidPage=true}}}return B}function q(){b.isFiltered=true;return p.trigger("error.infscr."+b.infid,[302])}function y(B){var C=0;a(B).children().each(function(){C=C+a(this).outerHeight(false)});return C}function m(B){var C=a(B).length+a(B).html().length+a(B).attr("class").length+a(B).attr("id").length;b.infid=C}function u(){if(b.container.nodeName=="HTML"){var B=0+a(document).height()-(a(b.container).scrollTop()||a(b.container.ownerDocument.body).scrollTop())-a(window).height()}else{var B=0+y(b.container)-a(b.container).scrollTop()-a(b.container).height()}return(B-b.bufferPx<b.pixelsFromNavToBottom)}function g(){j.loadingMsg.find("img").hide().parent().find("div").html(b.donetext).animate({opacity:1},2000,function(){a(this).parent().fadeOut("normal")});b.errorCallback()}function e(){if(b.isDuringAjax||b.isInvalidPage||b.isDone||b.isFiltered||b.isPaused){return}if(!u(b,j)){return}a(document).trigger("retrieve.infscr."+b.infid)}function v(){b.isDuringAjax=true;j.loadingMsg.appendTo(b.loadMsgSelector).show(b.loadingMsgRevealSpeed,function(){a(b.navSelector).hide();var B=a("ul#nav_filter").data("Filtered");d("the data item detected: ",B);if(B==false){b.currPage++;d("Page number incremented ",b.currPage)}else{b.currPage=1;a("ul#nav_filter").data("Filtered",false);d("The currentpage was reset")}d("heading into ajax",x);n=a(b.contentSelector).is("table")?a("<tbody/>"):a("<div/>");w=document.createDocumentFragment();if(a.isFunction(b.pathParse)){c=b.pathParse(x.join("2"),b.currPage)}else{c=x.join(b.currPage)}n.load(c+" "+b.itemSelector,null,l)})}function l(){if(b.isDone){g();return false}else{var B=n.children();if(B.length==0||B.hasClass("error404")){return A([404])}while(n[0].firstChild){w.appendChild(n[0].firstChild)}a(b.contentSelector)[0].appendChild(w);j.loadingMsg.fadeOut("normal");if(b.animate){var C=a(window).scrollTop()+a("#infscr-loading").height()+b.extraScrollPx+"px";a("html,body").animate({scrollTop:C},800,function(){b.isDuringAjax=false})}k.call(a(b.contentSelector)[0],B.get());if(!b.animate){b.isDuringAjax=false}}}function r(B){if(B=="pause"){b.isPaused=true}else{if(B=="resume"){b.isPaused=false}else{b.isPaused=!b.isPaused}}d("Paused: "+b.isPaused);return false}function A(B){if(!b.isDone&&B==404){d("Page not found. Self-destructing...");g();b.isDone=true;b.currPage=1;p.unbind("scroll.infscr."+b.infid);a(document).unbind("retrieve.infscr."+b.infid)}if(b.isFiltered&&B==302){d("Filtered. Going to next instance...");b.isDone=true;b.currPage=1;b.isPaused=false;p.unbind("scroll.infscr."+b.infid,e).unbind("pause.infscr."+b.infid).unbind("filter.infscr."+b.infid).unbind("error.infscr."+b.infid);a(document).unbind("retrieve.infscr."+b.infid,v)}}a.browser.ie6=a.browser.msie&&a.browser.version<7;var b=a.extend({},a.infinitescroll.defaults,s),j=a.infinitescroll,n,w,c,t,z;k=k||function(){};if(!o(b)){return false}b.container=b.container||document.documentElement;b.contentSelector=b.contentSelector||this;if(b.infid==0){m(b.contentSelector)}b.loadMsgSelector=b.loadMsgSelector||b.contentSelector;var f=/(.*?\/\/).*?(\/.*)/,x=a(b.nextSelector).attr("href");if(!x){d("Navigation selector not found");return}x=h(x);j.loadingMsg=a('<div id="infscr-loading" style="text-align: center;"><img alt="Loading..." src="'+b.loadingImg+'" /><div>'+b.loadingText+"</div></div>");(new Image()).src=b.loadingImg;if(b.container.nodeName=="HTML"){d("Window Scroll");var i=a(document).height();var p=a(window)}else{d("Local Scroll");var i=y(b.container);var p=a(b.container)}b.pixelsFromNavToBottom=i+(b.container==document.documentElement?0:a(b.container).offset().top)-a(b.navSelector).offset().top;p.bind("scroll.infscr."+b.infid,e).bind("filter.infscr."+b.infid,q).bind("error.infscr."+b.infid,function(B,C){A(C)}).bind("pause.infscr."+b.infid,function(C,B){r(B)}).trigger("scroll.infscr."+b.infid);a(document).bind("retrieve.infscr."+b.infid,v);return this};a.infinitescroll={defaults:{debug:false,preload:false,nextSelector:"div.navigation a:first",loadingImg:"http://www.infinite-scroll.com/loading.gif",loadingText:"<em>Loading the next set of posts...</em>",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:undefined,bufferPx:40,errorCallback:function(){},currPage:0,infid:0,isDuringAjax:false,isInvalidPage:false,isFiltered:false,isDone:false,isPaused:false,container:undefined,pixelsFromNavToBottom:undefined},loadingImg:undefined,loadingMsg:undefined,currDOMChunk:null}})(jQuery);
