     beta = (Math.asin(normalized.y) + Math.PI / 2) * sign
     betaDeg = beta * 360 / (2 * Math.PI)
     # preparing and changing css
-    @contains.rotate.$el.css @transformName, "rotate(#{betaDeg}deg)"
+    @contains.$el.css @transformName, "rotate(#{betaDeg}deg)"
 
   # @todo event were attach on document
   endRotate:=>


  signedDir: (vector, comp)->
    vector[comp] / Math.abs(vector[comp])

# BlockView
class @BlockView extends Backbone.View

    $(document).off('mouseleave', @endResize)
    @options.workspace.off('mousemove', @resize)

  # @chainable
  render: ->
    @$el.append @contains.render().el
    @


# global subcontainer to which rotations will be applied
# el
#   display
#     content
#     borders
#   handlerContainer
#     tracker
#     rotateHandle
#     dragbars
#     handles
class RotateContainerView extends Backbone.View
  initialize: ->
    @$el.attr style: 'width: 100%; height: 100%; position: absolute;'
    @handlerContainer = new HandlerContainerView
    @display = new DisplayContainerView

  # @chainable
  render: ->
    @$el
      .append(@display.render().el)
      .append(@handlerContainer.render().el)
    @

# display container that holds the content and the borders of the
# content
class DisplayContainerView extends Backbone.View

  initialize: ->
    @$el.attr style: 'width: 100%; height: 100%; position: absolute; overflow: hidden; bottom:0px;'
    @borders = for className, i in Cards.slice 0, 4
      new BorderView card: i
    @content = new ContentView

  # @chainable
  render: ->
    @$el.append @content.render().el
    @$el.append border.render().el for border in @borders
    @

# the content that we display
class ContentView extends Backbone.View
  tagName: 'img'

  initialize: ->
    @$el.attr
      src: 'assets/images/cat.jpg'
      style: 'border: none; visibility: visible; margin: 0px; padding: 0px; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; -webkit-user-select:none;'

# the borders are the line that are displayed around the content
class BorderView extends Backbone.View
  className: ->
    ['jcrop-hline', 'jcrop-hline bottom', 'jcrop-vline', 'jcrop-vline right'][_.indexOf Cards, @options.card]

  # @params options {object}
  # @params options.card {srting}
  initialize: ->
    @$el.attr style: 'position:absolute; opacity:0.4;'


class HandlerContainerView extends Backbone.View
  initialize: ->
    @$el.attr style: 'width: 100%; height: 100%; bottom: 0px; position: absolute; display: block;'
    @dragbars = for card, i in Cards.slice(0, 4)
      new DragbarView card: card
    @handles = for card, i in Cards
      new HandleView card: card
    @rotateHandle = new RotateHandleView
    @tracker = new TrackerView

  # @chainable
  render: ->
    @$el.append dragbar.render().el for dragbar in @dragbars
    @$el.append handle.render().el for handle in @handles
    @$el
      .append(@rotateHandle.render().el)
      .append(@tracker.render().el)
    @


# create the dragbars
class DragbarView extends Backbone.View
  className: -> "ord-#{@options.card} jcrop-dragbar dragbar"

  # @params options {object}
  # @params options.card {srting}
  initialize: ->
    @$el.attr style: 'position:absolute;'
    @$el.css cursor: @options.card + '-resize'


# create the handles
class HandleView extends Backbone.View
  className: -> "ord-#{@options.card} jcrop-handle handle"

  # @params options {object}
  # @params options.card {srting}
  initialize: ->
      @$el.attr style: 'position:absolute;'
      @$el.css  cursor: @options.card + '-resize'


# the special handler responsible for the rotation
class RotateHandleView extends Backbone.View
  className: 'jcrop-handle handleR'
  initialize: ->
    @$el.attr style: 'position:absolute; margin-left: -4px; margin-top: -4px; left: 50%; top:-25px; cursor:url(assets/images/rotate.png) 12 12, auto;'
    #@listenTo $el, 'mousedown', =>


#This element is here to receive mouse events (clicks)
class TrackerView extends Backbone.View
  className: 'jcrop-tracker tracker'
  initialize: ->
    @$el.attr style: 'cursor: move; position: absolute;'
