function init(is_restart)

	-- Initialise arena - backdrop_name, start_pos, is_restart
	init_level("level-game-ending", CCPoint(-7.5, -29), is_restart)

end

function onLevelIntro()

	bot_manager.MaxBotsOnScreen = 2

	say("lumberjack", localize("ENDING_INTRO_1"), talkToFist)
	say("fist", localize("ENDING_INTRO_2"), fistTalk)
	say("lumberjack", localize("ENDING_INTRO_3"), talkToFist)
	say("fist", localize("ENDING_INTRO_4"), fistTalk)
	say("lumberjack", localize("ENDING_INTRO_5"), talkToFist)
	say("lumberjack", localize("ENDING_INTRO_6"), talkToFist)
	say("fist", localize("ENDING_INTRO_7"), fistTalk)
	say("lumberjack", localize("ENDING_INTRO_8"), talkToFist)
	say("lumberjack", localize("ENDING_INTRO_9"), talkToFist)
	say("fist", localize("ENDING_INTRO_10"), fistTalk)
	say("lumberjack", localize("ENDING_INTRO_11"), fistGoesAway,	onLevelIntroEnd)

end

function onLumbermum(trigger)

	disconnectControls()

	say("lumbermum", localize("ENDING_MUM_1"))

	say("lumberjack", localize("ENDING_MUM_2"))
	say("lumbermum", localize("ENDING_MUM_3"), nil, connectControls)

	return true

end

function onLumberdad(trigger)

	disconnectControls()

	say("lumberdad", localize("ENDING_DAD_1"))
	say("lumberjack", localize("ENDING_DAD_2"), nil, connectControls)

	return true

end

function onDeer1(trigger)

	disconnectControls()

	say("deer", localize("ENDING_DEER_1_1"))
	say("lumberjack", localize("ENDING_DEER_1_2"), nil, connectControls)

	return true

end

function onDeer2(trigger)

	disconnectControls()

	say("deer", localize("ENDING_DEER_2_1"))
	say("lumberjack", localize("ENDING_DEER_2_2"), nil, connectControls)

	return true

end

function onDeer3(trigger)

	disconnectControls()

	say("deer", localize("ENDING_DEER_3_1"))
	say("lumberjack", localize("ENDING_DEER_3_2"), nil, connectControls)

	return true

end

function onDeer4(trigger)

	disconnectControls()

	say("deer", localize("ENDING_DEER_4_1"))
	say("lumberjack", localize("ENDING_DEER_4_2"), nil, connectControls)

	return true

end

function onDeer5(trigger)

	disconnectControls()

	say("deer", localize("ENDING_DEER_5_1"))
	say("lumberjack", localize("ENDING_DEER_5_2"), nil, connectControls)

	return true

end

function onLumberkid(trigger)

	disconnectControls()

	say("lumberkid", localize("ENDING_KID_1"))
	say("lumberjack", localize("ENDING_KID_2"))
	say("lumberkid", localize("ENDING_KID_3"))
	say("lumberjack", localize("ENDING_KID_4"), nil, connectControls)

	return true

end

function onDJBBQ(trigger)

	disconnectControls()

	say("djbbq", localize("ENDING_DJ_BBQ_1"))
	say("lumberjack", localize("ENDING_DJ_BBQ_2"))
	say("djbbq", localize("ENDING_DJ_BBQ_3"))
	say("lumberjack", localize("ENDING_DJ_BBQ_4"))
	say("djbbq", localize("ENDING_DJ_BBQ_5"))
	say("lumberjack", localize("ENDING_DJ_BBQ_6"))
	say("lumberjack", localize("ENDING_DJ_BBQ_7"))
	say("lumberjack", localize("ENDING_DJ_BBQ_8"))
	say("djbbq", localize("ENDING_DJ_BBQ_9"))
	say("lumberjack", localize("ENDING_DJ_BBQ_10"), nil, connectControls)
	return true

end

function showHint(trigger)

	hud:showLeftThumb(localize("ENDING_HINT"));

	return true

end

function onLumberlover(trigger)

	hud:hideLeftThumb()
	disconnectControls()

	local backdrop = game_manager.Background
	local lover_node = backdrop:getAnimatingSpriteByName("lumberlover")
	local world_pos = lover_node:convertToWorldSpace(ccp(0,0))
	local layer_pos = backdrop:getMainLayer():convertToNodeSpace(world_pos)
	layer_pos.x = layer_pos.x - 4
	player:setBasePosition(layer_pos)

	say("lumberlover", localize("ENDING_KISS_SPEECH_BOY"), nil, onLumberloverKiss)

	game_manager:updateAchievement("achievement.awesome.completed_game_lumberdude", 1.0)

	return true

end

function onLumberloverKiss()

	AnalyticsManager:sharedAnalyticsManager():logEvent("lumberdudeKiss")

	local lover_node = game_manager.Background:getAnimatingSpriteByName("lumberlover")
	lover_node:setWildcard("lumberlover-kiss")
	lover_node:setDelay(0.25)
	lover_node:setNoLoop(true)
	lover_node:restart()

	game_manager:startTimer(1, onFadeOutToDancefloor)

	player:setOpacity(0)

end

function onLumbergirl(trigger)

	hud:hideLeftThumb()
	disconnectControls()

	local backdrop = game_manager.Background
	local lover_node = backdrop:getAnimatingSpriteByName("lumbergirl")
	local world_pos = lover_node:convertToWorldSpace(ccp(0,0))
	local layer_pos = backdrop:getMainLayer():convertToNodeSpace(world_pos)
	layer_pos.x = layer_pos.x - 4
	player:setBasePosition(layer_pos)

	say("lumbergirl", localize("ENDING_KISS_SPEECH_GIRL"), nil, onLumbergirlKiss)

	game_manager:updateAchievement("achievement.awesome.completed_game_lumbergirl", 1.0)

	return true

end

function onLumbergirlKiss()

	AnalyticsManager:sharedAnalyticsManager():logEvent("lumbergirlKiss")

	local lover_node = game_manager.Background:getAnimatingSpriteByName("lumbergirl")
	lover_node:setWildcard("lumbergirl-kiss")
	lover_node:setDelay(0.25)
	lover_node:setNoLoop(true)
	lover_node:restart()	

	game_manager:startTimer(1, onFadeOutToDancefloor)

	player:setOpacity(0)

end

function onFadeOutToDancefloor()

	-- Must start a new game next time
	game_manager:resetStoryMode()

	hud:doScreenFade(ccc4(255,255,255,255), 1)

	game_manager:startTimer(1.1, onTimBow)

	game_manager:startTimer(2.5, onShowDancefloor)

end

function onTimBow()

	local backdrop = game_manager.Background

	local tim_node = backdrop:getNodeByName("timBowing")
	local world_pos = tim_node:convertToWorldSpace(ccp(0,0))
	local layer_pos = backdrop:getMainLayer():convertToNodeSpace(world_pos)

	player:setVisible(false)
	player:setBasePosition(layer_pos)

	hud:disableCinemascope()
	camera_manager:setRightEdgeCollisionToCameraBounds(false)

end

function onShowDancefloor()

	hud:doScreenFade(ccc4(0,0,0,0), 1)

	game_manager:startTimer(10, onEndGame)

	-- Woo! Yeah! Unlock stuff!
    game_manager:onStoryModeCompleted()

end

function onEndGame()

	hud:doScreenFade(ccc4(0,0,0,255), 1)

	game_manager:startTimer(1.1, onQuitToTitle)


end

function onQuitToTitle()

	game_manager:quitToTitleScreen()

end
