
jQuery.fn.extend({
  tableification: function(params){
    var jQ = jQuery;
    return this.each(function(){
		//setup classes on table elements
		var me = jQ(this);
		
		//check if header already exists before adding header
		if (!me.prev().hasClass('tableheadcapwbubble'))
			jQ("<div class='tableheadcap'><div></div></div>")
				.insertBefore( me );
		
		//add footer
		jQ("<div class='tablefootcap'><div></div></div>")
			.insertAfter( me );
			
		//wrap them for soft bordrs
		me.wrapAll( "<div class='tablewrap1'></div>" )
			.wrapAll("<div class='tablewrap2'></div>");

		//cycle thru each tr add utility clases
		me.children().eq(0).children().each(function(){
			if (jQ(this).attr('tagName') != 'TR') return;
			var tr = jQ(this);
			if (tr.length == 0) return;//dont'process empty trs
			tr.children().eq(0).addClass('first');
			tr.children().eq(tr.children().length-1).addClass('last');
		});
		
		//assign the 2nd tr to be 
		if (me.children().eq(0).children().length > 2) {
			var firsttr = me.children().eq(0).children().eq(1);
			firsttr.addClass('firstrow');
			var lasttr = me.children().eq(0).children().eq(me.children().eq(0).children().length -1);
			lasttr.addClass('last');
		}
    });
  }
});