/*-------------------------------------------------------------------- 
 * jQuery plugin: customInput()
 * by Maggie Wachs and Scott Jehl, http://www.filamentgroup.com
 * Copyright (c) 2009 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 * Article: http://www.filamentgroup.com/lab/accessible_custom_designed_checkbox_radio_button_inputs_styled_css_jquery/  
 * Usage example below (see comment "Run the script...").
--------------------------------------------------------------------*/


jQuery.fn.customInput = function(){
	$(this).each(function(i){	
		if($(this).is('[type=checkbox]')){
			var input = $(this);
			
			// get the associated label using the input's id
			var fakelabel = '<label for="'+input.attr('id')+'" id="label_'+input.attr('id')+'">checkboxlabel</label>';
			
			//get type, for classname suffix 
			var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			
			// wrap the input + label in a div 
			$('<div class="custom-'+ inputType +'"></div>').insertBefore(input).append(input, fakelabel);
			
			var label = $('#label_'+input.attr('id'));
			
			if (input.is(':checked')) {
				label.addClass('checked');
			}
			else { label.removeClass('checked checkedHover checkedFocus'); }
			
			input.change( function() {
				if (input.is(':checked')) {
					label.addClass('checked');
				}
				else {
					label.removeClass('checked');
				}
			});
		}
	});
};
