// 
/**
 * jQuery.filterOut
 * Copyright (c) 2009 Allison Richmond - arichmond79@gmail.com - allisonrichmond.com
// Dual licensed under MIT and GPL.
 * Date: 6/12/2009
 *
 * @projectDescription Filters out and array of objects based on a text comparison (within each object, to an outside 'control'), optionally removes the container if no objects remain
 * @projectURI
 * @author Allison Richmond
 * @version 1.0
 *
 * @id jQuery.fn.makeIndex
 * @param {Object} 
 * @return {jQuery} returns FALSE if no objects remain to be filtered
 *
 * @example $('#container div').filterOut({ compare: 'Uncategorized', remove: '#container' });
 *
 * @example $('ul li').filterOut({ compare: myVar, toThis: 'a.name' });
 
		$('td').filterOut({
			compare: DESC,
			toThis: 'a span',
			remove: '#other-products'
		});
 *
 **/
(function($){
$.fn.filterOut = function(options) {

	var defaults = {
		compare:	true,	// control text // no default // is required
		toThis:		true,	// text to compare
		remove:		true	// container to remove if no objects remain after filtering
	};
	var options = $.extend(defaults, options);
	
	var x = $(this).length;
	var idx = 0;
	compare = options.compare;
	$(this).each(function(i){
		
		txt	= $(this).find( options.toThis ).text();
		if (txt == compare) {
			$(this).remove();
			x--;
			idx = i;
		}
	});
	
	$(this).filter(':last').insertBefore( $(this).parent().children().eq(idx) );
		
	if ((x<=0) && options.remove) {
		if (options.remove === true) {
			$(this).parent().remove();
		} else {
			$(options.remove).remove();
		}
		return false;
	}

};
})(jQuery);