(function(d){d.fn.category=function(){var h=d(this),g=h.next().next(),l=g.find(".cs_sb"),m=l.find("input"),j=h.next(),k=g.find(".cs_mitem"),c={scache:{},mcache:{},kcache:"",load:function(a){d(this).css("visibility","hidden");var b=d(this).position();g.show().css({left:b.left,top:b.top-4});c.mcache[0]?c._binditem(c.mcache,false):d.getJSON("?app=system&controller=category&action=dropcate",{},function(e){if(e){c._binditem(e,false);c.mcache=e}});m.focus();a.stopPropagation()},search:function(a){if(!(a.keyCode==
38||a.keyCode==40||a.keyCode==13))if(a.keyCode==37||a.keyCode==39)c.select(d(".over"));else{var b=this.value;if(c.kcache=b)c.scache[b]==undefined?d.getJSON("?app=system&controller=category&action=search",{keyword:b},function(e){c._binditem(e,true);c.scache[b]=e}):c._binditem(c.scache[b],true);else c.mcache[0]&&c._binditem(c.mcache,false);return false}},hotkey:function(a){var b=d(".over");if(a.keyCode==38||a.keyCode==40)if(b[0]==undefined)d(".cs_mlist:first").addClass("over");else{b.removeClass("over");
var e=b.prev()[0]?b.prev():d(".cs_mlist:last");b=b.next()[0]?b.next():d(".cs_mlist:first");a.keyCode==40&&b.addClass("over");a.keyCode==38&&e.addClass("over")}a.keyCode==13&&c.select(d(".over"));a.stopPropagation()},select:function(a){var b=a[0]?a:d(this);a=b.attr("catid");var e=b.attr("name");if(b[0]!=document){h.val(a);j.html(e);d.get("?app=system&controller=category&action=note",{catid:h.val(),name:b.attr("name")});b=false;for(var i in c.mcache)if(a==c.mcache[i].catid){b=true;c.mcache.splice(i,
1);c.mcache.unshift({catid:a,name:e});break}if(!b){c.mcache.unshift({catid:a,name:e});c.mcache.pop()}}g.hide();k.html("");j.css("visibility","visible")},_binditem:function(a,b){k.html("");for(var e="",i=a.length,f=0;f<i;f++){if(b)e=a[f].name.replace(c.kcache,'<b style="color:#F00">'+c.kcache+"</b>");k.append(d('<div class="cs_mlist '+(f==0&&b?"over":"")+'" catid="'+a[f].catid+'" name="'+a[f].name+'" >'+(b?e:a[f].name)+"</div>").hover(function(){d(this).addClass("over")},function(){d(this).removeClass("over")}).bind("click",
c.select))}}};d(document).click(c.select);j.click(c.load);l.click(function(a){a.stopPropagation()});m.keyup(c.search);g.keydown(c.hotkey)}})(jQuery);
