         elements.push element  if element isnt `undefined`
         i++
       $result = Control(elements).cast()
+            # To make the element function $.end()-able, we want to call
+            # jQuery's public pushStack() API. Unfortunately, that call
+            # won't allow us to both a) return a result of the proper class
+            # AND b) ensure that the result of calling end() will be of
+            # the proper class. So, we directly set the internal prevObject
+            # member used by end().
       $result.prevObject = this
       $result
     else

        @referencedElement elementReference, elements
    logicalParent.referencedElement elementReference, control
  control
evaluateControlJsonProperties = (json, logicalParent) ->
  json = content: json  unless $.isPlainObject(json)
  properties = {}
  for key of json
    properties[key] = evaluateControlJsonValue(json[key], logicalParent)
  properties
evaluateControlJsonValue = (value, logicalParent) ->
  result = undefined
  if $.isArray(value)
    result = []
    i = 0

    while i < value.length
      item = value[i]
      itemValue = evaluateControlJsonValue(item, logicalParent)
      itemValue = itemValue[0]  if itemValue instanceof jQuery
      result.push itemValue
      i++
  else if $.isPlainObject(value)
    result = evaluateControlJson(value, logicalParent)
  else
    result = value
  result
copyExcludingKeys = (obj, excludeKeys) ->
  copy = {}
  for key of obj
    copy[key] = obj[key]  unless excludeKeys[key]
  copy
isElementInDocument = (element) ->
  !!document.body and (document.body is element or $.contains(document.body, element))
findMethodImplementation = (methodFn, classFn) ->
  prototype = classFn::
  for key of prototype
    if prototype[key] is methodFn
      methodInherited = (if classFn.superclass then prototype[key] is classFn.superclass::[key] else false)
      unless methodInherited
        return (
          classFn: classFn
          fnName: key
        )
  (if classFn.superclass then findMethodImplementation(methodFn, classFn.superclass) else null)
$.fn.control = (arg1, arg2) ->
  if arg1 is `undefined`
    $cast = Control(this).cast(jQuery)
    (if ($cast instanceof Control) then $cast else null)
  else if $.isFunction(arg1)
    controlClass = arg1
    properties = arg2
    controlClass.createAt this, properties
  else
    Control(this).cast().properties arg1

$.expr[":"].control = (elem) ->
  controlClass = Control(elem)._controlClass()
  (if controlClass then controlClass is Control or controlClass:: instanceof Control else false)

Control = $.sub()
$.extend Control,
  chain: ->
    args = arguments
    sideEffectFn = undefined
    if $.isFunction(args[args.length - 1])
      args = [].slice.call(arguments)
      sideEffectFn = args.pop()
    functionNames = []
    functionParams = []
    i = 0
    length = args.length

    while i < length
      parts = arguments[i].split("/")
      functionNames[i] = parts.shift()
      functionParams[i] = parts
      i++
    chain = (value) ->
      result = this
      i = 0

        i++
      results
    else
            # Setter
      i = 0
      length1 = @length
      length2 = values.length
