 
   # show-hide single div
   $('.show-content').click ->
+    node    = $(this).parents('.panel-container')
     content = $(this).parent().next('.panel_contents')
+
+    oldNodeHeight = $(node).height()
+    verticalLine  = getCSSRule('[id="' + $(node).attr('id') + '"]::before')
+
     if content.is(':hidden')
-      content.show('fast')
+      content.show 'fast', ->
+        changePseudoHeight(node, oldNodeHeight, verticalLine)
 
-      nodeId = $(this).parents('.panel-container').attr('id')
-      console.log document.styleSheets[0].cssRules[0]
-
-      # console.log verticalLine
-      # verticalLine = getCSSRule("[id='#{nodeId}']::before")
-      # verticalLine.style.height = '100px'
     else
-      content.hide('fast')
+      content.hide 'fast', ->
+        changePseudoHeight(node, oldNodeHeight, verticalLine)
 
   # show-hide nodes
   $('.show-childrens').click ->


  #--- Tree branches ---

  # find middle of node
  middleOfHeight = (node) ->
    Math.abs $(node).height() / 2

  distanceToTop = (node, target) ->
    Math.abs $(node).offset().top - $(target).offset().top

  # find distance btw node and its last child
  verticalBranchDist = (node, lastChild) ->
    distanceToTop(node, lastChild) + middleOfHeight(node)

  baseBranchProp =
    "content: ''; " +
    "position: absolute; " +
    "border: 0.1em solid gray; "

  # vertical line properies with dynamic height
  veticalBranchProp = (id, height) ->
    "margin-left: 2em; " +
    "height: #{height}px; " +
    "z-index: -1; " +

    baseBranchProp

  # add vertical line ( :before pseudoelement) to panel which has children
  addVerticalLine = (node, purposeNode) ->
    distance = verticalBranchDist(node, purposeNode)
    id       = $(node).attr('id')

    addCSSRule(
      "[id='#{id}']::before",
      veticalBranchProp(distance)
      )

  # add horizontal line (:after pseudoelement) to all panels except root
  addHorizontalLine = (node) ->
    id = $(node).attr('id')
    height = middleOfHeight(node)
    addCSSRule(
      "[id='#{id}']::after",
      horizontalBranchProp(height)
      )

  $('.panel-parent').each ->
    nodeId    = $(this).attr('id')
    lastChild = $(this).parent().find(
      ".panel-container[data-last-child=#{nodeId}]")

    addVerticalLine(this, lastChild) if $(lastChild).length

  $('.panel-container').each ->
    if $(this).hasClass('panel-root')
      true
    else
      addHorizontalLine(this)