 	Pairs = $resource '/api/v1/pairs/:id'
 	Files = $resource '/api/v1/files/:id'
 	Lessons = $resource '/api/v1/lessons/:id'
-	Response = $resource '/api/v1/response'
-	Tallies = $resource '/api/v1/tallies/:fileid/:userid'
+	Tallies = $resource '/api/v1/tallies/:id1/:id2'
 	Folders = $resource '/api/v1/folders/:id'
+	LIMIT = 3
 	
 	home = ->
 		$scope.show = 'directory'

	$scope.respond = ->
		correct = $scope.response == $scope.lesson.pairs[$scope.challengeIndex].back
		
		if correct
			$scope.message = {type: 'success', text: 'Right!'}
		else
			$scope.message = {type: 'error', text: 'Wrong: "' + $scope.lesson.pairs[$scope.challengeIndex].back + '"'}
			
		Response.save
			userid: $scope.user.id
			pairid: $scope.lesson.pairs[$scope.challengeIndex].id
			fileid: $scope.file.id
			correct: correct
		, (result, response) ->
			if result.done
				if $scope.lesson.pairs.length == 1
					$scope.complete = true
					$scope.message = {type: 'success', text: 'You finished!'}
			$scope.response = ''
			challenge( result.done )
		, (response) ->
			$scope.message = {type: 'error', text: response.data}
	
	$scope.editFront = (index) ->
		$scope.value = $scope.lessonData.pairs[index].front

			
	$scope.startCramming = ->
		Tallies.get
			id1: $scope.file.id
			id2: $scope.user.id
		, (result, response) ->
			$scope.start = true
			$scope.complete = false
			$scope.challengeIndex = undefined
			$scope.lesson = angular.copy( $scope.lessonData )
			$scope.lesson.tallies = ({foreward: 0, backward: 0} for i in [1..$scope.lesson.pairs.length])
			$scope.message = {type: 'none'}
			challenge()
		, (response) ->
