jQuery.fn.checkbox = function() {
	$(this).each(function(i) {
		if ($(this).is("[type=checkbox],[type=radio]")) {
			var input = $(this);

			/** Get the associated label using the inputs id */
			var label = $("label[for=" + input.attr("id") + "]");

			/** Get type, for classname suffix */
			var inputType = input.is("[type=checkbox]") ? "checkbox" : "radio";

			/** Wrap the input + label in a div */
			$("").insertBefore(input).append(input, label);

			/** Find all inputs in this set using the shared name attribute */
			var allInputs = $("input[name='" + input.attr("name") + "']");

			/** Necessary for browsers that don"t support the :hover pseudo class on labels */
			label.hover(
				function() { $(this).addClass("hover");    },
				function() { $(this).removeClass("hover"); }
			);

			/** Bind custom event, trigger it, bind click, focus, blur events */
			input.bind("updateState", function() {
				if (input.is(":checked")) {
					if (input.is(":radio")) {
						allInputs.each(function() {
							$("label[for='" + $(this).attr("id") + "']").removeClass("checked");
						});
					};

					label.addClass("checked");
				} else {
					label.removeClass("checked");
				}
			})
			.trigger("updateState")
			.click(function() {
				$(this).trigger("updateState");
			})
		}
	});
};

