$.fn.customInput = function() {
	
	$(this).each(function() {
		
		if($(this).is('[type=checkbox], [type=radio]')) {
			
			var $input = $(this);
			var $label = $('label[for=' + $input.attr('id') + ']');
			
			var type = ($input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			
			$('<div class="custom-' + type + '"></div>').insertBefore($input).append($input, $label);
			
			var $inputs = $('input[name=' + $input.attr('name') + ']');
			
			$label.hover(
				function() {
					$(this).addClass('hover');
					if(type == 'checkbox' && $input.is(':checked')) {
						$(this).addClass('checkedHover');
					}
				},
				function() { $(this).removeClass('hover checkedHover'); }
			);
			
			$input.bind('updateState', function() {
				if($input.is(':checked')) {
					if($input.is(':radio')) {
						$inputs.each( function() {
							$('label[for=' + $(this).attr('id') + ']').removeClass('checked');
						} );
					} ;
					$label.addClass('checked');
				}
				else { $label.removeClass('checked checkedHover checkedFocus'); }
			} )
			.trigger('updateState')
			.click( function() { $(this).trigger('updateState'); } )
			.focus( function() {
				$label.addClass('focus');
				if(type == 'checkbox' && $input.is(':checked')) {
					$(this).addClass('checkedFocus');
				}
			} )
			.blur( function() { $label.removeClass('focus checkedFocus'); } );
			
		}
		
	} );
	
} ;
