/**
 * Auto Complete 3.2
 * September 17, 2009
 * Corey Hart @ http://www.codenothing.com
 */ 
;(function(c,d){c.fn.autoComplete=function(f,h,e,i){if(h===d||typeof h!=="number"){return a.call(this,f)}var g=c.Event("keyup");g.keyCode=h;return c(this).trigger(g,[f,e,i])};var b=0,a=function(e){return this.each(function(){var n=c(this).attr("autocomplete","off"),m,g,i,f,j=c.extend({opt:-1,inputval:"",mouseClick:false,dataName:"ac-data",inputIndex:++b,ajax:"ajax.php",list:"auto-complete-list",rollover:"auto-complete-list-rollover",width:n.outerWidth(),postVar:"value",postData:{},minChars:1,maxRequests:0,requests:0,onMaxRequest:function(){},onSelect:function(){},onRollover:function(){},onBlur:function(){},onFocus:function(){},preventEnterSubmit:false,enter:true,delay:100,selectFuncFire:true,useCache:true,cacheLimit:50,cacheLength:0,cache:{}},e||{},c.metadata?n.metadata():{});var k=c("ul."+j.list)[0]?c("ul."+j.list):c("<ul/>").appendTo("body").addClass(j.list).hide();n.keyup(function(r,q,o,u){var p=r.keyCode;j.mouseClick=false;if(q&&typeof q==="object"){var t=c.extend(true,{},j);j=c.extend(true,j,q);if(u){if(!o){j=t}return false}}if(p==13&&m){j.opt=-1;if(j.selectFuncFire){j.selectFuncFire=false;j.onSelect.call(n[0],m.data(j.dataName),m,k);if(i){clearTimeout(i)}i=setTimeout(function(){j.selectFuncFire=true},1000)}k.hide()}else{if(p==38){if(j.opt>0){j.opt--;m=c("li",k).removeClass(j.rollover).eq(j.opt).addClass(j.rollover);n.val(m.data(j.dataName).value||"");j.onRollover.call(n[0],m.data(j.dataName),m,k)}else{j.opt=-1;n.val(j.inputval);k.hide()}}else{if(p==40){if(j.opt<c("li",k).length-1){j.opt++;m=c("li",k.show()).removeClass(j.rollover).eq(j.opt).addClass(j.rollover);n.val(m.data(j.dataName).value||"");j.onRollover.call(n[0],m.data(j.dataName),m,k)}}else{j.opt=-1;j.inputval=n.val();if(j.inputval.length>=j.minChars){if(g){clearTimeout(g)}g=setTimeout(function(){h(j);if(t&&!o){j=t}clearTimeout(g)},j.delay)}else{if(p==8){k.html("").hide()}}}}}if(t&&!o&&!g){j=t}}).blur(function(){j.enter=true;f=setTimeout(function(){if(j.mouseClick){return false}j.opt=-1;j.onBlur.call(n[0],j.inputval,k);k.hide()},150)}).focus(function(){j.enter=false;if(j.inputIndex!=k.data("ac-input-index")){k.html("").hide()}j.onFocus.call(n[0],k)}).parents("form").eq(0).submit(function(){return j.preventEnterSubmit?j.enter:true});function h(o){if(o.maxRequests&&++o.requests>=o.maxRequests){return o.requests>o.maxRequests?false:o.onMaxRequest.call(n[0],o.inputval,k)}if(o.useCache&&o.cache[o.inputval]){return l(o.cache[o.inputval],o)}o.postData[o.postVar]=o.inputval;c.post(o.ajax,o.postData,function(p){if(o.useCache){o.cacheLength++;o.cache[o.inputval]=p;if(o.cacheLength>o.cacheLimit){o.cache={};o.cacheLength=0}}l(p,o)},"json")}function l(s,r){if(!s||s.length<1){return k.html("").hide()}var t=n.offset();k.data("ac-input-index",r.inputIndex).html("").css({top:t.top+n.outerHeight(),left:t.left,width:r.width});var p=0,q;for(q in s){if(s[q].value){c("<li/>").appendTo(k).html(s[q].display||s[q].value).data(r.dataName,s[q]).data("ac-index",p++)}}k.show().mouseout(function(){c("li."+r.rollover,k).removeClass(r.rollover);if(!r.mouseClick&&r.selectFuncFire){n.val(r.inputval)}}).children("li").mouseover(function(){m=c(this);c("li."+r.rollover,k).removeClass(r.rollover);n.val(m.addClass(r.rollover).data(r.dataName).value);r.onRollover.call(n[0],m.data(r.dataName),m,k);r.opt=m.data("ac-index")}).click(function(){r.mouseClick=true;if(f){clearTimeout(f)}r.onSelect.call(n[0],m.data(r.dataName),m,k);k.hide();n.focus()})}})}})(jQuery);

