Array.prototype.index=function(a){for(var b=0,j=this.length;b0&&c<=5&&v.fadeTo("fast",0.5).fadeTo("fast",1)},e=function(c){if(c.isEmpty())return"none";if(c.total>j&&c.allocations.length>1)return"support";return"ok"};this.insert=function(c){i.val(c);i.select()};this.fullResultsCallback=function(c){var s=e(c);x.attr("class",s);h.hide();g.hide();o.fadeTo(166,1);s=c.total;v.text(s);q(s);if(c.isEmpty()){w.empty();g.show()}else if(c.total> j&&c.allocations.length>1){k&&p(c);h.show(c)}else{p(c);l&&h.show(c)}};this.liveResultsCallback=function(c){var s=e(c);x.attr("class",s);c=c.total;v.text(c);q(c)};this.allocationChosen=function(c){c=c.data.query;a.insert(c);a.allocationChosen(c)};this.addinationClicked=function(c){a.addinationClicked(f(),c)};(function(){i.keyup(function(c){if(f()==""){n();a.searchTextCleared()}else o.fadeTo(166,1);a.searchTextEntered(f(),c)});v.click(function(){a.searchButtonClicked(f())});r.click(function(){a.searchButtonClicked(f())}); o.click(function(){n();a.clearButtonClicked();i.focus()})})();i.focus()};var PickyBackend=function(a){var b=function(j,k,l){var i=l||{};i=$.extend({query:j},l);$.getJSON(a,i,function(o){k&&k(new PickyData(o))})};this.search=function(j,k,l,i){b(j,function(o){k&&k(i,o)},l)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),j=new PickyBackend(b);this.search=function(k,l,i,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;i=$.extend({ids:a.liveResults||0,offset:0},i);j.search(k,function(r,v){if(!r.live||r.live==latestRequestTimestamp)l&& l(v,k)},i,o)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),j=new PickyBackend(b);this.search=function(k,l,i,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;i=$.extend({ids:a.fullResults||20,offset:0},i);j.search(k,function(r,v){if(!r.full||r.full==latestRequestTimestamp)l&&l(v,k)},i,o)}};var PickyController=function(a){var b=new PickyView(this,a),j=a.backends,k=a.beforeInsert||function(e){return e},l=a.before||function(e){return e},i=a.success||function(e){return e},o=a.after||function(e){return e},r=a.searchOnEmpty||false,v=a.liveRendered||false,x=a.liveSearchInterval||180,u,w=function(e){return(e=e&&e.match(/q=([^&]+)/))&&decodeURIComponent(e[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var g=function(){var e=window.History&&window.History.getState();return w(e&& e.url)};this.lastFullQuery=g;var d=function(e,c,s,y){var z=l(c,y);if(z!=undefined)c=z;u=[e,c,s,y];z=c;if(z!=g()){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&&c=="")b.reset();else(e=j[e])&&e.search(c,s,y)};this.resend=function(){u&&d.apply(this,u)};var h=function(e,c){(e=i(e,c))&&b.fullResultsCallback(e);o(e,c)},m=function(e,c){clearInterval(f);d("full",e,h,c||{})};a=function(e, c){(e=i(e,c))&&b.liveResultsCallback(e);o(e,c)};var n=v?h:a,f,p=function(){var e=b.text();d("live",e,n,{});clearInterval(f)};f=setInterval(p,x);clearInterval(f);var q=function(e,c,s){var y=k(e);if(y!=undefined)e=y;b.insert(e);s&&m(e,c)};this.insert=q;this.clearButtonClicked=function(){clearInterval(f)};this.searchTextCleared=function(){clearInterval(f)};this.searchTextEntered=function(e,c){if($.inArray(c.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(c.keyCode==13)m(e);else{clearInterval(f);f=setInterval(p,x)}};this.searchButtonClicked=function(e){m(e)};this.allocationChosen=function(e){m(e)};this.addinationClicked=function(e,c){m(e,{offset:c.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var e=window.History.getState();e=w(e.url);e!=undefined&&e!=(u&&u.length>1&&u[1])&&q(e,{},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 b=a.backends;if(b){b.live||alert("Both a full and live backend must be provided.");b.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)}; b=a.enclosingSelector||".picky";var j=a.formSelector||b+" form";a.form=$(j);a.input=$(a.inputSelector||j+" input[type=search]");a.reset=$(a.resetSelector||j+" div.reset");a.button=$(a.buttonSelector||j+" input[type=button]");a.counter=$(a.counterSelector||j+" div.status");a.results=$(a.resultsSelector||b+" div.results");a.noResults=$(a.noResultsSelector||b+" div.no_results");a.moreSelector=a.moreSelector||b+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||b+" .allocations"); a.shownAllocations=$(a.shownAllocations||a.allocations.find(".shown"));a.showMoreAllocations=$(a.showMoreAllocations||a.allocations.find(".more"));a.hiddenAllocations=$(a.hiddenAllocations||a.allocations.find(".hidden"));a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||b+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||"
    ";var k=a.controller&&new a.controller(a)||new PickyController(a);var l=this.insert=function(i, o,r){k.insert(i,o||{},r||true)};this.resend=k.resend;this.insertFromURL=function(i){if(i)l(i);else(i=k.lastFullQuery())&&l(i)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(j){var k=j.total,l,i=j.renderedAmount();l=j.offset+i;i=l+i;j=j.total;if(j"+t("results.addination.more")+"");k.bind("click",{offset:l.offset},a.addinationClicked);return k}else return""}};var PickyResultsRenderer=function(a,b){var j=b.locale,k=b.explanations||{},l=b.explanation_delimiters||{},i=b.resultsDivider,o=b.wrapResults,r=b.nonPartial,v=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=v;var x=function(d){for(var h=k[j]||{},m=[],n,f=0,p=d.length;f"+d+"",h].join(" ")};this.strongify=u;var w=function(d,h){var m=l[j],n="",f=[],p=[];x(v(h)).each(function(q,e){var c=e[0],s=e[1];s=s.replace(/[\w,]+:(.+)/,"$1");if(n==""||c==n){f.push(s);n=c}else{var y=u(n,f.join(" "));f=[];f.push(s);n=c;p.push(y)}});p.push(u(n,f.join(" ")));p=p.join(" "+m+" ");return p=''+d+" "+p+""};this.explain=w;var g=function(d,h){var m='
    ';m+=w(h.type,h.combination);if(d.offset> 0)m+='';m+="
    ";return m};this.renderHeader=g;this.render=function(d,h){h.allocations.each(function(m,n){if(n.entries.length>0){d.append(g(h,n)).append(n.entries.join(i));d.children("li").wrapAll(o)}});d.append(a.render(h))}};function AllocationRenderer(a){function b(g){var d={},h={},m={},n=[],f,p;f=0;for(p=g.length;f=0;f--)g.remove(n[f]);return g}function j(g){g.map(function(d){return"%"+(d+1)+"$s"});return g.join(" ")}function k(g){if(g.length==0)return"";g=b(g);for(var d=[],h=0,m=g.length;h=0;g--){c=d[g];if(c.length>0)break}c=c[c.length-1];w.include(c[0])||(c[1]=c[1].valueOf()+"*");return d}function i(g){var d=[];l(g).each(function(h,m){var n=k(m);n&&d.push(n)});return d.join(" ")}var o=a.locale,r=a.qualifiers&&a.qualifiers[o]|| {},v=a.explanations&&a.explanations[o]||{},x=a.groups||[],u=a.choices&&a.choices[o]||{},w=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=j;this.rendered=k;this.groupify=l;this.querify=function(g){var d=[],h,m,n;for(n in g){h=g[n][0];h=r[h]||h;m=(m=g[n][1])||"";m=m.charAt(m.length-1)=="*"?"*":"";d[n]=h+":"+g[n][2]+m}return d.join(" ")};this.suggestify=i;this.render=function(g){return i(g.combination)}};var PickyAllocationsCloud=function(a,b){var j=b.allocations,k=b.shownAllocations,l=b.showMoreAllocations,i=b.hiddenAllocations,o=b.maxSuggestions,r=function(){j.hide()},v=function(g){r();a.allocationChosen(g)},x=new AllocationRenderer(b),u=function(g){var d=[];g.each(function(h,m){var n=x.querify(m.combination),f=x.render(m);f=$('
  1. '+f+'
    '+m.count+"
  2. ");f.bind("click",{query:n},v);d.push(f)});return d},w=function(g){if(g.length==0)return j.hide(); k.empty();l.hide();i.empty().hide();if(g.length>o){$.each(g.slice(0,o-1),function(d,h){k.append(h)});$.each(g.slice(o-1),function(d,h){i.append(h)});l.show()}else $.each(g,function(d,h){k.append(h)});return j.show()};l.click(function(){l.hide();i.show()});this.hide=r;this.show=function(g){w(u(g.allocations));j.show()}};