(function ($) {
  $.fn.CheckHighlight = function (options) {
	// handle option changes
	options = $.extend({
	  className: 'highlight',
	  clickableCell: true
	}, options);
	// execute for each item
	return this.each(function (i) {
	  var input = $(this);
	  var row = input.parents('tr');	  
	  // make sure that it is an input
	  if (/checkbox|radio/i.test(input.attr('type'))) {
		// if we want the cell to be clickable arount the input
		if (options.clickableCell) {
		  input.attr('id') ? null : input.attr('id', 'CheckHighlight_' + i);
		  input.wrap('<label for="' + input.attr('id') + '"></label>');
		}
		// function  to highlight the input's row
		highlight = function () {
		  var el = input.get(0);
		  // for radios find each row
		  if (el.type == 'radio') {
			row.parent().find('tr').each(
			  function (i) {
				var r = $(this);
				// with at least one checked input - highlight the row / or remove the highlight
				r.find('input[@checked]').length ? r.addClass(options.className) : r.removeClass(options.className);
			  }
			);
		  } else {
			// for checkboxes just look at the current row
		    row.find('input[@checked]').length ? row.addClass(options.className) : row.removeClass(options.className);	
		  }
		};
		
		// when clicked
	    input.click(highlight);
		// when loaded
		highlight();
	  }
	});
  }
}) (jQuery);
