jQuery.fn.extend({
  customFormStyle: function() {
    $(this).filter(':input')
      .bind('click change', function (event) { $(this).setCFSWrapperClassName(this); event.stopPropagation(); })
      .bind('mousedown',    function() { $(this).parent().addClass('mousedown'); })
      .bind('mouseup blur', function() { $(this).parent().removeClass('mousedown'); })

      .addClass('invisible')
      .wrap('<span></span>')
      .css('height', $(this).parent().css('height'))
      .each(function () { $(this).setCFSWrapperClassName(); })
      ;
  },

  setCFSWrapperClassName: function() {
    var className = 'custom-form-style ' + $(this).attr('type').toLowerCase() + ' ';
    if ($(this).attr('checked')) {      className += 'selected '; }
    className += $(this).attr('class').replace('invisible', ''); 
    $(this).parent().attr('class', className);
  },
});

