 # License: MIT
 # Author: Maartyl (c) 2016
 # VERSION: 1.0.0
+
+
+## LIB
+###*
+# http://stackoverflow.com/a/2381862/2692364
+# Fire an event handler to the specified node. Event handlers can detect that the event was fired programatically
+# by testing for a 'synthetic=true' property on the event object
+# @param {HTMLNode} node The node to fire the event handler on.
+# @param {String} eventName The name of the event without the "on" (e.g., "focus")
+###
+
+fireEvent = (node, eventName, evo) ->
+  # Make sure we use the ownerDocument from the provided node to avoid cross-window problems
+  doc = if node.ownerDocument
+    node.ownerDocument
+  else if node.nodeType is 9
+    # the node may be the document itself, nodeType 9 = DOCUMENT_NODE
+    node
+  else
+    throw new Error('Invalid node passed to fireEvent: ' + node.id)
+
+  if node.dispatchEvent
+    # Gecko-style approach (now the standard) takes more work
+
+    # Different events have different event classes.
+    # If this switch statement can't map an eventName to an eventClass,
+    # the event firing is going to fail.
+    ev = evo or do->
+      eventClass = switch eventName
+        # Dispatching of 'click' appears to not work correctly in Safari. Use 'mousedown' or 'mouseup' instead.
+        when 'click', 'mousedown', 'mouseup'
+          'MouseEvents'
+        when 'focus', 'change', 'blur', 'select'
+          'HTMLEvents'
+        else
+          throw new Error "fireEvent: Couldn't find an event class for event '#{eventName}'."
+      ev = doc.createEvent eventClass
+      ev.initEvent eventName, true, true
+      # All events created as bubbling and cancelable.
+      ev.synthetic = true
+      ev
+      # allow detection of synthetic events
+    # The second parameter says go ahead with the default action
+    node.dispatchEvent ev, true
+  else if node.fireEvent
+    # IE-old school style
+    event = doc.createEventObject()
+    event.synthetic = true
+    # allow detection of synthetic events
+    node.fireEvent 'on' + eventName, event
+  else
+    node[eventName]() #node.click() etc.
+
+# ---
+# generated by js2coffee 2.2.0
+## /LIB
+
+DBG_SHOW_FOUND = false
 
 # keeps track of last MAX positions and derivations, to compute overscroll
 class Buf

  compare: (e) -> e.scrollLeftMax ##e.scrollWidth - e.clientWidth #0 if same
  scroll: (dist) => @elem.scrollLeft+=dist #auto manages bounds
  fallback: (dist) -> window.scrollBy(dist, 0)
class ScrollerY extends Scroller
  compare: (e) -> e.scrollTopMax ##e.scrollHeight - e.clientHeight #0 if same
  scroll: (dist) => @elem.scrollTop+=dist
  fallback: (dist) -> window.scrollBy(0, dist)

# exists for a single drag
class Dragger

    if ev.button isnt MB then return
    @serv = @serv.start ev
    document.addEventListener 'mousemove', @move
    false
  up: (ev) =>
    if ev.button isnt MB then return
    document.removeEventListener 'mousemove', @move
    @serv = @serv.stop ev

  #API
  show_found:(state)->
    unless state?
      DBG_SHOW_FOUND
    else
      DBG_SHOW_FOUND = state

l = new Listener()

maa = 'Maa_scroll_drag'
