$.fn.removeCol = function(col){
    // Make sure col has value
    if(!col){ col = 1; }
    $('tr td:nth-child('+col+'), tr th:nth-child('+col+')', this).remove();
	
    return this;
};

$.fn.tablesizer = function() {
	self = this;
	form = $("<form id='select_columns'></form>");
	$(this).before(form);
	$("th", this).each(
		function(i) {
			form.append("<label style='display:inline; padding-right: 10px;' ><input type='checkbox' value='"+$(this).html().split(" ")[0]+"' checked='checked' />"+$(this).html()+"</label>");
			$(this).attr("title", $(this).html().split(" ")[0]);
		}
	);
	tableHTML = $(this).html();
	formHTML = form.html();
	
	form.change(
		function(){
			
			$(self).html(tableHTML);
			$(this).children("label").children(":not(:checked)").each(
				function() {
					rows = new Array;
					$("th", self).each(
						function(i) {
							rows.push($(this).attr("title"));
						}
					);

					self.removeCol(rows.indexOf(this.value)+1);
				}
			);
		}
	);
}


$.fn.tablesizer2 = function() {
	self = this;
	form = $("<form id='select_columns'></form>");
	$(this).before(form);
	$("tr:first td", this).each(
		function(i) {
			form.append("<label style='display:inline; padding-right: 10px;' ><input type='checkbox' value='"+$(this).html().split(" ")[0]+"' checked='checked' />"+$(this).html()+"</label>");
			$(this).attr("title", $(this).html().split(" ")[0]);
		}
	);
	tableHTML = $(this).html();
	formHTML = form.html();
	
	form.change(
		function(){
			
			$(self).html(tableHTML);
			$(this).children("label").children(":not(:checked)").each(
				function() {
					rows = new Array;
					$("tr:first td", self).each(
						function(i) {
							rows.push($(this).attr("title"));
						}
					);

					self.removeCol(rows.indexOf(this.value)+1);
				}
			);
		}
	);
}
