Autocompleter.TagAndFirm = new Class({
	Extends: Autocompleter,
	
	options: {
		'firmItems': 'Firemní záznamy'
	},
	
	update: function(tokens) {
		this.choices.empty();
		var emptyTags = tokens.tags.length == 0;
		if (Math.floor(this.options.maxChoices / 2) < tokens.tags.length && !this.options.overflow) 
			tokens.tags.length = Math.floor(this.options.maxChoices / 2);
		if (Math.ceil(this.options.maxChoices / 2) < tokens.firms.length && !this.options.overflow)
			tokens.firms.length = Math.ceil(this.options.maxChoices / 2);
		tokens.tags.each(this.options.injectChoice || function(token) {
			var choice = new Element('li', {'html': this.markQueryValue(token)});
			choice.inputValue = token;
			this.addChoiceEvents(choice).inject(this.choices);
		}, this);
		var start = true;
		tokens.firms.each(this.options.injectChoice || function(token) {
			var choice = new Element('li', {'html': this.markQueryValue(token) + (start ? ('<span>' + this.options.firmItems + '</span>') : ''), 'class': (!emptyTags && start ? 'first-firm firm' : 'firm')});
			choice.inputValue = token;
			this.addChoiceEvents(choice).inject(this.choices);
			start = false;
		}, this);
		
		this.showChoices();
	}
});
