       attroptional = {}
       attrrequired = {}
       attrgroups = {}
-      newtagname = $(node).attr("data-xmlel") || params['key']
+      editorNode = @editorNodeFromListNode node
+      newtagname = $(editorNode).attr("data-xmlel") || params['key']
       elementattrs = @editor.plugins.textorum.schema.defs[newtagname]?.attr
 
-      attrRequiredList = document.createElement("ul")
-      attrlist = document.createElement("ul")
-      attrform = document.createElement("div")
-
-      attrwindow = document.createElement("div")
-      attrlists = document.createElement("div")
-      attrlists.appendChild(attrRequiredList)
-      attrlists.appendChild(attrlist)
-      attrwindow.appendChild(attrlists)
-      attrwindow.appendChild(attrform)
+      attrRequiredList = $(document.createElement("ul"))
+      attrlist = $(document.createElement("ul"))
+      attrform = $(document.createElement("div"))
+
+      attrwindow = $(document.createElement("div"))
+      attrwindow.addClass "textorum_attributewindow"
+      attrlists = $(document.createElement("div"))
+      attrlists.append attrRequiredList
+      attrlists.append attrlist
+      attrwindow.append attrlists
+      attrwindow.append attrform
+      
+      attrlists.on 'click', 'li.optional', (e) ->
+        el = $(this)
+        window.foo = el
+        el.parents(".textorum_attributewindow").find("div.#{el.data('target')}").toggle()
+
       for own attr of elementattrs
-        attrform.appendChild(@attrFormElement(attr, elementattrs[attr], node))
+        attrform.append @attrFormElement(attr, elementattrs[attr], node)
         if elementattrs[attr].required
-          attrRequiredList.appendChild(@attrListElement(attr, elementattrs[attr], node))
+          attrRequiredList.append @attrListElement(attr, elementattrs[attr], node)
           attroptional[attr] = elementattrs[attr]
         else
-          attrlist.appendChild(@attrListElement(attr, elementattrs[attr], node))
+          attrlist.append @attrListElement(attr, elementattrs[attr], node)
           attrrequired[attr] = elementattrs[attr]
-      if attrform.childNodes.length
+      if attrform.children().length
+        window.attrform = attrform
         wm = @editor.windowManager
         w = wm.open {
           inline: true

    # Delete a tag
    removeTag: (ui, params) ->

    attrListElement: (name, params, node) ->
      el = document.createElement("li")
      el.appendChild(document.createTextNode(name))
      el

    attrFormElement: (name, params, node) ->
      node = $(node)
      node = @editor.dom.select("##{node.attr('name')}")[0]
      if params.ns
        prefix = @editor.plugins.textorum.nsmap[params.ns]
        if prefix is undefined

          # TODO: Better way to get the actual base document element?
          # TODO: Only set this when necessary, maybe?
          @editor.dom.select("body")[0].firstElementChild.setAttribute("xmlns:#{prefix}", params.ns)
          attrValue = editorNode[0].getAttributeNS params.ns, name
          if attrValue
            editorNode[0].removeAttributeNS params.ns, name
            editorNode.attr "#{prefix}:#{name}", attrValue
          else
        if prefix
          return "#{prefix}:#{name}"
      return name

    attrListElement: (name, params, node) ->
      origname = name
      node = @editorNodeFromListNode(node)
      name = @nameWithPrefix(name, params, node)
      attrValue = node.attr name
      el = $(document.createElement("li"))
      el.addClass "attr_#{origname.replace(/:/, '__')}"
      el.data "target", "attr_#{origname.replace(/:/, '__')}"
      el.append(document.createTextNode(name))
      if not params.required
        el.addClass "optional"
      if attrValue?
        el.addClass "visible"
      el

    attrFormElement: (name, params, node) ->
      origname = name
      node = @editorNodeFromListNode(node)
      name = @nameWithPrefix(name, params, node)
      attrValue = node.attr name

      if params.required or attrValue?
        display = "block"
      else
        display = "none"
      out = $(document.createElement("div"))
      out.attr "style", """display: #{display};"""
      out.addClass "attr_#{origname.replace(/:/, '__')}"
      out.data 'attribute_name', name
      out.addClass "attrform"
      label = $(document.createElement("label"))
      label.append document.createTextNode("#{name}")
      out.append label

      if params.value?.length
        sel = $(document.createElement("select"))
        sel.addClass "attrinput"
        sel.name = "attr_#{name}"
        if not params.required
          opt = $(document.createElement("option"))
          opt.val ""
          opt.append document.createTextNode(" -- empty -- ")
          sel.append opt
        for value in params.value
          opt = $(document.createElement("option"))
          opt.val value
          if value is attrValue
            opt.prop "selected", true
          opt.append document.createTextNode(value)
          sel.append opt
        out.append sel
      else if params.data isnt undefined
        sel = $(document.createElement("input"))
        sel.addClass "attrinput"
        sel.prop "type", "text"
        if attrValue?
          sel.val attrValue
        out.append sel
      else if params.$?
        sel = $(document.createElement("textarea"))
        sel.addClass "attrinput"
        if attrValue?
          sel.append document.createTextNode(attrValue)
        out.append sel

      out

