/*
 * jquery.passwordtoggle.js
 * PasswordToggle is used to toggle input fields between a text and password type
 * which increases usability for those people that may need to see the content of the password box
 * they're forced to enter
 *
 * @author		Adrian Scott
 * @created		May 17, 2010
 * @version		0.1
 * @req				jQuery 1.3+
 */
(function($) {
	$.fn.passwordtoggle = function(target) {
		
		return this.each(function() {
		
			$(this).click(function() {
				var $target = $(target),
					attrs = $target[0].attributes,
					$field = $(document.createElement('input'));

				// because IE doesn't allow you to change the "type" of an input element, have to do it this way
				// use the HTML DOM's attributes object to provide insight into what attributes exist for this element
				for (var i = 0; i < attrs.length; i++) {
					if (attrs[i].specified && attrs[i].nodeName != 'type' && attrs[i].nodeName != 'value') $field.attr(attrs[i].nodeName, attrs[i].nodeValue);
				}
				$field.attr('type', $target.is(':password') ? 'text' : 'password').val($target.val());
				$target.replaceWith($field);

				return false;
			});
		
		});

	};
})(jQuery);
