function TrainersDirector(
	oSearchInput,	
	oItems,	
	oOptions
	) {
			
	this.oSearchInput = oSearchInput;	
	this.oItems = oItems;	
	this.oOptions = oOptions;
			
	var oThis = this;				
			
	oSearchInput.onkeyup = oSearchInput.onblur = function() {
			
		oThis.update();
			
	}
			
}
		
TrainersDirector.prototype = {
		
	update : function() {
			
		var
			sValue = this.oSearchInput.value.toLowerCase(),			
			i = 0,
			iLength = this.oItems.length,
			oCurrentItem = null,
			oCurrentGroup = this.oItems[0].oGroupElement? this.oItems[0].oGroupElement : null,
			sCurrentGroupValue = this.oItems[0].sGroupValue? this.oItems[0].sGroupValue : '',
			bCurrentGroupShow = false			
			;
			

		while(i < iLength) {
				
			oCurrentItem = this.oItems[i];
							
			if(oCurrentGroup && (oCurrentItem.sGroupValue != sCurrentGroupValue ||
				i == iLength - 1)) {
												
				if(i == iLength - 1) {																
					
					if(oCurrentItem.sGroupValue != sCurrentGroupValue) {					
					
						oCurrentGroup.className = bCurrentGroupShow? '' : this.oOptions.sInvisibleClassName;
						bCurrentGroupShow = this.checkValue(oCurrentItem.sValue, sValue);
						
					}
					else if(!bCurrentGroupShow) {
						bCurrentGroupShow = this.checkValue(oCurrentItem.sValue, sValue);
					}

					oCurrentGroup = oCurrentItem.oGroupElement;																			
					
				}
				
				oCurrentGroup.className = bCurrentGroupShow? '' : this.oOptions.sInvisibleClassName;							
					
				oCurrentGroup = oCurrentItem.oGroupElement;
				sCurrentGroupValue = oCurrentItem.sGroupValue;
						
				bCurrentGroupShow = false;				
						
			}
										
			if(this.checkValue(oCurrentItem.sValue, sValue)) {								
					
				bCurrentGroupShow = true;																			
							
				oCurrentItem.oElement.className = oCurrentItem.sDefaultClassName;																									
					
			}
			else {															
				oCurrentItem.oElement.className += ' ' + this.oOptions.sInvisibleClassName;							
			}
														
			i++;
				
		}
						
			
	},		
			
			
	checkValue : function(	
		sItemValue,
		sCheckedValue
		) {
				
		return sCheckedValue.length >= this.oOptions.iMinSearchLength? sItemValue.toLowerCase().indexOf(sCheckedValue) > -1 : true;
				
	}		
		
};