 'use strict'
 
+###
+  @param  :
+    id: DOM id attribute
+    settings: Specify options in {}. May be on of size, times or color.
+  @example:
+    new Counter('downloader', {
+      size: 420,
+      secondsColor : "#ffdc50",
+      secondsGlow  : "#ffdc50",
+      startDate    : 1412698808,
+      endDate      : 1412704208,
+      now          : 1412701317
+    });
+###
 class Counter
   constructor: (id, settings) ->
     @element = document.getElementById(id)
-
-    @glob = settings
+    @settings = settings
     @init()
 
   init: ->
-
     @canvas = document.createElement('canvas');
-    @canvas.setAttribute('width', @glob.size)
-    @canvas.setAttribute('height', @glob.size)
+    @canvas.setAttribute('width', @settings.size)
+    @canvas.setAttribute('height', @settings.size)
 
     @element.appendChild(@canvas);
 
-    @glob.total   = Math.floor((@glob.endDate - @glob.startDate) / 86400)
-    @glob.days    = Math.floor((@glob.endDate - @glob.now) / 86400)
-    @glob.hours   = 24 - Math.floor((@glob.endDate - @glob.now) % 86400 / 3600)
-    @glob.minutes = 60 - Math.floor((@glob.endDate - @glob.now) % 86400 % 3600 / 60)
-    @glob.seconds = 60 - Math.floor((@glob.endDate - @glob.now) % 86400 % 3600 % 60)
-    @glob.secLeft = Math.floor(@glob.endDate - @glob.now)
+    @settings.total   = Math.floor((@settings.endDate - @settings.startDate) / 86400)
+    @settings.days    = Math.floor((@settings.endDate - @settings.now) / 86400)
+    @settings.hours   = 24 - Math.floor((@settings.endDate - @settings.now) % 86400 / 3600)
+    @settings.minutes = 60 - Math.floor((@settings.endDate - @settings.now) % 86400 % 3600 / 60)
+    @settings.seconds = 60 - Math.floor((@settings.endDate - @settings.now) % 86400 % 3600 % 60)
+    @settings.secLeft = Math.floor(@settings.endDate - @settings.now)
 
     @meter()
     @start()

    ctx.closePath()

    ctx.beginPath()
    ctx.arc(@glob.size/2, @glob.size/2, @glob.size/2-6, 0, Math.PI*2, true)
    ctx.lineWidth = 1
    ctx.strokeStyle = "#000000"
    ctx.shadowBlur  = 0

  deg: (deg) ->
    (Math.PI/180) * deg - (Math.PI/180)*90


  meter: ->
    @settings.secLeft--

    ctx = @canvas.getContext("2d")

    ctx.clearRect(0, 0, @settings.size, @settings.size)

    ctx.beginPath()
    ctx.arc(@settings.size/2, @settings.size/2, @settings.size/2-10, 0, Math.PI*2, true)
    ctx.lineWidth = 5
    ctx.strokeStyle = "#1C1C1C"
    ctx.shadowBlur  = 0
