(function($) {
	$.fn.cloneInputs = function() {
		$(this).each(function() {
			var $parent = $(this);
			var $checkbox = $(this).find(':checkbox,:radio');
			var $inputs = $(this).find('.inputs');
			
			function toggleInputs() {
				var checked = $checkbox.is(':checked');
				$inputs.toggle(checked);
				if (! checked) {
					$parent.find('.inputs > :text').val('');
				}
			}
			if ($checkbox.is(':radio')) {
				// Put the event on all related radios
				var name = $checkbox.attr('name');
				$('[name=' + name + ']').click(toggleInputs);
			} else {
				// Enable the checkbox click event
				$checkbox.click(toggleInputs);
			}
			toggleInputs();
			
			$(this).find('.inputs > :text:last').focus(function() {
				$(this).clone(true).insertAfter(this);
				$(this).unbind('focus');
			});
		});
	}
	
	$.fn.toggleCheckboxNotes = function() {
		$(this).each(function() {
			var checked = $(this).is(':checked');
			$(this).nextAll('input, a, span').toggle(checked);
			
			$(this).click(function() {
				var checked = $(this).is(':checked');
				$(this).nextAll('input, a, span').toggle(checked);
				if (! checked) {
					$(this).nextAll('input').val('');
				}
			});
		});
	}
	
	$.fn.toggleRadioNotes = function() {
		$(this).each(function() {
			var $parent = $(this);
			
			var checked = $(this).find(':radio').is(':checked');
			if (! checked) {
				$parent.find(':text').parent().hide();
			}
			
			$(this).find(':radio').click(function() {				
				$parent.find(':text').parent().show();
			});
		});
	}
	
	$.fn.toogleTooglers = function() {
		$(this).each(function() {
			var $parent = $(this);
			var $name = "#" + $parent.attr('id');
			$parent.click(function() {
				$($name + ' a').toggleClass("hide");				
			});
		});
	}
	
})(jQuery);
