Ajax.AutocompleterHF = Class.create(Ajax.Autocompleter, {

  initialize: function(element, update, url, options, afterComplete, offsetLeft) {

      if(typeof(offsetLeft) == "undefined") {
	offsetLeft = 0;
      }

      options.onShow = options.onShow ||
	function(element, update) {
	  if(!update.style.position || update.style.position=='absolute') {
	    update.style.position = 'absolute';
	    Position.clone(element, update, {
	      setHeight: false,
		  offsetLeft: element.offsetWidth + 2 + offsetLeft,
		  offsetTop: -2
		  });
	  }
	  Effect.Appear(update,{duration:0.15});
      };
      Ajax.Autocompleter.prototype.initialize.call(this, element, update, url, options);
      this.afterComplete = afterComplete;
  },

  onComplete: function(request) {
      Ajax.Autocompleter.prototype.onComplete.call(this, request);
      this.afterComplete.call(this, this.update);
  },

  markPrevious: function() {
    if(this.index > 1) this.index--;
      else this.index = this.entryCount-2;
    this.getEntry(this.index).scrollIntoView(true);
  },

  markNext: function() {
    if(this.index < this.entryCount-2) this.index++;
      else this.index = 1;
    this.getEntry(this.index).scrollIntoView(false);
  },

  onHover: function(event) {
    var element = Event.findElement(event, 'LI');
    if(this.index != element.autocompleteIndex && element.autocompleteIndex < this.entryCount - 1)
    {
        this.index = element.autocompleteIndex;
        this.render();
    }
    Event.stop(event);
  }

});
