function classHobbySelect( HobbyJSON, id, callback ) {
	//}
	var thisO = this;
	this.write_id = id;
	this.callback = callback;
	this.JSON = HobbyJSON;
	
	this.opt_multiselect = false;
	this.opt_return_name_array = false;
	this.opt_return_type = 'array';
	this.opt_arr_preselected = [];
	
	this.allowed_return_type = ['array', 'string', 'int'];
	
	this.arr_selected = [];
	
	this._suggest_name;
	this._suggest_category_id;
	this._default = 0;
	
	
	this.search = function() {
		var str = $('#'+this.write_id+'_HS_search').val();
		var sug = str;
		$('#'+this.write_id+'_HS_ghost').html(str);
		var width = $('#'+this.write_id+'_HS_ghost').outerWidth() + 10;
		$('#'+this.write_id+'_HS_search').css( { width: width + "px" } );
		
		var reg1 = /(\*|\+|\?|\.|\(|\)|\[|\]|\{|\}|\\|\/|\||\^|\$)/;
		var reg2 = /^(.){2,}$/;
		
		if ( !reg1.test(str) && reg2.test(str) ) {
			var inner_html = '';
			reg = eval('/(\\b' + str + ' *)/gi');
			var hobby = this.JSON.subcategory;
			var arr_result = new Array();
			var num_result = 0;
			
			for ( var i in hobby ) {
				var str = hobby[i].name;
				if ( reg.test(str) ) {
					num_result++;
					str = str.replace(reg, '<span style="font-weight: bold; color: #666699;">$1</span>' );
					var superiorId = hobby[i].superiorId;
					var superiorName = this.getSuperiorName( superiorId );
					inner_html += '' +
						'<div id="'+this.write_id+'_HS_result_'+num_result+'" style="border-bottom: 1px solid #AAAAAA; padding: 2px; cursor: pointer; color: #333333;" class="HS_option">' +
							'' + str + '<br />' + 
							'<span class="atrS">' + superiorName + '</span>' + 
						'</div>';
					var arr_temp = new Array();
					arr_temp['num'] = num_result;
					arr_temp['event_id'] = this.write_id+'_HS_result_'+num_result;
					arr_temp['id'] = hobby[i].id;
					arr_temp['superior_id'] = hobby[i].superiorId;
					arr_temp['name'] = hobby[i].name;
					arr_temp['superior_name'] = superiorName;
					arr_result.push(arr_temp);
				}
			}
			
			if ( num_result == 0 ) {
				inner_html = '<div style="border-bottom: 1px solid #AAAAAA; padding: 5px;"><h2>Sorry!</h2>Leider haben wir dein Hobby nicht gefunden.<br />Du kanst aber ganz einfach eine neues Hobby vorschlagen<br /><table><tr><td class="atrN">Neues Hobby: </td><td><input id="'+this.write_id+'_suggest_name" tpye="text" class="input" style="width: 185px;" /></td></tr><tr><td class="atrN">Kategorie:</td><td><select id="'+this.write_id+'_suggest_category_id" name="hobby_search_add_category" size="5" style="width: 188px;">';
				for ( i = 0; i < this.JSON.category.length; i++ ) {
					var selected = '';
					if ( i == 0 ) selected = 'selected="selected"';
					inner_html += '<option value="' + this.JSON.category[i].id + '" ' + selected + '>' + this.JSON.category[i].name + '</option>';
				}
				inner_html += '</select></td></tr></table><div style="text-align: right;"><input id="'+this.write_id+'_suggest_button" type="button" class="Button" value="Add"/></div></div>';
				//if( $('#'+this.write_id+'_HS_fly_div').outerWidth() < 280 ) $('#'+this.write_id+'_HS_fly_div').css({width: '280px'});
				//alert($('#'+this.write_id+'_HS_fly_div').outerWidth());
			}
			inner_html = '<div style="border-top: 1px solid #AAAAAA; border-left: 1px solid #AAAAAA; border-right: 1px solid #AAAAAA;">' + inner_html + '</div>';
			MY.box[this.write_id+"_HS_fly_div"].html(inner_html);
			MY.box[this.write_id+"_HS_fly_div"].show();
			if ( num_result != 0 ) {
				this.makeClickSelectable(arr_result);
			} else {
				$('#'+this.write_id+'_HS_fly_div').css({width: '280px'});
				this.addSuggestEvent();
				$('#'+this.write_id+'_suggest_name').val(sug);
			}
		} else {
			//alert(inner_html);
			MY.box[this.write_id+"_HS_fly_div"].html('');
			MY.box[this.write_id+"_HS_fly_div"].hide();
		}
	}
	
	this.getHobbyName = function( id ) {
		var hobby_name = '';
		var hobby = this.JSON.subcategory;
		for ( var i in hobby ) {
			if ( id == hobby[i].id ) {
				hobby_name = this.JSON.subcategory[i].name;
			}
		}
		return hobby_name;
	}
	
	this.getSuperiorId = function( id ) {
		var superiorId = 0;
		var hobby = this.JSON.subcategory;
		for ( var i in hobby ) {
			if ( id == hobby[i].id ) {
				superiorId = this.JSON.category[i].superiorId;
			}
		}
		return superiorId;
	}
	
	this.getSuperiorName = function( id ) {
		var superiorName = '';
		for ( j = 0; j < this.JSON.category.length; j++ ) {
			if ( id == this.JSON.category[j].id ) {
				superiorName = this.JSON.category[j].name;
			}
		}
		return superiorName;
	}
	
	this.makeClickSelectable = function( arr_result ) {
		for ( var i in arr_result ) {
			this.addClickSelect( arr_result[i]['event_id'], arr_result[i]['id'], arr_result[i]['name'], arr_result[i]['superior_id'], arr_result[i]['superior_name'] );
		}
		$('.HS_option').hover(
			function(){
				$(this).css( { backgroundColor: '#EBEBEB' } );
			}, 
			function(){
				$(this).css( { backgroundColor: '#FFFFFF' } );
			}
		);
	}
	
	this.addClickSelect = function ( id, hobby_id, hobby_name, superior_id, superior_name) {
		$('#'+id).click(
			function () {
				thisO.select( hobby_id, hobby_name, superior_id, superior_name );
			}
		);
	}
	
	this.select = function( id ) {
		$('#'+this.write_id+'_HS_search').val('').css( { width: '10px' } );
		$('#'+this.write_id+'_HS_ghost').html('');
		if ( !this.opt_multiselect ) {
			this.arr_selected = new Array();
			this.arr_selected.push(id);
		} else if ( !in_array( id, this.arr_selected ) ) {
			this.arr_selected.push(id);
		}
		this.visualize();
	}
	
	this.makeClickRemoveable = function() {
		//alert( "length: " + this.arr_selected.length );
		for ( var i in this.arr_selected ) {
			var id = this.arr_selected[i];
			this.addClickRemove( this.write_id+'_HS_visualize_'+id, id );
		}
	}
	
	this.addClickRemove = function( id, hobby_id ) {
		//alert("remove: " + hobby_id + "\nfrom: " + id );
		$('#'+id).click(
			function () {
				thisO.remove( hobby_id );
			}
		);
	}
	
	this.addSuggestEvent = function() {
		$( '#'+this.write_id+'_suggest_button').click(
			function() {
				thisO.suggest();
			}
		);
	}
	
	this.suggest = function() {
		var name = $('#'+this.write_id+'_suggest_name').val();
		var cat_id = $('#'+this.write_id+'_suggest_category_id').val();
		if( name.length > 2 && !isNaN(parseInt(cat_id, 10)) ) {
			this._suggest_name = name;
			this._suggest_category_id = cat_id;
			$.post(
				'ajax_receive.php', 
				{ action: 'suggest', name: name, category: cat_id }, 
				function(data) {
					thisO.suggestHandle(data);
				}
			);
		}
		//alert(name+'\n'+cat_id+'\n'+Number.MAX_VALUE);
	}
	
	this.suggestHandle = function(id) {
		id = parseInt(id, 10);
		if( id == 0 || isNaN(id) ) {
			alert("Hobby was not suggested");
		} else {
			this.suggestAdd( id, this._suggest_name, this._suggest_category_id );
		}
	}
	
	this.suggestAdd = function( id, name, cat_id ) {
		var arr_subcat = [];
		var arr_cat = [];
		
		var cat = this.JSON.category;
		for( var i in cat ) {
			arr_cat.push( '{ "name": "'+cat[i].name+'", "id": '+cat[i].id+' }' );
		}
		var subcat = this.JSON.subcategory;
		for( var i in subcat ) {
			arr_subcat.push( '{ "name": "'+subcat[i].name+'", "id": '+subcat[i].id+', "superiorId": '+subcat[i].superiorId+' }' );
		}
		arr_subcat.push( '{ "name": "'+name+'", "id": '+id+', "superiorId": '+cat_id+' }' );
		
		var json = '({"subcategory": ['+arr_subcat.join(',')+'],"category": ['+arr_cat.join(',')+']})';
		this.JSON = eval(json);
		this.select(id);
	}
	
	this.remove = function () {
		var id = 'all';
		if ( arguments.length ) {
			id = arguments[0];
		}
		if ( id == 'all' ) {
			this.arr_selected = new Array();
		} else {
			arr_temp = new Array();
			for ( var i in this.arr_selected ) {
				if ( id != this.arr_selected[i] ) {
					arr_temp.push(this.arr_selected[i]);
				}
			}
			this.arr_selected = arr_temp;
		}
		if( !this.arr_selected.length && this._default ) {
			this.select(this._default);
		} else {
			this.visualize();
		}
	}
	
	this.visualize = function() {
		var html = '';
		for ( var i in this.arr_selected ) {
			html += '<span id="'+this.write_id+'_HS_visualize_'+this.arr_selected[i]+'" style="border: 1px solid #3B5998; background-color: #D8DFEA; cursor: pointer; margin-left: 1px; margin-right: -3px; font-weight: normal; font-size: 10px; font-style: normal;"><nobr>&nbsp;' +  this.getHobbyName(this.arr_selected[i]) + '&nbsp;</nobr></span> ';
		}
		$('#'+this.write_id+'_HS_visualize').html(html);
		this.makeClickRemoveable();
		this.returnValue();
	}
	
	this.returnValue = function() {
		MY.box[this.write_id+"_HS_fly_div"].hide();
		MY.box[this.write_id+"_HS_fly_div"].html('');
		$('#'+this.write_id+'_HS_search').val('').focus();
		var return_value = this.arr_selected;
		if ( this.opt_return_type == 'string' ) {
			return_value = return_value.join(', ');
		} else if ( this.opt_return_type == 'int' ) {
			return_value = parseInt(return_value[0], 10);
		}
		this.callback( return_value );
	}
	
	this.check = function( what ) {
		what = parseInt(what, 10);
		if ( !isNaN(what) && what > 0 ) {
			var hobby = this.JSON.subcategory;
			for ( var i in hobby ) {
				if( hobby[i].id == what ) {
					return true;
				}
			}
			return false;
		}
		return false;
	}
	
	this.checkClick = function(e) {
		if (  MY.box[thisO.write_id+"_HS_fly_div"] && !objectClicked(e, [thisO.write_id+"_HS_fly_div", thisO.write_id]) ) {
			MY.box[thisO.write_id+"_HS_fly_div"].hide();
		}
	}
	
	
	
	if ( arguments.length == 4 ) {
		var opts = arguments[3]
		for ( var opt in opts ) {
			if ( opt == 'multiselect' ) {
				this.opt_multiselect = opts[opt] ? true : false;
			}
			if ( opt == 'returnNameArray' ) {
				this.opt_return_name_array = opts[opt] ? true : false;
			}
			if ( opt == 'preselect' && opts[opt].length ) {
				this.opt_arr_preselected = opts[opt];
			}
			if ( opt == 'returnType' && in_array(opts[opt], this.allowed_return_type) ) {
				this.opt_return_type = opts[opt];
			}
			if ( opt == 'default' && this.check(opts[opt]) ) {
				this._default = opts[opt];
			}
		}
	}
	if ( this.opt_return_type == 'int' && this.opt_multiselect ) this.opt_return_type = 'array';
	
	var html = 	'';
	html 	+= 	'<span id="'+this.write_id+'_HS_visualize"></span>';
	html 	+= 	'<input id="'+this.write_id+'_HS_search" type="text" name="hobby_search_string" class="HS_input" style="margin-left: 1px;" />';
	html 	+=	'<span id="'+this.write_id+'_HS_ghost" class="HS_input" style="position: absolute; left: -9999px;  top: -9999px;"></span>';
	//html 	+= 	'<div style="clear: both;"></div>';
	$('#'+this.write_id).html(html);
	$('#'+this.write_id+'_HS_search').keyup(
		function () {
			thisO.search();
		}
	);
	$('#'+this.write_id).css(
		{ cursor: 'text', lineHeight: '15px', padding: '1px', overflow: 'hidden', height: 'auto' } 
	).click(
		function () {
			$('#'+thisO.write_id+'_HS_search').focus();
			thisO.search();
		}
	);
	$(document).click(
		function(e) {
			thisO.checkClick(e);
		}
	);
	var width = $('#'+this.write_id).outerWidth();
	if ( width < 280 ) 
		width = 280;
	else 
		width = 'object';
	var temp = new flyBox('', { position: this.write_id, id: this.write_id+"_HS_fly_div", vertical: "bottom", horizontal: "inner_left", width: 'object' }, { marginTop: "-1px" } );
}
