"use strict";function Spinner(b,e,a,f,c,d){this.elem=b;this.no_of_frames=d;this.x_squares=c;this.y_squares=Math.floor(d/c)+1;this.img_url=e;this.x_step=a/this.x_squares;this.y_step=f/this.y_squares}Spinner.prototype.show=function(a){this.elem.css("background-position","-"+(a%this.x_squares)*this.x_step+"px -"+Math.floor(a/this.x_squares)*this.y_step+"px")};Spinner.prototype.step=function(){this.cur_frame=(this.cur_frame%this.no_of_frames)+1;this.show(this.cur_frame)};Spinner.prototype.start=function(a){this.elem.css("background-image",'url("'+this.img_url+'")');this.elem.css("width",this.x_step);this.elem.css("height",this.y_step);this.elem.css("display","block");this.show(this.cur_frame=1);var b=this;this.id=setInterval(function(){b.step()},a)};Spinner.prototype.stop=function(){this.elem.css("display","none");clearInterval(this.id);this.show(this.cur_frame=0)};jQuery.fn.extend({scrollTo:function(a,b,c){return this.each(function(){var d=$(this).offset().top;setTimeout(function(){$("html, body").animate({scrollTop:d},b,c)},a)})}});function sanitize_headers(){var b,a="";$("li.header").each(function(){b=$(this).text();if(b===a){$(this).remove()}a=b})}function bind_more(){var b=$("li.more a"),a=b.attr("href");b.removeAttr("href");$("span.title",b).text(msg_load_more);b.bind("click",{href:a},function(d){var c=new Spinner($("span.spinner",b),"/pics/24/gnome-spinner.png",176,88,8,31);b.css({"background-color":"rgba(0,0,255,0.4)"});c.start(50);$.ajax({url:d.data.href}).done(function(f){c.stop();get_logo_token(f);var e=$("li.booklink, li.more",f).clone();e.appendTo(b.parent().parent());b.parent().remove();sanitize_headers();bind_more()})})}function clear_suggestions(a){$(".suggestion").slideUp("fast",function(){$(".suggestion").remove();$("#searchlist").scrollTo(0,"fast")})}function get_suggestions(a){var b=a.target.value;if(b!==a.target.old_value){a.target.old_value=a.target.value;clear_suggestions(a);if(b.length>=4){$.ajax({url:json_search,data:{query:b},dataType:"json",cache:false,xhrFields:{withCredentials:true}}).done(function(e){if(e[0]===a.target.value){var d,c=e[1];for(d=c.length-1;d>=0;--d){$("#searchlist").after('')}$(".suggestion").slideDown("fast",function(){$("#searchlist").scrollTo(0,"fast")})}})}}}function toggle_help(){$("#helpbox").slideToggle("fast")}function get_help(){$("#helpbox").slideDown("fast")}function clear_help(){$("#helpbox").slideUp("fast")}function bind_search(){var a=$("#query");if(a){a.keydown(function(b){if(b.target.suggestions_timer_id){clearTimeout(b.target.suggestions_timer_id);delete b.target.suggestions_timer_id}});a.keyup(function(b){var c=b;c.target.suggestions_timer_id=setTimeout(get_suggestions,500,c)});a.attr("placeholder",a.attr("title"));a.attr("type","search");a.old_value=a.value}}function bind_clear(){var b=$("#query"),a=$("#clear");a.click(function(c){c.preventDefault();b.val("");b.old_value=b.value;clear_suggestions();b.focus()})}function scroll_to_first_header(){if($.fx.off){return}$(".header:eq(0)").scrollTo(500,800,"swing")}function get_logo_token(b){var c=$(".icon_search",b),a=c.attr("id");$.cookie("bonus",a,{path:"/",domain:"gutenberg.org"})}$(document).ready(function(){get_logo_token($(document));$.fx.off=!do_animations;bind_more();bind_search();bind_clear();scroll_to_first_header()});