 		diagram.active_points = []
 		setTimeout updateSidebar, 400
 	else
-		markAllActive("red")
 		tempAddClass "#check_button", "button_red"
-		updateSidebar()
+		updateSidebar("red")
 
 onClearButtonClick = (e) ->
+	diagram = game.currDiagram()
 	diagram.active_points = []
 	updateSidebar()
 
 onDoneButtonClick = (e) ->
+	diagram = game.currDiagram()
 	if diagram.allFound()
 		tempAddClass "#done_button", "button_green"
 		game.processCorrectDone()
-		sidebarClearForNextDiagram()
+		if game.alive # still alive ~
+			sidebarClearForNextDiagram()
+			updateSidebar()
 	else
 		tempAddClass "#done_button", "button_red"
 		game.processIncorrectDone()
-	updateSidebar()
+		updateSidebar()
 
 onStopButtonClick = (e) ->
 	if (confirm("Are you sure you want to give up?"))

toJSON = (filename) ->
	"diagrams/" + filename + ".json"

loadDiagram = (filename) ->
	clearAll()
	CANVAS.css "background", "url(" + toImg(filename) + ") no-repeat"
	$.getJSON(toJSON(filename),
		(data, status, xhr) ->
			diagram = new Diagram(data)
			$("#head_title").html(diagram.source)
			updateSidebar()
	).error( # chain
		(jqXhr, textStatus, error) ->
			alert textStatus + " : " + error
	)
# }}}
# Canvas art and Button UI {{{
# Low-level things


# Main function {{{
$ ->
	game = new Game(["demo1"])
	console.log(game)
	$("[type=button]").prop("disabled", true)
	$("#start_game").prop("disabled", false)

	$("#start_game").click ->
		startGameUI()
		game.startGame()

# }}}
