window.addEvent('domready', function() {
  var m = new mooFacebox();
	
	if (Browser.name=="ie" && Browser.version<8) return;
	
  var ac = new QAutocompleter('q', '/werke.json', {
    'postVar': 'q',
    minLength: 3,
    maxChoices: 10,
    autoSubmit: false,
    cache: true,
    delay: 300,
    customChoices: $('werke-result'),
    modal: m
  });
/*
  var pop = function(items) {
    var list = $('werk-liste');
    list.empty();

    new Element('tr').adopt(
      new Element('th', {'html':'&nbsp;'}),
      new Element('th', {'html':'Verlag'}),
      new Element('th', {'html':'&nbsp;'})
    ).inject(list, 'top');

    items.each(function(i){
      ac.buildChoice(i[0], i).inject(list);
    });
    m.scan();
  }

  $$('.tab-menu a').addEvent('click', function(e){
    e.stop();
    if (!this.retrieve('items')) {
      new Request.JSON({
        'url': this.href,
        'link': 'cancel',
        'onComplete': function(response){
          this.store('items', response.result);
          pop(response.result);
        }.bind(this)
      }).send();
    }
    else {
      pop(this.retrieve('items'));
    }
  });
*/
});
