/**
 * Select assignees
 */
jQuery.fn.selectSubscribers = function(s) {
  var settings = jQuery.extend({  }, s);  
  
  return this.each(function() {
    
    var wrapper = $(this);
    wrapper.find('div.user_group li').each(function () {
      var list_element = $(this);
      
      if ($.inArray(list_element.attr('user_id'), s.can_see_private) !== -1) {
        list_element.attr('can_see_private', 1);
      } else {
        list_element.attr('can_see_private', 0);        
      } // if
    });
    
    
    /**
     * filter list by visibility
     * 
     * @param integer visibility
     * @return null
     */
    var filter_by_visibility = function (visibility) {
      var wrapper = $(this);
      
      wrapper.find('div.user_group').each(function () {
        var group = $(this);
        group.show();
        
        if (visibility == 1) {
          group.find('li').show();
        } else {
          group.find('li[can_see_private="0"]').hide();
          group.find('li[can_see_private="1"]').show();
        } // if
        
        if (group.find('li:visible').length) {
          group.show();
        } else {
          group.hide();          
        } // if
      });
      
      // uncheck and unsubscribe hidden checked users
      wrapper.find('input[type="checkbox"]:not(:visible):checked').attr('checked', false);
    }; // filter_by_visibility
    
    // provide public interface for this function
    this.filterByVisibility = filter_by_visibility;
  });
  
};