       while i < length
         fn = result[functionNames[i]]
         params = functionParams[i]
+                    # Invoke last function as setter.
         params = params.concat([ value ])  if value isnt `undefined` and i is length - 1
         if fn is `undefined`
           message = "Control class \"" + @className() + "\" tried to chain to an undefined getter/setter function \"" + functionNames[i] + "\"."

      throw "Unable to find a class called \"" + value + "\"."  unless classFn
    classFn

  isControl: (element) ->
    Control(element).control() isnt `undefined`

  iterator: (fn) ->
    ->
      args = arguments

      elementClass = $element._controlClass() or defaultClass
      setClass = elementClass  if setClass is `undefined` or ( setClass:: ) instanceof elementClass
      i++
    setClass = setClass or defaultClass  # In case "this" had no elements.
    setClass this

  ###
  See if the control's size has changed since the last time we checked and,
  if so, trigger the sizeChanged event.
  
  A control can use this method to let layout-performing ancestors know
  that the control has changed its size, in case the ancestor will now
  need to update the layout.
  ###
  checkForSizeChange: ->
    @trigger "sizeChanged"  if @_updateSavedSize()
    this

  ###
  The set of classes on the control's element.
  If no value is supplied, this gets the current list of classes.
  If a value is supplied, the specified class name(s) are *added*
  to the element. This is useful for allowing a class to be added
  at design-time to an instance, e.g., <Foo class="bar"/>. The
  resulting element will end up with "bar" as a class, as well as
  the control's class hierarchy: <div class="Foo Control bar">.
  ###
  class: (classList) ->
    (if (classList is `undefined`) then @attr("class") else @toggleClass(classList, true))

  ###
  The name of the control's class.
  This shorthand is useful for quickly getting the name in the debugger
  when one is holding a reference to a control.
  ###
  className: ->
    @constructor.className

  ###
  Get/set the content of an HTML element.
  
  Like $.contents(), but you can also set content, not just get it.
  You can set content to a single item, an array of items, or a set
  of items listed as parameters. Setting multiple items at a time
  is an important case in compiled QuickUI markup. Input elements
  are also handled specially: their value (val) is their content.
  
  This function attempts to return contents in a canonical form, so
  that setting contents with common parameter types is likely to
  return those values back in the same form. If there is only one
  content element, that is returned directly, instead of returning
  an array of one element. If the element being returned is a text node,
  it is returned as a string.
  
  Usage:
   $element.content("Hello")              # Simple string
   $element.content(["Hello", "world"])   # Array
   $element.content("Hello", "world")     # Parameters
   Control("<input type='text'/>").content("Hi")   # Sets text value
  
  This is used as the default implementation of a control's content
  property. Controls can override this behavior.
  ###
  content: (value) ->
    if value is `undefined`
            # Getting contents. Just process first element.
      $element = @nth(0)
      result = undefined
      if $element.isInputElement()
                # Return input element value.
        result = $element.val()
      else
                # Return HTML contents in a canonical form.
        resultContainsStrings = false
        result = $element.contents().map((index, item) ->
          if item.nodeType is 3
                        # Return text as simple string
            resultContainsStrings = true
            item.nodeValue
          else
            item
        )
                    # Return the single string instead of an array.
        result = result[0]  if resultContainsStrings and result.length is 1
      result
    else
            # Setting contents.
            
            # Cast arguments to an array.
            
                 # set of parameters
                 
                 # convert jQuery object to array 
                 
                 # single array parameter
                 # singleton parameter
      array = (if (arguments.length > 1) then arguments else (if value instanceof jQuery then value.get() else (if $.isArray(value) then value else [ value ])))
      @each (index, element) ->
        $element = Control(element)
        if $element.isInputElement()
                    # Set input element value.
          $element.val value
        else
                    # Set HTML contents.

                    # We're about to blow away the contents of the element
                    # via $empty(), but the new content value might actually
                    # already be deeper in the element's existing content.
                    # To ensure that data, etc., get preserved, first detach
                    # the existing contents.
          $element.children().detach()
                    # Use apply() to feed array to $.append() as params.
          $element.empty().append.apply $element, array

  ###
  The control's culture.
  If jQuery Globalize is present, this defaults to the current culture.
  This can be overridden on a per-control basis, e.g., for testing purposes.
  
  Control classes can override this method to respond immediately to an
  explicit change in culture. They should invoke their base class' culture
  method, do whatever work they want (if the culture parameter is defined),
  then return the result of the base class call.
  ###
  culture: (culture) ->
    cultureDataMember = "_culture"
    controlCulture = undefined
