(function($) { $.suggest = function(input, options) { var $input = $(input).attr("autocomplete", "off"); var $results = $(document.createElement("ul")); var timeout = false; var prevLength = 0; var cache = []; var cacheSize = 0; $results.addClass(options.resultsClass).appendTo('body'); resetPosition(); $(window).load(resetPosition).resize(resetPosition); $input.blur(function() { setTimeout(function() { $results.hide() }, 200); }); try { $results.bgiframe(); } catch (e) { } if ($.browser.mozilla) $input.keypress(processKey2); $input.keyup(processKey); $input.keydown(processKey2); function resetPosition() { var offset = $input.offset(); var logooffset = $(".logo").offset(); var width = $(input).width(); if($(input).siblings(".zt_s_submit").length == 1){ width = $(input).parents("div").width() - $(input).siblings(".zt_s_submit").width(); } else if($(input).css("padding-left") != '0px' || $(input).css("padding-right") != '0px'){ var left_length = $(input).css("padding-left").length; var right_length = $(input).css("padding-right").length; width += parseInt($(input).css("padding-left").substring(0, left_length-2)) + parseInt($(input).css("padding-right").substring(0, right_length-2)); } $results.css( { top : (offset.top + input.offsetHeight-1) + 'px', left : offset.left + 'px', width : width }); } function processKey(e) { if (/^9$|27$|38$|40$/.test(e.keyCode) && getCurrentResult()) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); e.cancelBubble = true; e.returnValue = false; selectCurrentResult(); } else if ($input.val().length != prevLength) { if (timeout) clearTimeout(timeout); timeout = setTimeout(suggest, options.delay); prevLength = $input.attr({"_val":$input.val()}).val().length; } } function processKey2(e) { if (/27$|38$|40$/.test(e.keyCode) && $results.is(':visible')) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); e.cancelBubble = true; e.returnValue = false; switch (e.keyCode) { case 38: // up prevResult(); break; case 40: // down nextResult(); break; case 27: // escape $results.hide(); break; } with($input)if(!getCurrentResult())val(attr("_val")); } else if ($input.val().length != prevLength) { if (timeout) clearTimeout(timeout); timeout = setTimeout(suggest, options.delay); prevLength = $input.val().length; } } function suggest() { var q = $input.val(); if (q.length >= options.minchars) { cached = checkCache(q); if (cached) { displayItems(cached['items']); } else { window.sugresult = ""; $.getScript(options.source + "&sw=" + encodeURIComponent(q)+"&t="+new Date().getTime(), function(data) { var txt = window.sugresult; $results.hide(); var items = parseTxt(txt, q); displayItems(items); addToCache(q, items, txt.length); }); } } else { $results.hide(); } } function checkCache(q) { for ( var i = 0; i < cache.length; i++) if (cache[i]['q'] == q) { cache.unshift(cache.splice(i, 1)[0]); return cache[0]; } return false; } function addToCache(q, items, size) { while (cache.length && (cacheSize + size > options.maxCacheSize)) { var cached = cache.pop(); cacheSize -= cached['size']; } cache.push( { q : q, size : size, items : items }); cacheSize += size; } function displayItems(items) { if (!items) return; if (!items.length) { $results.hide(); return; } var html = ''; for ( var i = 0; i < items.length; i++) html += '