Array.prototype.index=function(a){for(var c=0,i=this.length;c0&&b<=5&&p.fadeTo("fast", 0.5).fadeTo("fast",1)},u=function(b){if(b.isEmpty())return"none";if(b.total>i&&b.allocations.length>1)return"support";return"ok"};this.insert=function(b){g.val(b);g.select()};this.fullResultsCallback=function(b){var n=u(b);r.attr("class",n);if(b.isEmpty()){m();q(0);s.show();h()}else if(b.total>i&&b.allocations.length>1){m();h();f.show(b);q(b.total)}else if(b.offset==0){m();q(b.total);d.render(v,b);v.show();h();g.focus()}else{n=$(w).position().top;y.remove();d.render(v,b);$("body").animate({scrollTop:n- 12},500)}};this.liveResultsCallback=function(b){var n=u(b);r.attr("class",n);q(b.total)};this.allocationChosen=function(b){b=b.data.query;a.insert(b);a.allocationChosen(b)};this.addinationClicked=function(b){a.addinationClicked(e(),b)};(function(){g.keyup(function(b){if(e()==""){o();a.searchTextCleared()}else h();a.searchTextEntered(e(),b)});p.click(function(){a.searchButtonClicked(e())});k.click(function(){a.searchButtonClicked(e())});j.click(function(){o();a.clearButtonClicked();g.focus()})})(); g.focus()};var PickyBackend=function(a){var c=function(i,g,j){var k=j||{};k=$.extend({query:i},j);$.getJSON(a,k,function(p){g&&g(new PickyData(p))})};this.search=function(i,g,j,k){c(i,function(p){g&&g(k,p)},j)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),i=new PickyBackend(c);this.search=function(g,j,k,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;k=$.extend({ids:a.liveResults||0,offset:0},k);i.search(g,function(r,w){if(!r.live||r.live==latestRequestTimestamp)j&& j(w)},k,p)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),i=new PickyBackend(c);this.search=function(g,j,k,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;k=$.extend({ids:a.fullResults||20,offset:0},k);i.search(g,function(r,w){if(!r.full||r.full==latestRequestTimestamp)j&&j(w)},k,p)}};var PickyController=function(a){var c=new PickyView(this,a),i=a.backends,g=a.beforeInsert||function(){},j=a.before||function(){},k=a.success||function(){},p=a.after||function(){},r=a.searchOnEmpty||false,w=a.liveRendered||false,v=a.liveSearchInterval||180,s,y=function(b){return(b=b&&b.match(/q=([^&]+)/))&&decodeURIComponent(b[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=y;var f=function(){var b=window.History&&window.History.getState();return y(b&&b.url)};this.lastFullQuery=f;var d= function(b,n,A,x){var z=j(n,x);if(z!=undefined)n=z;s=[b,n,A,x];z=n;if(z!=f()){z=!r&&z==""?"":"?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}if(!r&&n=="")c.reset();else(b=i[b])&&b.search(n,A,x)};this.resend=function(){s&&d.apply(this,s)};var h=function(b,n){b=k(b,n)||b;c.fullResultsCallback(b);p(b,n)},m=function(b,n){clearInterval(e);d("full",b,h,n||{})};a=function(b,n){b=k(b,n)||b;c.liveResultsCallback(b); p(b,n)};var o=w?h:a,e,q=function(){var b=c.text();d("live",b,o,{});clearInterval(e)};e=setInterval(q,v);clearInterval(e);var u=function(b,n,A){var x=g(b);if(x!=undefined)b=x;c.insert(b);A&&m(b,n)};this.insert=u;this.clearButtonClicked=function(){clearInterval(e)};this.searchTextCleared=function(){clearInterval(e)};this.searchTextEntered=function(b,n){if($.inArray(n.keyCode,[0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(n.keyCode== 13)m(b);else{clearInterval(e);e=setInterval(q,v)}};this.searchButtonClicked=function(b){m(b)};this.allocationChosen=function(b){m(b)};this.addinationClicked=function(b,n){m(b,{offset:n.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var b=window.History.getState();b=y(b.url);b!=undefined&&b!=(s&&s.length>1&&s[1])&&u(b,{},true)})};var PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;a.qualifiers=a.qualifiers||{};a.explanations=a.explanations||{};a.choices=a.choices||{};a.explanation_delimiters={ch:"und",de:"und",en:"and",fr:"et",it:"e"};var c=a.backends;if(c){c.live||alert("Both a full and live backend must be provided.");c.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)}; c=a.enclosingSelector||".picky";var i=a.formSelector||c+" form";a.form=$(i);a.input=$(a.inputSelector||i+" input[type=search]");a.reset=$(a.resetSelector||i+" div.reset");a.button=$(a.buttonSelector||i+" input[type=button]");a.counter=$(a.counterSelector||i+" div.status");a.results=$(a.resultsSelector||c+" div.results");a.noResults=$(a.noResultsSelector||c+" div.no_results");a.moreSelector=a.moreSelector||c+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||c+" .allocations"); a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||c+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||"
    ";var g=a.controller&&new a.controller(a)||new PickyController(a);var j=this.insert=function(k,p,r){g.insert(k,p||{},r||true)};this.resend=g.resend;this.insertFromURL= function(k){if(k)j(k);else(k=g.lastFullQuery())&&j(k)}};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(i){var g=i.total,j,k=i.renderedAmount();j=i.offset+k;k=j+k;i=i.total;if(i"+t("results.addination.more")+"");g.bind("click",{offset:j.offset},a.addinationClicked);return g}else return""}};var PickyResultsRenderer=function(a,c){var i=c.locale,g=c.explanations||{},j=c.explanation_delimiters||{},k=c.resultsDivider,p=c.wrapResults,r=c.nonPartial,w=function(d){var h=d[d.length-1];if(h===undefined)return[];d=d.slice(0,d.length-1);if(d==[])d=[d];if(!r.include(h[0]))if(h[1].match(/[^\*~]$/))h[1]+="*";d.push(h);return d};this.asteriskifyLastToken=w;var v=function(d){for(var h=g[i]||{},m=[],o,e=0,q=d.length;e"+d+"",h].join(" ")};this.strongify=s;var y=function(d,h){var m=j[i],o="",e=[],q=[];v(w(h)).each(function(u,b){var n=b[0],A=b[1];A=A.replace(/[\w,]+:(.+)/,"$1");if(o==""||n==o){e.push(A);o=n}else{var x=s(o,e.join(" "));e=[];e.push(A);o=n;q.push(x)}});q.push(s(o,e.join(" ")));q=q.join(" "+m+" ");return q=''+d+" "+q+""};this.explain=y;var f=function(d,h){var m='
    ';m+=y(h.type,h.combination);if(d.offset> 0)m+='';m+="
    ";return m};this.renderHeader=f;this.render=function(d,h){h.allocations.each(function(m,o){if(o.entries.length>0){d.append(f(h,o)).append(o.entries.join(k));d.children("li").wrapAll(p)}});d.append(a.render(h))}};function AllocationRenderer(a){function c(f){var d={},h={},m={},o=[],e;e=0;for(l=f.length;e=0;e--)f.remove(o[e]);return f}function i(f){f.map(function(d){return"%"+(d+1)+"$s"});return f.join(" ")}function g(f){if(f.length==0)return"";f=c(f);f.sort(function(u,b){return u[0]=0;f--){n=d[f];if(n.length>0)break}n=n[n.length-1];y.include(n[0])||(n[1]=n[1].valueOf()+"*");return d}function k(f){var d=[];j(f).each(function(h,m){var o=g(m);o&&d.push(o)});return d.join(" ")}var p=a.locale, r=a.qualifiers&&a.qualifiers[p]||{},w=a.explanations&&a.explanations[p]||{},v=a.groups||[],s=a.choices&&a.choices[p]||{},y=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=c;this.makeUpMissingFormat=i;this.rendered=g;this.groupify=j;this.querify=function(f){var d=[],h,m,o;for(o in f){h=f[o][0];h=r[h]||h;m=(m=f[o][1])||"";m=m.charAt(m.length-1)=="*"?"*":"";d[o]=h+":"+f[o][2]+m}return d.join(" ")};this.suggestify=k;this.render=function(f){return k(f.combination)}};var PickyAllocationsCloud=function(a,c){var i=c.allocations,g=c.shownAllocations,j=c.showMoreAllocations,k=c.hiddenAllocations,p=c.maxSuggestions,r=function(){i.hide()},w=function(f){r();a.allocationChosen(f)},v=new AllocationRenderer(c),s=function(f){var d=[];f.each(function(h,m){var o=v.querify(m.combination),e=v.render(m);e=$('
  1. '+e+'
    '+m.count+"
  2. ");e.bind("click",{query:o},w);d.push(e)});return d},y=function(f){if(f.length==0)return i.hide(); g.empty();j.hide();k.empty().hide();if(f.length>p){$.each(f.slice(0,p-1),function(d,h){g.append(h)});$.each(f.slice(p-1),function(d,h){k.append(h)});j.show()}else $.each(f,function(d,h){g.append(h)});return i.show()};j.click(function(){j.hide();k.show()});this.hide=r;this.show=function(f){y(s(f.allocations));i.show()}};