/**
 * Toggle Optional Fields
 *
 * Shows and Hides optional form elements (those that have a class name 'optional')
 */
jQuery.toggleOptionalFields = function(){

    // Create the toggle link
    var newLink = $(document.createElement('a')).attr('href','#').text('Remove optional fields?');
    
    // Add the event handlers
    newLink.click(function() {
    
      // Update the text
      var ctnr = $('#linkContainer a');
      var linkText = ctnr.text();
      var newText = (linkText == 'Remove optional fields?') ? 'Display optional fields?' : 'Remove optional fields?';
      ctnr.text(newText);
      
      // Hide/show optional fields
      $('form .optional').toggle('fast');
      
      return false;
    });
    
    // Insert toggle link into the DOM
    $('#linkContainer').append(newLink);
};
