$.fn.checkboxToggle = function(opt){
   var check = $(this).next()[0].checked == true;
   var unck = $(this).next()[0].name;
   if (unck.substring(0,3) == 'pre') {
		unck = unck.replace("pre","cur");
   } else if (unck.substring(0,3) == 'cur') {
		unck = unck.replace("cur","pre");
   }
   if($("[name='"+unck+"']").attr("checked")) {
   		$("[name='"+unck+"']").trigger('click');
   		$("[name='"+unck+"']").prev("<img>").attr({src: check ? opt.checked : opt.unchecked, alt: "" });
   }
   if(check) {
   	$("#pointcol"+unck.substring(3,unck.length)).removeClass("highlightpoint");
   } else {
	$("#pointcol"+unck.substring(3,unck.length)).addClass("highlightpoint");
   }
   $(this)
   	.attr({ src: check ? opt.unchecked : opt.checked })
   	.next()[0].checked = !check;
}
$.fn.checkbox = function(opt){
   $(":checkbox", this)
	   // Hide each native checkbox
	   .hide()
	   // Iterate through checkboxes and do all the magical stuff
	   .each(function (){
		   $("<img>")
			   // Set image attributes
			   .attr({src: this.checked ? opt.checked : opt.unchecked, alt: "" })
			   // Bind toggle
			   .click(function() {
				   $(this).checkboxToggle(opt);
			   })
			   // Attach image
			   .insertBefore(this);
	   });
}
$.fn.cssCheckboxToggle = function(){
   this.toggleClass("checked");
   var check = $(":checkbox[@name='"+this.attr("for")+"']")[0];
   check.checked = !check.checked;
}
$.fn.cssCheckbox = function(){
   $(":checkbox", this)
	   // Hide native checkboxes
	   .hide()
	   // Find related labels and add all the fancy stuff
	   .each(function(){
		   var check = this;
		   var jlabel = $("label[@for='"+$(check).attr("name")+"']");
		   // Initial state check
		   if (check.checked) {
			   jlabel.addClass("checked");
		   }
		   jlabel
			   // Label hover state
			   .hover(
				   function() { $(this).addClass("over"); },
				   function() { $(this).removeClass("over"); }
			   )
			   // Label click state
			   .click(function(){
				   $(this).cssCheckboxToggle();
			   });
	   });
}
