Ajax.SearchAutocompleter = Class.create(Ajax.Autocompleter, {
    markPrevious: function() {
        var step = 1;
        if (this.index > 0) {
            this.index = this.index - step;
		} else {
			this.index = this.entryCount - step;
        }
        
        if (typeof this.options.onMarkPrevious == 'function') {
            this.options.onMarkPrevious(this);
        }
	},

    markNext: function() {
        var step = 1; 
        if (this.index < this.entryCount) {
            this.index = this.index + step;
        } else {
            this.index = 0;
        }
        
        if (typeof this.options.onMarkNext == 'function') {
            this.options.onMarkNext(this);
        }
    },

    updateChoices: function ($super, choices) {
        $super(choices);

        if (!this.changed && this.hasFocus) {
            var links = this.update.select('a.product', 'span.sku');
            links.each((function (item) {
                var text = item.innerHTML;
                text = text.replace(new RegExp('(' + this.element.value + ')', 'i'), '<b>$1</b>');
                item.update(text);
            }).bind(this));
        }

        this.index = -1;
        this.render();

        if (typeof this.options.onUpdateChoices == 'function') {
            this.options.onUpdateChoices(this);
        }
    },

    onBlur: function (e) {
        this.hideTimeout = setTimeout(this.hide.bind(this), 250);
        this.hasFocus = false;
        this.active = false;
    }
});