app = angular.module('<%= moduleName %>.controllers')

DemoController =

  name: 'DemoController'

  inject: ['$scope']

  # check out the unit tests to see how this method is tested
  add: (x, y) -> @$.x = x + y

  init: ->

    ##################################################
    # just for show - never do this in your own code #
    ##################################################
    $(document).mousemove (e) ->
      $('.background-image').css(
        Modernizr.prefixed('transform'),
        "scale(5) translate(#{-e.pageX/500}px, #{-e.pageY/500}px)"
      )
    delay = (ms, fn) -> window.setTimeout(fn, ms)
    transitionEndEvents =
      'WebkitTransition' : 'webkitTransitionEnd'
      'MozTransition'    : 'transitionend'
      'OTransition'      : 'oTransitionEnd otransitionend'
      'msTransition'     : 'MSTransitionEnd'
      'transition'       : 'transitionend'
    coords = (e, type) ->
      touchEvent =
        e.type.toLowerCase() is 'touchstart'
      switch type
        when 'top' then x = 'pageY'
        when 'left' then x = 'pageX'
      if touchEvent
        e.originalEvent.touches[0][x]
      else e[x]
    $(document).on 'mousedown touchstart', (e) ->
      $clicker = $('<div class="clicker"></div>')
      $clicker
        .css(left: coords(e, 'left'), top: coords(e, 'top'))
      $('body').append($clicker)
      delay 0, ->
        $clicker.on(
          transitionEndEvents[Modernizr.prefixed('transition')],
          -> $clicker.remove()
        )
        $clicker.addClass('is-active')
    ##################################################
    # use directives instead!!!!!                    #
    ##################################################

    console.log 'hello world from DemoController.coffee'

    @$.test = "Hello, world!"


module.exports = app.classy.controller DemoController
