       return pos
 
 
-  onIdle = do ->
+  idle = do ->
     requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame# || (delegate) -> setTimeout(delegate, 17);
     ticking = false
     tickEvents = []

      @sprite = null


  # flatten element.attributes to a hash
  flattenattributes = (namednodemap)  ->
    attributes = {}
    for i in namednodemap
      attributes[i.name] = i.value
    attributes

  # a list of constraint scopes gathered at init time
  constraintScopes = []
  # initialize an element
  initFromElement = (el) ->
    initElement(el)
    # init constraints
    for constraint in constraintScopes
      constraint._bindConstraints()
    constraintScopes = []

  specialtags = ['handler', 'method', 'attribute', 'setter']
  # recursively init classes based on an existing element
  initElement = (el, parent) ->
    tagname = el.localName
    if not (tagname of lz)
      console.warn 'could not find class for tag', tagname, el
      return

    attributes = flattenattributes(el.attributes)

    # swallow builtin mouse attributes to allow event delegation, set clickable if an event is found
    for event in mouseEvents
      eventname = 'on' + event
      if eventname of attributes
        attributes.clickable = true unless attributes.clickable == false
        el.removeAttribute(eventname)

    parent ?= el.parentNode
    attributes.parent = parent if parent?
    # console.log 'parent', tagname, attributes, parent

    children = (child for child in el.childNodes when child.nodeType == 1)

    if tagname is 'class'
      # defer creation of children if selected by init()
      for child in children
        child.$defer = true
        
    processSpecialTags(el, attributes, attributes.type) unless tagname is 'class'

    parent = new lz[tagname](el, attributes)

    unless tagname is 'class'
      # create children now
      for child in children
        initElement(child, parent) unless child.localName in specialtags

    return


  # write default CSS to the DOM 
  writeDefaultStyle = ->
    style = document.createElement('style')
    style.type = 'text/css'
    style.innerHTML = '.sprite{ position: absolute; pointer-events: none; } .sprite-text{ width: auto; height; auto; white-space: nowrap; } .hidden{ display: none; }'
    document.getElementsByTagName('head')[0].appendChild(style)

  # init all views in the DOM recursively
  init = (selector = $('view')) ->
    for el in selector
      initFromElement(el) unless el.$defer or el.$view
    # console.log 'caches', compileCache

  # http://stackoverflow.com/questions/1248849/converting-sanitised-html-back-to-displayable-html
  htmlDecode = (input) ->
    # return if not input
    e = document.createElement('div');
    e.innerHTML = input;
    e.childNodes[0].nodeValue;

  processSpecialTags = (el, classattributes, defaulttype) ->
    classattributes.$types ?= {}
    classattributes.$methods ?= {}
    classattributes.$handlers ?= []
    children = (child for child in el.childNodes when child.nodeType == 1 and child.localName in specialtags)
    for child in children
      attributes = flattenattributes(child.attributes)
      child.setAttribute('class', 'hidden')
      # console.log child, attributes, classattributes

      switch child.localName
        when 'handler'
          args = (attributes.args ? '').split()
          script = htmlDecode(child.innerHTML)
          type = attributes.type ? defaulttype
          handler = 
            name: attributes.name
            script: compiler.transform(script, type)
            args: args
            reference: attributes.reference

          classattributes.$handlers.push(handler)
          # console.log 'added handler', attributes.name, script, attributes
        when 'method'
          args = (attributes.args ? '').split()
          script = htmlDecode(child.innerHTML)
          type = attributes.type or defaulttype
          classattributes.$methods[attributes.name] = [compiler.transform(script, type), args]
          # console.log 'added method', attributes.name, script, classattributes
        when 'setter'
          args = (attributes.args ? '').split()
          script = htmlDecode(child.innerHTML)
          type = attributes.type or defaulttype
          classattributes.$methods['set_' + attributes.name] = [compiler.transform(script, type), args]
          # console.log 'added setter', 'set_' + attributes.name, args, classattributes.$methods
        when 'attribute'
          classattributes[attributes.name] = attributes.value
          classattributes.$types[attributes.name] = attributes.type
          # console.log 'added attribute', attributes, classattributes

    # console.log('processSpecialTags', classattributes)
    return children


  class Class

      if @started and type is 'mousemove'
        @x = event.pageX
        @y = event.pageY
        idle(0, @sender) 
      else 
        @sendEvent(type, view)

