

function TagsSearch(searchField, tagsList) {
	
	this.searchField = $(searchField);
	this.searchField.bind('keypress keydown keyup cut paste change', $.bind(this, this.updateTagsList));
	this.tagsList = tagsList;
	
}


TagsSearch.prototype = {
	
	updateTagsList: function() {
		var callback = $.bind(this, this.updateTagState);
		this.tagsList.each(callback);
	},
	
	updateTagState: function(tagElement) {
		var text = this.searchField.val().toLowerCase();
		tagElement = $(tagElement);
		
		tagElement.css('display',
			((text && (tagElement.text().toLowerCase().indexOf(text) < 0)) ? 'none' : 'inline')
		);
	}
	
}



