(function(){var g=[];window.jQuery&&jQuery(function(c){window._wp_rp_request_id=window._wp_rp_request_id||((new Date).getTime()%60466176/60466176).toString(36).substr(2,5)+Math.random().toString(36).substr(2,10);var h=0,t=c(window),j=1*window._wp_rp_num_rel_posts||5,u=2*j,k=!0,f=c(".wp_rp.related_post"),l=!1,m=!1,z=2*f.outerHeight(!0),n=j,p=function(){if(0>=g.length)return c("#wp_rp_related_load_more").parent().remove(),[];for(var b=0,a=[],e={};b<(k?j:u);b+=1)(e=g.shift())&&a.push(e);k=!1;return a},
q=function(b){m&&0>=g.length&&c("#wp_rp_related_load_more").parent().remove();!l&&!m&&(l=!0,c.getJSON(window._wp_rp_wp_ajax_url+"?action=wp_rp_load_articles&post_id="+window._wp_rp_post_id+"&from="+n+"&count=50&size=full",function(a){!a||!a.length||"string"===typeof a?(m=!0,0>=g.length&&c("#wp_rp_related_load_more").parent().remove()):(n+=a.length,c.each(a,function(a,c){g.push(c)}),b&&b());l=!1}))},v=function(){var b=function(a){setTimeout(function(){c("#wp_rp_related_load_more").find(".zloader").hide().end().find("span").show()},
500);var b=c(".related_post.wp_rp"),d=b.find("li ul li").length,g=null,f=b.find(".wp_rp_related_post_column"),h=function(a){var b=c();f.each(function(a,d){d=c("ul",d);if(null===b.height()||b.height()>=d.height())b=d});b.append(a)};c.each(a,function(a,b){var e=c(b.img);e.load(function(){c(this).data("zloaded",!0)}).error(function(){c(this).data("zloaded",!0)});var f=c('<li data-position="'+d+'" data-poid="'+b.id+'"><a href="'+b.url+'" class="wp_rp_thumbnail"></a><a href="'+b.url+'" class="wp_rp_title">'+
b.title+"</a></li>");f.data("position",d);f.data("poid",b.id);f.find(".wp_rp_thumbnail").append(e);d+=1;var i=g;setTimeout(function(){!i||!i.length||i.data("zloaded")?h(f,e):i.load(function(){h(f,e)}).error(function(){h(f,e)})},75*a);g=e})};0>=g.length?q(function(){b(p())}):g.length<=2*u?(b(p()),q()):b(p())},w=function(){h&&clearTimeout(h);h=setTimeout(function(){var b=c(".related_post.wp_rp");b.offset().top+b.outerHeight(!0)-t.scrollTop()-t.height()+100<z&&v()},150)},y=-1,r=[],s=0;f.find("li").each(function(b,
a){a=c(a);a.children().find("img").data("zloaded",!0);var e=a.data("poid"),d=a.data("position"),f=a.data("post-type"),g=a.attr("class"),e=c('<li class="'+g+'" data-post-type="'+f+'" data-position="'+d+'" data-poid="'+e+'"></li>'),d=a.offset().left;d>y&&(y=d,s+=1);d=b%s;e.append(a.children());r[d]?(r[d].find("ul").append(e),a.remove()):(a.empty(),a.attr("data-position",null),a.attr("data-poid",null),a.attr("data-post-type",null),a.addClass("wp_rp_related_post_column"),a.addClass("wp_rp_special"),a.append("<ul></ul>"),
a.find("ul").append(e),r[d]=a)});w();c(window).bind("scroll.zloader",function(){k?w():c(window).unbind("scroll.zloader")});q();f.append(c('<li class="wp_rp_related_post_load_more wp_rp_special"><a id="wp_rp_related_load_more" href="#"><span>Load more posts</span><img src="'+window._wp_rp_static_base_url+'img/loading.gif" class="zloader" /></a></li>'));f.find("#wp_rp_related_load_more").click(function(b){c("span",this).hide();c(".zloader",this).show();b.preventDefault();v();var b=document.createElement("img"),
a={action:"pinterest-load-more",post_id:window._wp_rp_post_id,request_id:window._wp_rp_request_id,_:+new Date},e=[],d=window._wp_rp_static_base_url+"stats.gif?";for(x in a)a.hasOwnProperty(x)&&e.push(x+"="+a[x]);d+=e.join("&");b.src=d})})})();
