function brpCategoryWidget(opts, container){

	// properties
	var me=this;
	me.opts = cpyObj(opts, {});
	me.container = container;

	// event methods
	me.onCategoryChanged = null;
    me.setDefault();
    $('.poi').click(function(event){me.checkboxChanged(event, this)});
    $('.selectall', me.container).click(function(event){me.checkboxAll(event, this)});
    $('#afstapper').click(function(event){me.setAfstapper(event, this)});
};

brpCategoryWidget.prototype.addCategory = function(id, cat){
	var attrs = {'name':'cat'+id,'id':'cat'+id,'value':id};
	if (cat.visible) attrs['checked'] = 'checked';
	var cb = $('<li><input type="checkbox" class="noDisplay" />' + cat.name + '</li>'), me = this;
	$(cb.children()[0]).attr(attrs).change(function(){
		var cat = brpCategories[this.value];
		if (!cat || cat.visible == this.checked) return;
		cat.visible = this.checked;
	});
	$('ul.categorylist,ol.categorylist', me.container).append(cb)
	if (me.onCategoryChanged) me.onCategoryChanged();
}


brpCategoryWidget.prototype.checkboxChanged = function(event, cb){
	var cat = brpCategories[cb.value];
	if (!cat || cat.visible == cb.checked) return;
	cat.visible = cb.checked;
	if (this.onCategoryChanged) this.onCategoryChanged(cat)
}

brpCategoryWidget.prototype.checkboxAll = function(event, cb){
    var cont = $(cb).parent().parents('.poigroup'); //.next();
    var ischecked = cb.checked;
    $('input:checkbox',cont).each(function()
        {
            this.checked = ischecked;            
            var cat = brpCategories[this.value];
            if (!cat || cat.visible == ischecked) return;
            cat.visible = ischecked;
        }
    );
    if (this.onCategoryChanged) this.onCategoryChanged();
}


brpCategoryWidget.prototype.setAfstapper = function(event, cb){
    
    for(var I=43; I< 55; I++) {
        var cat = brpCategories[I];
        if(cat) {
		   cat.visible = !cat.visible;
	       
	    }
    }
    if (this.onCategoryChanged) this.onCategoryChanged();		
};

brpCategoryWidget.prototype.clearPoi = function() {

    $('.selectall').attr('checked',false);
    $('.poi').each(function(){
        this.checked = false;            
        if (brpCategories[parseInt(this.value)])
            brpCategories[parseInt(this.value)].visible = false;
    });
}

brpCategoryWidget.prototype.setDefault = function() {
    
    brpCategories[30].visible = true;

	for(var I=43; I< 55; I++) {
        var cat = brpCategories[I];
        if(cat) {
		   cat.visible = true;
	    }
    }	
	$('#afstapper').attr('checked',true);
	$('#vvv').attr('checked',true);
	if (this.onCategoryChanged) this.onCategoryChanged(cat);
} 

brpCategoryWidget.prototype.setRoutePois = function(p) {

	this.clearPoi();
	this.setDefault();
    for(var idx in p) {
      var cat = brpCategories[p[idx]];
	  if (cat) {
	   cat.visible = true;
	  }
	  $('.poi').each( function() {
	    if ($(this).attr('value') == p[idx]) this.checked = true;
	    });
    }
            	
	//
    if (this.onCategoryChanged) this.onCategoryChanged(cat);
}
