/*  
 *  Input Custom 1.0
 *  Date : 06/04/2010  
 *
 * To Use: place in the head 
 *   <script type="text/javascript" src="js/jquery.inputCustom.js"></script>
 *    JavaScript Exp: 
 *       $("#demo").inputCustom({
 *          selected       : "( X )",
 *          noSelected   : "(   )",
 *       });
 *	   HTML Exp: 
 *       <fieldset id="demo">
 *         <label><input type="radio"></label>
 *       </fieldset>
 */ 
 
(function($){
	$.fn.inputCustom = function(parameters)
	{
		// attributes
		var element 		= $(this);
		var iniDefault		= {
			radioSelected				:  'X',
			radioNoSelected			:	'O',
			chackboxSelected		:	'*',
			chackboxNoSelected		:	'#'
		}
		var vDefault 		= $.extend({},iniDefault,parameters);

		$(element).find("label").each(function(){
			if( $(this).find("input").is(":radio") )
			{
				$(this).prepend("<span class=\"marcador\">"+ vDefault.radioNoSelected +"</span>");
			}
			else if( $(this).find("input").is(":checkbox") ){
				$(this).prepend("<span class=\"marcador\">"+ vDefault.chackboxNoSelected +"</span>");
			};
		});
		
		$(element).find("label").each(function(){
			if( $(this).find("input").is(":radio") || $(this).find("input").is(":checkbox") ){
				$(this).find("input").hide();
			}
		});
		
		$(element).find("label").click(function(){
			/*Radio Inputs Type.*/
			if($(this).find("input").is("input:radio"))
			{
				//percorre todos os campos
				var name = $(this).find("input").attr("name");
				$(this).parent().find("input").each(function(){
					if($(this).attr("name") == name){
						$(this).parent().find(".marcador").html( vDefault.radioNoSelected);
					}
				});
				
				//atribui o marcador de selecionado e marca o campo
				$(this).find(".marcador").html(vDefault.radioSelected);
				$(this).find("input").attr("checked", true);
			}
			
			
			/*Inputs do tipo checkbox - multiplas alternativas.*/
			else if($(this).find("input").is("input:chackbox"))
			{
				if( $(this).find("input").is(":checked") == false ){
					$(this).find("input").attr("checked",true);
					$(this).find(".marcador").html( vDefault.chackboxSelected);
				}
				else {
					
					//atribui o marcador de não selecionado e desmarca o campo
					$(this).find(".marcador").html( vDefault.chackboxNoSelected);
					$(this).find("input").attr("checked",false);
				}
			}
			
		})
	}
})(jQuery);