function classFriendSelect( JSON, container_id, callback ) {
	//}
	var thisO = this;
	
	this.friend_json = JSON;
	this.friend_container = container_id;
	this.callback = callback;
	this.show_name = false;
	this.show_name_selector = '';
	
	this.opt_return_type = 'array';
	this.opt_arr_preselected = new Array();
	this.opt_print_group = true;
	this.opt_print_quicksearch = true;
	this.opt_print_all_button = true;
	this.opt_print_all_button_group = true;
	this.opt_return_name_array = false;
	this.opt_div_height = 'auto';
	this.opt_filter = true;
	
	this.allowed_return_type = new Array('array', 'string', 'int');
	this.arr_selected = new Array();
	
	this._filtering = false;
	this._arr_friend = [];
	this._arr_group = [];
	
	if ( arguments.length == 4 ) {
		var opts = arguments[3]
		for ( var opt in opts ) {
			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 == 'printGroup' ) {
				this.opt_print_group = opts[opt] ? true : false;
			}
			if ( opt == 'printQuicksearch' ) {
				this.opt_print_quicksearch = opts[opt] ? true : false;
			}
			if ( opt == 'printAllButton' ) {
				this.opt_print_all_button = opts[opt] ? true : false;
			}
			if ( opt == 'printAllButtonGroup' ) {
				this.opt_print_all_button_group = opts[opt] ? true : false;
			}
			if ( opt == 'returnNameArray' ) {
				this.opt_return_name_array = opts[opt] ? true : false;
			}
			if ( opt == 'height' && !isNaN(parseInt(opts[opt], 10)) && parseInt(opts[opt], 10) > 50 ) {
				this.opt_div_height = opts[opt];
			}
			if ( opt == 'showName' && opts[opt] ) {
				if( opts[opt] != false ) {
					if( $(opts[opt]).length ) {
						$(opts[opt]).each(function() { thisO.show_name = this.nodeName });
						//this.show_name = true;
						this.show_name_selector = opts[opt];
					}
				} else {
					this.show_name = false;
					this.show_name_selector = '';
				}
			}
		}
	}
	
	this.return_format = 'string';
	
	this.print_quicksearch = 1;
	this.print_all_button = 1;
	this.print_all_button_group = 1;
	this.print_group = 0;
	this.out;
	this.HTML = '';
	this.div_height = 400;
	this.do_visualize = 0;
	this.visualize_id = 'FS_visualize_id';
	
	this.out_input = 'friend_select_input';
	
	this.EC_name;
	
	this.poststr = '';
	
	this.newRequest = function() {
		this.poststr = 	"action=" 		+ encodeURIComponent( "friend_selector" ) + 
						"&action_id=" 	+ encodeURIComponent( "get_JSON" );
	}
	
	this.requestInClub = function(id) {
		if ( this.poststr != '' ) {
			this.poststr += "&in_club=" 	+ encodeURIComponent( id );
		}
	}
	
	this.requestInEvent = function(id) {
		if ( this.poststr != '' ) {
			this.poststr += "&in_event=" 	+ encodeURIComponent( id );
		}
	}
	
	this.requestClubMember = function(id) {
		if ( this.poststr != '' ) {
			this.poststr += "&getClubMember=" 	+ encodeURIComponent( id );
		}
	}
	
	this.requestInFriend = function() {
		if ( this.poststr != '' ) {
			this.poststr += "&in_friend=1";
		}
	}
	
	this.requestSend = function() {
		if ( this.poststr != '' ) {
			ajaxRequest.ajax('requestFriend', this.poststr, 'JSON', thisO.handleRequest);
			this.poststr = '';
		}
	}
	
	this.handleRequest = function() {
		var action = ajaxRequest.action();
		if ( action == 'requestFriend' ) {
			var friendJSON = eval(ajaxRequest.responseText());
			alert(friendJSON);
			this.setFriend(friendJSON);
			this.write();
		}
	}
	
	this.setFriend = function(JSON) {
		this.friend_json = JSON;
	}
	
	this.setDivHeight = function(height) {
		height = parseInt(height, 10);
		if ( height == 0 ) {
			this.div_height = '';
		} else if ( height < 50 ) {
			this.div_height = 50;
		} else if ( height >= 50 ) {
			this.div_height = height;
		}
	}
	
	this.visualize = function() {
		if (arguments.length) this.visualize_id = arguments[0];
		this.do_visualize = 1;
	}
	
	this.quicksearch = function() {
		var str = getObject("FS_quicksearch_input").value;
		reg1 = /(\*|\+|\?|\.|\(|\)|\[|\]|\{|\}|\\|\/|\||\^|\$)/;
		reg2 = /^.{2,}$/
		
		if ( !reg1.test(str) && reg2.test(str) ) {
			reg = eval('/(\\b' + str + ' *)/gi');
			for ( var key in this.friend_json.friend ) {
				var id = this.friend_json.friend[key].id;
				if( this._arr_friend[id].active == 1 || (this._arr_friend[id].active == 0 && this._filtering ) ) {
					var name = this.friend_json.friend[key].name;
					if ( reg.test(id) || reg.test(name) ) {
						name = name.replace(reg, '<font style="font-weight: bold;">$1</font>' );
						getObject("FS_name_"+id).innerHTML = name;
						getStyleObject("FS_"+id).display = "";
					} else {
						getObject("FS_name_"+id).innerHTML = name;
						getStyleObject("FS_"+id).display = "none";
					}
				}
			}
		} else {
			for ( var key in this.friend_json.friend ) {
				var id = this.friend_json.friend[key].id;
				if( this._arr_friend[id].active == 1 || (this._arr_friend[id].active == 0 && this._filtering ) ) {
					var name = this.friend_json.friend[key].name;
					getObject("FS_name_"+id).innerHTML = name;
					getStyleObject("FS_"+id).display = "";
				}
			}
		}
	}
	
	this.filter = function() {
		var disp = getObject('FS_filter').checked ? '' : 'none';
		this._filtering = getObject('FS_filter').checked ? true : false;
		var member = this.friend_json.friend;
		for ( var i in member ) {
			if ( member[i].active == 0 ) {
				getStyleObject('FS_'+member[i].id).display = disp;
			}
		}
	}
	
	this.select = function(id) {
		var select = !this._arr_friend[id]['selected'];
		var className = select ? "FS_selected" : "FS_unselected";
		if( this._arr_friend[id]['active'] == 1 ) {
			this._arr_friend[id]['selected'] = select;
			getObject('FS_'+id).className = className;
		}
		this.check();
	}
	
 	this.check = function() {
		if ( this.opt_print_quicksearch ) {
			$("#FS_quicksearch_input").focus().select();
		}
		getObject("FS_all").className = this.checkAllSelected() ? "FS_selected" : "FS_unselected";
		
		for( var gid in this._arr_group ) {
			getObject("FS_group_"+gid).className = this.checkAllSelectedGroup(this._arr_group[gid]['member_id']) ? "FS_selected" : "FS_unselected";
		}
		
		if ( this.show_name != false ) {
			this.doVisualize();
		}
		this.callback( this.arrId() );
	}
	
	this.checkAllSelected = function() {
		for( var mid in this._arr_friend ) {
			if( this._arr_friend[mid]['active'] == 1 && this._arr_friend[mid]['selected'] == 0 ) return false;
		}
		return true
	}
	
	this.checkAllSelectedGroup = function( arr_group_id ) {
		for( var mid in arr_group_id ) {
			if( this._arr_friend[arr_group_id[mid]]['active'] == 1 && this._arr_friend[arr_group_id[mid]]['selected'] == 0 ) return false;
		}
		return true;
	}
	
	this.selectGroup = function(id) {
		var select = !this.checkAllSelectedGroup( this._arr_group[id]['member_id'] );
		var className = select ? "FS_selected" : "FS_unselected";
		getObject("FS_group_"+id).className = className;
		var friend = this._arr_group[id]['member_id'];
		for( var mid in friend ) {
			if( this._arr_friend[friend[mid]]['active'] == 1 ) {
				this._arr_friend[friend[mid]]['selected'] = select;
				getObject('FS_'+friend[mid]).className = className;
			}
		}
		this.check();
	}
	
	this.selectAll = function() {
		var select = !this.checkAllSelected();
		var className = select ? "FS_selected" : "FS_unselected";
		getObject("FS_all").className = className;
		for( var mid in this._arr_friend ) {
			if( this._arr_friend[mid]['active'] == 1 ) {
				this._arr_friend[mid]['selected'] = select;
				getObject('FS_'+mid).className = className;
			}
		}
		this.check();
	}
	
	this.write = function() {
		var arr_event = new Array();
		this.HTML = '';
		if ( this.opt_print_quicksearch ) {
			this.HTML += this.printQuicksearch();
			var arr_temp = new Array();
			arr_temp['id'] = 'FS_quicksearch_input';
			arr_temp['event'] = 'keyup';
			arr_temp['function'] = function() {thisO.quicksearch();};
			arr_event.push(arr_temp);
			if( this.opt_filter ) {
				var arr_temp = new Array();
				arr_temp['id'] = 'FS_filter';
				arr_temp['event'] = 'click';
				arr_temp['function'] = function() {thisO.filter();};
				arr_event.push(arr_temp);
			}
		}
		if ( this.opt_print_all_button ){ 
			this.HTML += this.printAllButton();
			var arr_temp = new Array();
			arr_temp['id'] = 'FS_all';
			arr_temp['event'] = 'click';
			arr_temp['function'] = function() {thisO.selectAll();};
			arr_event.push(arr_temp);
		}
		if ( this.friend_json.group && this.friend_json.group.length > 0 ) {
			var group = this.friend_json.group;
			for ( var i in group ) {
				var member_id = [];
				if ( typeof group[i].user == 'object' ) {
					member_id = group[i].user;
				} else {
					member_id.push(group[i].user);
				}
				
				var temp = [];
				temp['name'] = group[i].name;
				temp['member_id'] = member_id;
				temp['type'] = group[i].type;
				this._arr_group[group[i].id] = temp;
			}
		}
		
		
		if ( this.opt_print_all_button_group ) {
			//this.HTML += this.printAllButtonGroup();
			if ( this.friend_json.group && this.friend_json.group.length > 0 ) {
				var group = this.friend_json.group;
				this.HTML += '<div style="padding-bottom: 4px;">';
				for ( var i in group ) {
					var group_id = group[i].id;
					var name = group[i].name;
					var type = group[i].type;
					this.HTML += '<div id="FS_group_' + group_id + '" class="FS_unselected">All from ' + type + ' ' + name + '</div>';
					var arr_temp = new Array();
					arr_temp['id'] = group_id;
					arr_temp['event'] = 'click';
					arr_temp['function'] = 'selectGroup';
					arr_event.push(arr_temp);
				}
				this.HTML += '</div>';
			}
		}
		var member = this.friend_json.friend;
		this.HTML += '<div style="height: ' + this.opt_div_height + 'px; overflow: auto;">';
		for ( var i in member ) {
			var temp = [];
			temp['name'] = member[i].name;
			temp['selected'] = member[i].selected;
			temp['active'] = member[i].active;
			this._arr_friend[member[i].id] = temp;
			
			var friend_id = member[i].id;
			var name = member[i].name;
			var msg = member[i].msg;
			var className = 'FS_unselected';
			if ( member[i].active == 0 ) {
				className = 'FS_inactive';
			} else if ( member[i].selected == 1 ) {
				className = 'FS_selected';
			}
			this.HTML += '<div id="FS_' + friend_id + '" class="' + className + '"><span id="FS_name_' + friend_id + '">' + name + '</span>&nbsp;&nbsp;&nbsp;&nbsp;' + msg + '</div>';
			if( member[i].active == 1 ) {
				var arr_temp = new Array();
				arr_temp['id'] = friend_id;
				arr_temp['event'] = 'click';
				arr_temp['function'] = 'select';
				arr_event.push(arr_temp);
			}
		}
		this.HTML += '</div>';
		getObject(this.friend_container).innerHTML = this.HTML;
		this.check();
		this.addEvent(arr_event);
	}
	
	this.addClickSelectEvent = function( arr_event ) {
		var id_name = 'FS_' + arr_event['id'];
		$('#'+id_name).click( function() {thisO.select(arr_event['id']);} );
	}
	
	this.addClickSelectGroupEvent = function( arr_event ) {
		var id_name = 'FS_group_' + arr_event['id'];
		$('#'+id_name).click( function() {thisO.selectGroup(arr_event['id']);} );
	}
	
	this.addEvent = function( arr_event ) {
		for ( var i in arr_event ) {
			if ( arr_event[i]['event'] == 'click' && arr_event[i]['function'] == 'select' ) {
				this.addClickSelectEvent( arr_event[i] );
			} else if ( arr_event[i]['event'] == 'click' && arr_event[i]['function'] == 'selectGroup' ) {
				this.addClickSelectGroupEvent( arr_event[i] );
			} else if ( arr_event[i]['event'] == 'click' ) {
				this.addClickEvent( arr_event[i] );
			} else if ( arr_event[i]['event'] == 'keyup' ) {
				this.addKeyupEvent( arr_event[i] );
			}
		}
	}
	
	this.addClickEvent = function( arr_event ) {
		$('#'+arr_event['id']).click( arr_event['function'] );
	}
	
	this.addKeyupEvent = function( arr_event ) {
		$('#'+arr_event['id']).keyup( arr_event['function'] );
	}
	
	this.printQuicksearch = function() {
		var temp = '<div style="padding-bottom: 4px;" class="atrS">Schnellsuche:<input type="text" id="FS_quicksearch_input" class="input" style="font-size: 9px; padding: 0px; margin: 0px; height: auto;" />';
		if( this.opt_filter ) temp += this.printFilter();
		temp += '</div>';
		return temp;
	}
	
	this.printFilter = function() {
		return ' Inaktive<input id="FS_filter" type="checkbox" checked="checked" style="border:solid 1px #999999;" />';
	}
	
	this.printAllButton = function() {
		return '<div style="padding-bottom: 4px;"><div id="FS_all" class="FS_unselected">All</div></div>';
	}
	
	this.printAllButtonGroup = function() {
		if ( this.friend_json.group && this.friend_json.group.length > 0 ) {
			var num_group = this.friend_json.group.length;
			var temp = '';
			temp += '<div style="padding-bottom: 4px;">';
			for ( i = 0; i < num_group; i++ ) {
				var id = this.friend_json.group[i].id;
				var name = this.friend_json.group[i].name;
				var type = this.friend_json.group[i].type;
				temp += '<div id="FS_group_' + id + '" class="FS_unselected" onclick="FriendSelector.selectGroup(' + id + ');">All from ' + type + ' ' + name + '</div>';
			}
			temp += '</div>';
			return temp;
		} else {
			return '';
		}
	}
	
	this.doVisualize = function() {
		if( $(this.show_name_selector).length ) {
			var name = this.arrName();
			if ( this.show_name == 'TEXTAREA' || this.show_name == 'INPUT' ) {
				$(this.show_name_selector).val(name.join(', '));
			} else {
				$(this.show_name_selector).html(name.join(', '));
			}
		}
	}
	
	this.arrId = function() {
		var arr_selected = new Array();
		for( var mid in this._arr_friend ) {
			if( this._arr_friend[mid]['selected'] == 1 ) arr_selected.push(mid);;
		}
		return arr_selected;
	}
	
	this.arrName = function() {
		var arr_selected = new Array();
		var member = this._arr_friend;
		for ( var mid in member ) {
			if ( member[mid]['selected'] == 1 ) {
				arr_selected.push(member[mid]['name']);
			}
		}
		return arr_selected;
	}
	this.write();
}
