@.generalSiteHandler = ->
  $(document).ready(->
    bindInstructionListHandler()
    bindFormHandler()
  )

  bindInstructionListHandler = ->
    $('.instruction-list__title').on('click', ->
      $('.instruction-list__content__item').stop().toggle(->
        $('.instruction-list').toggleClass('show')
        return
      )
    )
  bindFormHandler = ->
    do ->
      $('input').each(->
        if($(this).val() != '')
          $(this).siblings('label').css({
            'bottom': '45px',
            'font-size': '13px'
          })
        if($(this).parent().hasClass('has-error'))
          $(this).siblings('label').css({
            'bottom': '65px',
            'font-size': '13px'
          })
      )

    $('input').on('change', ->
      if($(this).val() != '')
        $(this).siblings('label').css({
          'bottom': '45px',
          'font-size': '13px'
        })
      else
        $(this).siblings('label').css({
          'bottom': '',
          'font-size': '13px'
        })

      if($(this).parent().hasClass('has-error'))
        $(this).siblings('label').css({
          'bottom': '65px',
          'font-size': '13px'
        })
    )

@.userProfileHandler = () ->
  onDocumentReady = ->
    $('.edit-save-button').on('click', ->
      $(this).hide()
      $(this).parent().find('button').show()
      $(this).parent().find('input').prop('readonly', false)
    )

    $('.password-edit-view').on('click', ->
      $('.new-password-2-wrapper').show()
    )

    $('.username-edit-view').on('click', ->
      $('.username-hint-wrapper').show()
    )

  $(document).ready(onDocumentReady)

@.popupHandler = () ->
  onDocumentReady = ->
    $('.popup-close-button').on('click', ->
      $('.popup-container').hide()
    )

  $(document).ready(onDocumentReady)

@.exerciseHandler = () ->
  onDocumentReady = ->
    exerciseDoneCallback = (data) ->
      if data.status
        if data.status == 'all_done'
          $('.todo-notification').hide()
          $('.all-done-notification').show()
        if data.status == 'done'
          $('.todo-notification').hide()
          $('.done-notification').show()
        if data.progress
          $('.exercises-progress-content').html(data.progress + '%')


    $('.exercise-done-button').on('click', ->
      exercise_task_position_id = $(this).data('extra-arg')
      Dajaxice.exercises.exercise_done(exerciseDoneCallback, {'exercise_task_position_id': exercise_task_position_id})
    )

  $(document).ready(onDocumentReady)

@.likesHandler = () ->
  onDocumentReady = ->
    sendLikesCallback = (data) ->
      if data.status
        if data.status == 'ok'
          $('.social-vote-content').html(data.social_vote_list_html)

    $('.like-button').on('click', ->
      $(this).parent().toggleClass('voted')
    )

    $('.send-likes').on('click', ->
      taskMarkCriteriaIds = []
      taskAnswerId = $('.send-likes').data('task-answer-id')
      $('.voted').each (index, element) =>
        id = $(element).data('task-mark-criteria-id')
        taskMarkCriteriaIds.push(id)
      Dajaxice.tasks.submit_likes(sendLikesCallback, {
        'task_mark_criteria_ids': taskMarkCriteriaIds,
        'task_answer_id': taskAnswerId
      })
    )

  $(document).ready(onDocumentReady)

@.taskAnswerListHeaderHandler = () ->
  onDocumentReady = ->
    $('#queryInput').keyup (e) ->
      if e.which is 13
        $('#sortHeaderForm').submit();
        return false

    $('#pathSelect').change ->
      $('#sortHeaderForm').submit();
      return false

    $('#sortSelect').change ->
      $('#sortHeaderForm').submit();
      return false

    $('.more-button').click ->
      $('#moreInput').val(true)
      $('#sortHeaderForm').submit();

  $(document).ready(onDocumentReady)
