/******************************************************************************
 * Checkbox Radiobutton 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo independente
 *
 * COMO UTILIZAR
 * 
 * Use a classe chk-rdo-replace nos checkboxes e radiobuttons que deseja fazer o replace
 *
 *
 * PARAMETROS
 *
 * --
 *
 ******************************************************************************/

(function($) {

	$.extend({

		// Checkbox radiobutton replace
		checkboxRadiobutton: function() {
			/* Radio replace */
			var rdoReplace = $("input:radio.chk-rdo-replace");
		
			rdoReplace.css("opacity","0");
			rdoReplace.before("<span class='rdo-replace'>Radio</span>");
			
			rdoReplace.change(function() {
				rdoClick($(this).attr("name"));
			});
			/* IE fix */
			rdoReplace.click(function() {
				rdoReplace.change();
			});
		
			$(".rdo-replace").click(function() {
				$(this).next().attr("checked","checked");
				rdoReplace.change();
			});
		
			function rdoClick(name) {
				$("input:radio.chk-rdo-replace[name='"+name+"']").each(function() {
					if ($(this).attr("checked")) {
						$(this).prev().addClass("rdo-checked");
					} else {
						$(this).prev().removeClass("rdo-checked");
					}
				});
			}
			/* // Radio replace */
		
		
			/* Checkbox replace */
			var chkReplace = $("input:checkbox.chk-rdo-replace");
			
			chkReplace.css("opacity","0");
			
			chkReplace.each(function() {
				if ($(this).attr("checked")) {
					$(this).before("<span class='chk-replace chk-checked'>Checkbox</span>");
				} else {
					$(this).before("<span class='chk-replace'>Checkbox</span>");
				}
			});
			
			chkReplace.each(function() {
				$(this).change(function() {
					if ($(this).attr("checked")) {
						$(this).prev().addClass("chk-checked");
					} else {
						$(this).prev().removeClass("chk-checked");
					}
				});
			});
			/* IE fix */
			chkReplace.click(function() {
				$(this).change();
			});
			
			$(".chk-replace").click(function() {
				if ($(this).next().attr("checked")) {
					$(this).next().removeAttr("checked");		
				} else {
					$(this).next().attr("checked","checked");
				}
				$(this).next().change();
			});
			/* // Checkbox replace */
		}
	});
})(jQuery);

// $.checkboxRadiobutton();
