(function($) {	//	// plugin definition	//	$.fn.niceforms = function(obj) {		// iterate and reformat each matched element		return this.each(			function(i) {				var tag  = $.fn.niceforms.capitalize($(this).get(0).tagName.toLowerCase());								if (tag == "Input") {					var type = $.fn.niceforms.capitalize($(this).attr("type").toLowerCase());										if (type == "Text" || type == "Password" || type == "Submit") {						$(this).wrap('<div class="js' + type + 'WrapperLeft"><div class="js' + type + 'WrapperRight"></div></div>');					}										else if (type == "Checkbox") {						$(this).hide();						$(this).wrap('<div class="jsCheckboxWrapper"></div>');						$(this).parent().click(function(){							$.fn.niceforms.checkboxWrapperClicked(this);						});						$("label[for=" + $(this).attr('id') + "]").click(function(){							$.fn.niceforms.checkboxLabelClicked(this);						});												if ($(this).attr("checked") == "1") {							$(this).parent().addClass("checked");						}					}										else if (type == "Radio") {						$(this).hide();						$(this).wrap('<div class="jsRadioWrapper"></div>');						$(this).parent().click(function(){							$.fn.niceforms.radioWrapperClicked(this);						});						$("label[for=" + $(this).attr('id') + "]").click(function(){							$.fn.niceforms.radioLabelClicked(this);						});												if ($(this).attr("checked") == "1") {							$(this).parent().addClass("checked");						}					}				}								else if (tag == "Select") {					if ($(this).attr("id")) {}					else {						$(this).attr("id", "jsSelect" + i);					}					thisID = $(this).attr("id");										var defaultText = $(this).get(0).options[$(this).get(0).selectedIndex].text;															//create and build div structure					$(this).before('<div class="jsSelectWrapper" id="jsSelectWrapper' + i + '"><div class="jsSelectWrapperLeft"></div><div class="jsSelectWrapperRight"><a href="javascript:$.fn.niceforms.selectOptionsToggle(' + i + ')"></a></div><div class="jsSelectWrapperCenter" onclick="javascript:$.fn.niceforms.selectOptionsToggle(' + i + ')">' + defaultText + '</div></div>');										//hide the select field					$(this).hide();									$(this).prev(".jsSelectWrapper").append('<div class="jsSelectWrapperOptions"><ul></ul></div>');										$("option", this).each(						function(j) {							$("#jsSelectWrapper" + i + " ul").append('<li><a href="javascript:$.fn.niceforms.selectOptionsToggle(' + i + '); $.fn.niceforms.selectOptionClicked(\'' + thisID + '\',' + j + ',' + i + ');">' + $(this).html() + '</a></li>');						}					);				}								else if (tag == "Textarea") {					$(this).wrap('<div class="js' + tag + 'WrapperLeft"><div class="js' + tag + 'WrapperRight"></div></div>');				}			}		);	}; 	//	// define and expose our format function	// 	$.fn.niceforms.capitalize = function(str) {	    return str.replace(/\w+/g, function(a){	        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();	    });	}		// checkbox			$.fn.niceforms.checkboxWrapperClicked = function(obj) {			var input = $("input", obj);			$.fn.niceforms.checkboxToggle($(input));		}				$.fn.niceforms.checkboxLabelClicked = function(obj) {			var input = $("#" + $(obj).attr("for"));			$.fn.niceforms.checkboxToggle($(input));		}				$.fn.niceforms.checkboxToggle = function(obj) {			if($(obj).attr("checked") == true) {				$(obj).attr("checked", false);			}			else {				$(obj).attr("checked", true);			}			$.fn.niceforms.checkboxWrapperToggle($(obj));			$(obj).blur();		}				$.fn.niceforms.checkboxWrapperToggle = function(obj) {			if($(obj).attr("checked") == true) {				$(obj).parent().addClass("checked");			}			else {				$(obj).parent().removeClass("checked");			}		}		// radio			$.fn.niceforms.radioWrapperClicked = function(obj) {			var input = $("input", obj);			$.fn.niceforms.radioToggle($(input));		}				$.fn.niceforms.radioLabelClicked = function(obj) {			var input = $("#" + $(obj).attr("for"));			$.fn.niceforms.radioToggle($(input));		}				$.fn.niceforms.radioToggle = function(obj) {			if($(obj).attr("checked") == true) {				//$(obj).attr("checked", false);			}			else {				$("input[name=" + $(obj).attr("name") + "]").attr("checked", false)				$(obj).attr("checked", true);			}			$.fn.niceforms.radioWrapperToggle($(obj));			$(obj).blur();		}				$.fn.niceforms.radioWrapperToggle = function(obj) {			$("input[name=" + $(obj).attr("name") + "]").each(function(){				if($(this).attr("checked") == true) {					$(this).parent().addClass("checked");				}				else {					$(this).parent().removeClass("checked");				}			});		}		// select			$.fn.niceforms.selectOptionsToggle = function(i) {			var obj = $("#jsSelectWrapper" + i + " div.jsSelectWrapperOptions");			if ($(obj).css("display") == "block") {				$(obj).hide();			}			else {				$("div.jsSelectWrapperOptions:visible").hide();				$(obj).show();			}		}				$.fn.niceforms.selectOptionClicked = function(selectFieldId, linkNo, selectNo) {			//feed selected option to the actual select field			var obj = $("#" + selectFieldId);			$("option", $(obj)).each(				function(i) {					if(i == linkNo) {						$(this).attr("selected", "selected");					}					else {						$(this).attr("selected", "");					}				}			);						newText = $("option", $(obj)).get(linkNo).value;			$("#jsSelectWrapper" + selectNo + " .jsSelectWrapperCenter").html(newText);						$("#jsSelectWrapper" + selectNo + " .jsSelectWrapperOptions a.selected").removeClass("selected");			$("#jsSelectWrapper" + selectNo + " .jsSelectWrapperOptions a").slice(linkNo, linkNo+1).addClass("selected");		}//// end of closure//})(jQuery);
