Suggest = Class.create(Ajax.Autocompleter, {
  initialize: function(element, update, url, options) {
    this.baseInitialize(element, update, options);
    this.options.asynchronous  = true;
    this.options.onComplete    = this.onComplete.bind(this);
    this.options.defaultParams = this.options.parameters || null;
    this.url                   = url;
    new Form.Element.Observer(this.element, 1, this.onChange.bind(this));
  },
  onChange: function() {
    if(this.hasFocus){
      this.changed = true;
      this.hasFocus = true;
      if(this.observer)clearTimeout(this.observer);
      this.observer=setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
    }
  },
  render: function() {
    if(this.entryCount > 1) {
      for (var i = 0; i < this.entryCount; i++){
        this.index==i ?
          Element.addClassName(this.getEntry(i),"selected") :
          Element.removeClassName(this.getEntry(i),"selected");
      }
      if(this.index == 0){
          Element.addClassName(this.getEntry(0),"hidden");
      }
      if(this.hasFocus) {
        this.show();
        this.active = true;
      }
    } else {
      this.active = false;
      this.hide();
    }
  },
  selectEntry: function() {
    this.active = false;
    this.updateElement(this.getCurrentEntry());
    this.hasFocus = false;
    this.active = false;
    if(this.observer)clearTimeout(this.observer);
  },
  markPrevious: function() {
    if(this.index > 0) this.index--;
      else this.index = this.entryCount-1;
  },
  markNext: function() {
    if(this.index < this.entryCount-1) this.index++;
      else this.index = 0;
  }
});
