   processLabels = (data) ->
     clearLabels()
     jq.each data.labels, ->
-      jq(".custom-timer-labels").append "<div class='timer-description-button animate-click'>#{this}</div>"
+      jq(".custom-timer-labels").append "<div class='timer-description-button animate-click'>#{@}</div>"
 
     jq.each data.timed_labels, ->
-      jq(".timed-custom-timer-labels").append "<div class='timer-description-button animate-click' data-duration='#{this.duration}'>#{this.label}</div>"
+      jq(".timed-custom-timer-labels").append "<div class='timer-description-button animate-click' data-duration='#{@duration}'>#{@label}</div>"
 
     modal_elem.find(".timer-description-button").on "click", ->
       content_switch.userActivity()
-      name = jq(this).html()
+      name = jq(@).html()
       submitTimer(name)
 
   updateLabels = ->

    d = content.substring(0, index_start) + data + content.substring(index_start + length)
    return d

  nullTimeField = (content, field) ->
    replace_string = ""
    #TODO: validate this
    for i in [0..time_spec["#{field}_l"]]
      replace_string += "0"

    return setTimeField(content, field, replace_string)

  processButton = (content) ->
    current_content = duration_elem.data("content")
    if content.substring(0, 6) == "clear-"
      # backspace
      clear_field = content.substring(6)
      current_content = nullTimeField(current_content, clear_field)
    else
      data = parseInt(content.substring(0, content.length - 1))
      field = content.substring(content.length - 1)
      field_data = parseInt(getTimeField(current_content, field))
      field_data += data
      if field_data < 0
        hours_field = parseInt(getTimeField(current_content, "h"))
        minutes_field = parseInt(getTimeField(current_content, "m"))
        if field == "s"
          if minutes_field == 0 and hours_field > 0
            # Take 1h to minutes field.
            hours_field -= 1
            current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
            minutes_field += 60

          if minutes_field > 0
            # Take 1 minute to seconds field.
            minutes_field -= 1
            field_data += 60
            current_content = setTimeField(current_content, "m", zeroPad(minutes_field, time_spec.m_l))
          else
            field_data = 0

        else if field == "m"
          if hours_field > 0
            # Take 1 hour to minutes field.
            hours_field -= 1
            field_data += 60
            current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
          else
            field_data = 0
        else
          field_data = 0

      if (field == "s" or field == "m") and field_data >= 60
        if field == "s"
          minutes_field = parseInt(getTimeField(current_content, "m"))
          minutes_field += 1
          field_data -= 60
          if minutes_field >= 60
            minutes_field -= 60
            hours_field = parseInt(getTimeField(current_content, "h"))
            hours_field += 1
            current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))

          current_content = setTimeField(current_content, "m", zeroPad(minutes_field, time_spec.m_l))

        if field == "m"
          field_data -= 60
          hours_field = parseInt getTimeField(current_content, "h")
          hours_field += 1
          current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))

      field_data = zeroPad field_data, time_spec[field + "_l"]
      current_content = setTimeField current_content, field, field_data

    duration_elem.data "content", current_content
    c = current_content

  ge_refresh.register "timer-labels", updateLabels
  ws_generic.register "timer-labels", processLabels

  @showCustomTimer = showCustomTimer
  @closeCustomTimer = closeCustomTimer
  @submitTimer = submitTimer
  @processButton = processButton
  @setTimeField = setTimeField
  @getTimeField = getTimeField

  return this

jq =>
  @.custom_timer = new CustomTimer
    duration_elem: "#custom-timer-duration"
    modal_elem: "#add-custom-timer"
