function fireFlickerFunction(sprite, parent)
	if (parent == nil) then parent = sprite end
	
	parent:doEvery(0, function()
		local durationLowerLimit = 40
		local durationUpperLimit = 300
		local d1 = math.Random(durationLowerLimit, durationUpperLimit)
		local d2 = math.Random(durationLowerLimit, durationUpperLimit)
		sprite:animate("fire glow fade",
			{alpha = math.Random(0.9, 1.0), duration = d1},
			{alpha = math.Random(0.0, 0.4), duration = d2}
		)
		return d1+d2
	end)
end


function initSelectionScene(scene)

	local groupNode = scene:newChildSprite({name="GroupNode"})
	local foreground = scene:child("foreground")

	-----------------------------------------
	-- TreeLight
	-----------------------------------------
	fireFlickerFunction(scene:child("treelight"), groupNode)

	-----------------------------------------
	-- Clouds
	-----------------------------------------
	scene.couldIdx = 1
	groupNode:doEvery(0, function()
		local durationLowerLimit = 16000
		local durationUpperLimit = 30000
		local startX = 1024
		local startY = math.Random(50, 160)
		if (scene.couldIdx == 2) then scene.couldIdx = 1 else scene.couldIdx = 2 end
		local cloud = scene:newChildSprite({name="RemoveMe", x = startX, y = startY, image="cloud"..scene.couldIdx..":sceneselection"})
		cloud:moveBehind(foreground)
		local endX = -cloud:width()
		local endY = startY
		local dur = math.Random(durationLowerLimit, durationUpperLimit)
		cloud:animate("cloud move", {x = endX, y = endY, duration = dur}, {obsolete = true})
		return math.Random(6000, 10000)
	end)

	-----------------------------------------
	-- Mist
	-----------------------------------------
	local sec = 1000
	local mist1 = groupNode:newChildSprite({name="RemoveMe", y = 768, anchorpoint = "bottomleft", image="mist:sceneselection"})
	local mist2 = groupNode:newChildSprite({name="RemoveMe", y = 768, anchorpoint = "bottomleft", image="mist:sceneselection"})
	mist1:moveBehind(scene:child("trunk"))
	mist2:moveBehind(scene:child("trunk"))
	mist2:setX(1024)
	mist1:animate("mist 1 - blink", {blink={1.0, 0.5, 20*sec, 20*sec, 4*sec, 12*sec}})
	mist2:animate("mist 2 - blink", {blink={1.0, 0.5, 20*sec, 20*sec, 4*sec, 12*sec}})
	groupNode:doEvery(0, function()
		local dur = 100*sec
		mist2:setX(1024)
		mist1:animate("mist 1 - move", {x = -1024, duration = dur})
		mist2:animate("mist 2 - move", {x = 0, duration = dur})
		local tmp = mist1
		mist1 = mist2
		mist2 = tmp
		return dur
	end)

	-----------------------------------------
	-- Strips (Setup)
	-----------------------------------------
	local stripY = 328
	local stripHeight = 95
	local clipWidths = {122, 188, 222, 154, 167, 107, 52}
	local config = {
		{ img="1_1", pos = {{x=15,y=64,w=122},  {x=2,y=2,w=202}},   dur = 14000 },
		{ img="2_1", pos = {{x=37,y=29,w=188},  {x=18,y=30,w=278}}, dur = 14000 },
		{ img="3_1", pos = {{x=83,y=37,w=222},  {x=2,y=1,w=435}},   dur = 14000 },
		{ img="4_1", pos = {{x=96,y=64,w=154},  {x=1,y=2,w=291}},   dur = 14000 },
		{ img="5_1", pos = {{x=152,y=30,w=167}, {x=10,y=4,w=318}},  dur = 14000 },
		{ img="6_1", pos = {{x=55,y=22,w=89},   {x=180,y=8,w=89}},  dur = 14000 },
		{ img="7_1", pos = {{x=53,y=22,w=52},   {x=17,y=3,w=100}},  dur = 14000 }
	}
	
	local curX = 0 -- window bar start offset and position counter
	local pad = 2 -- padding between clip windows
	for i = 1,#config do
		local cfg = config[i]
		cfg.idx = i
		cfg.clipX = curX
		cfg.clipW = clipWidths[i]
		
		for p=1,#cfg.pos do
			local pos = cfg.pos[p]
			pos.s = clipWidths[i] / pos.w
			pos.x = curX - pos.x * pos.s
			pos.y = stripY - pos.y * pos.s
		end
		
		cfg.strip = groupNode:newChildSprite({
			class = "SpriteExt",
			name="RemoveMe",
			x = cfg.pos[1].x,
			y = cfg.pos[1].y,
			scale = cfg.pos[1].s,
			image = "strip"..cfg.img..":sceneselection",
		})
		cfg.strip:setClipRect(cfg.clipX, stripY, cfg.clipW, stripHeight)
		curX = curX + clipWidths[i] + pad
	end
	
	-----------------------------------------
	-- Strips (Function)
	-----------------------------------------
	local prevStripIndices = {}
	groupNode:doEvery(0, function()
		local cfg
		while (1) do
			local i = math.Random(1, #config)
			if (i ~= prevStripIndices[1] and
				i ~= prevStripIndices[2] and
				i ~= prevStripIndices[3] and
				i ~= prevStripIndices[4] and
				i ~= prevStripIndices[5]) then
				table.insert(prevStripIndices, 1, i)
				prevStripIndices[5+1] = nil
				cfg = config[i]
				break
			end
		end
		
		local dur = cfg.dur / #cfg.pos
		local steps = {}
		for p=2,#cfg.pos do
			local pos = cfg.pos[p]
			steps[#steps+1] = {x = pos.x, y = pos.y, scale = pos.s, duration = dur, style = "easeInOut"}
		end
		local pos = cfg.pos[1]
		steps[#steps+1] = {x = pos.x, y = pos.y, scale = pos.s, duration = dur, style = "easeInOut"}
		cfg.strip:animate("strip", unpack(steps))

		return #steps * dur / 2
	end)
	
	-----------------------------------------
	-- FireFly
	-----------------------------------------
	groupNode:doEvery(4000, function()
		local dur = 5000
		local startScale = 1.0
		local endScale = 0.0
		local startX = 0
		local startY = 768
		local endX
		local endY
		if (math.Random(0, 1000) < 500) then
			endX = math.Random(1024-200, 1024)
			endY = 0
		else
			endX = 1024
			endY = math.Random(0, 200)
		end
		
		local points = {}
		local numPoints = 5

		local delta = 150
		local slopeX = startY - endY
		local slopeY = endX - startX
		local slopeLength = math.sqrt(slopeX*slopeX + slopeY*slopeY)
		slopeX = delta * slopeX / slopeLength
		slopeY = delta * slopeY / slopeLength
		
		local sign = 1
		if (math.Random(0, 1000) < 500) then sign = -1 end
		for i = 1,numPoints do
			local frac = (i-1) / (numPoints-1)
			local x = startX + (endX - startX) * frac
			local y = startY + (endY - startY) * frac

			if (sign == 1) then sign = -1 else sign = 1 end
			local d = (1 - frac) * sign
			x = x + slopeX * d
			y = y + slopeY * d

			points[#points+1] = {x,y}
		end
		
		local firefly = scene:newChildSprite({name="RemoveMe", x = startX, y = startY, scale = startScale, image = "firefly:sceneselection" })
		firefly:moveInFrontOf(foreground)
		firefly:animate("firefly",
			{startFrame = 0, frameTime = 20, loops = -1, path = points, scale = endScale, duration = dur},
			{obsolete = true}
		)
		
		return dur + math.Random(2000, 6000)
	end)

	-----------------------------------------
	-- Birds
	-----------------------------------------
	local doSkyBirds = true	
	groupNode:doEvery(2000, function()
		local maxDur
		if (doSkyBirds) then
		
			-----------------------------------------
			-- Sky Birds
			-----------------------------------------
			maxDur = 3500
			-- The first and last point are CONTROL points and are not incorpoated into the path
			local path = {{100,170},
				{240,150},
				{430,170},
				{670,120},
				{910,150},
			{999,130}}

			local minDV = 30 -- min displacement variation
			local maxDV = 80 -- max displacement variation
			
			local num = math.Random(500, 800) / 100
			for i=1,num do
				local pth = {}
				for p = 1,#path do
					pth[p] = {
						path[p][1] + math.Random(minDV, maxDV),
						path[p][2] + math.Random(minDV, maxDV)
					}
				end
				local crow = scene:newChildSprite({name="RemoveMe", x = pth[2][1], y = pth[2][2], image = "flyingcrow:sceneselection", scale = 0.8, alpha = 0.1})
				crow:moveBehind(foreground)
				local frameTime = math.Random(60, 80)
				local delay = math.Random(0, 500)
				local dur = maxDur - math.Random(0, 200)
				crow:animate("flyingbird - fade", {alpha = 1.0, duration = 800})
				crow:animate("flyingbird - frames", {startFrame = 0, frameTime = frameTime, loops = -1})
				crow:animate("flyingbird - path", {delay = delay}, {path = pth, pathStart = 1, pathEnd = 4, duration = dur}, {obsolete = true})
				crow:animate("flyingbird - fade", {delay = delay+dur-1800}, {alpha = 0.1, duration = 1000})
			end		
		else
		
			-----------------------------------------
			-- Forset Birds
			-----------------------------------------
			maxDur = 3000
			-- The first and last point are CONTROL points and are not incorpoated into the path
			local path = {{810,480},
				{730,340},
				{620,240},
				{440,180},
				{320,100},
			{150,90}}
			
			local dist = 30 -- displacement distance
			local mdv = 50 -- max displacement variation
			local offsets = {
				{ 0.0,  0.0},
				{ 0.0, -1.0},
				{-0.9, -0.2},
				{ 0.9, -0.2},
				{-0.4,  0.4},
				{ 0.4,  0.4}
			}
			
			for i=1,6 do
				local pth = {}
				for p = 1,#path do
					pth[p] = {
						path[p][1] + offsets[i][1] * dist + math.Random(0, mdv),
						path[p][2] + offsets[i][2] * dist + math.Random(0, mdv)
					}
				end
				local crow = scene:newChildSprite({name="RemoveMe", x = pth[2][1], y = pth[2][2], image = "birdlift:sceneselection", alpha = 0.0})
				local fadeTime = 200
				local frameTime = math.Random(80, 120)
				local delay = math.Random(0, 1200)
				local dur = maxDur - math.Random(0, 200)
				crow:animate("birdlift - frames",
					{delay = delay},
					{startFrame = 0, endFrame = 19, frameTime = frameTime, loops = 1, alpha = 1.0, duration = fadeTime},
					{startFrame = 20, endFrame = 24, frameTime = frameTime, loops = -1}
				)
				crow:animate("birdlift - path", {delay = delay}, {path = pth, pathStart = 1, pathEnd = 4, duration = dur}, {obsolete = true})
				crow:animate("birdlift - relink", {delay = delay+dur/2}, {call = function() crow:moveBehind(foreground) end})
				crow:animate("birdlift - fade", {delay = delay+dur-fadeTime}, {alpha = 0.0, duration = fadeTime})

				local screamMaxDelay = dur * 0.8
				local screamDelay = math.Random(0, screamMaxDelay)
				local fraction = screamDelay / screamMaxDelay
				local screamVol = 0.4 - 0.35 * fraction -- From 0.05 to 0.4
				local screamPan = 0.6 - 1.2 * fraction -- From -0.6 to 0.6
				local screamPitch = math.Random(800, 1200) / 1000
				crow:animate("birdlift - fade", {delay = screamDelay}, {call = function() getAudioManager():playTrack({definition = "CROW_SCREAM", volume = screamVol, pan = screamPan, pitch = screamPitch}) end})
				crow:moveInFrontOf(foreground)
			end
		end
		
		doSkyBirds = not doSkyBirds
		return maxDur + math.Random(10000, 20000)
	end)
end