commentContextArray = [];
fwiccCommentFilters = [];

//filter the comments according to the title and value
function fwicc_filter_comments( title , value){

	var updated = false;
	for(var i = 0; i < fwiccCommentFilters.length; i++){
		if ( fwiccCommentFilters[i][0] == title ) {
			fwiccCommentFilters[i][1] = value;
			updated = true;
		}
	}
	
	if (!updated) {
		fwiccCommentFilters.push([title,value]);
	}
	
	fwicc_run_filter();
	
}

function fwicc_run_filter(){

	var deleteArray = [];
	var checkedArray = [];
	var filtersExist = false;
	//loop through each applicable comment
	commentContextLoop:
	for(var i = 0; i < commentContextArray.length; i++){
		//mark comment as checked
		checkedArray.push('comment-'+commentContextArray[i][0]);
		//loop through each filter condition
		for(var x = 0; x < fwiccCommentFilters.length; x++){
			//reset the comparison counted
			var comparison_counter = 0;
			//loop throught the filterable options		
			for(var y = 0; y < commentContextArray[i].length; y++){
				//if a comparison can be made
				if ( commentContextArray[i][y][0] == fwiccCommentFilters[x][0] && fwiccCommentFilters[x][1] != 'Any' ){
					//make it and increment the counted
					comparison_counter++;
					if ( commentContextArray[i][y][1] != fwiccCommentFilters[x][1] ){
						deleteArray.push('comment-'+commentContextArray[i][0]); continue commentContextLoop;
					} 
				} 
			}
			//if we have reached this point, not bugged out, and not made any comparisons then check for any
			if ( comparison_counter == 0 && fwiccCommentFilters[x][1] != 'Any' ) {
				//no comparisons, not set to any, kill the comment
				deleteArray.push('comment-'+commentContextArray[i][0]); continue commentContextLoop;
			}
			//make sure that something has been filtered
			if ( fwiccCommentFilters[x][1] != 'Any' ) {
				filtersExist = true;
			}
		}
	}
	//do the delety bit

	
	jQuery('.commentlist li').each(function(i){
		if ( jQuery.inArray(jQuery(this).attr("id"), deleteArray) != -1 ||  ( jQuery.inArray(jQuery(this).attr("id"), checkedArray) == -1 && filtersExist == true)  ){
			jQuery(this).hide();
		} else {
			jQuery(this).show();
		}
	});
	

	
}