--[[
Ambient Animations
--]]


function SCENESELECTION_loopCloud1()
 	local cloud1 = scene:child("Cloud1")	-- get the cloud sprite from the scene pipeline
	if cloud1 ~= nil then
		cloud1:doEvery(0, function()		-- repeat this stuff
			cloud1:animate(
				{x = 1300, duration = 200000},	-- move clouds left to right
				{x = -170}					
			)
			return 210000		-- this number is delay before repeating; must be larger than duration of stuff we do above.
			end
		)
	end
end

function SCENESELECTION_palmTree1()
-- PALM TREE 1 --------------------------------
	local tree1 = scene:child("Tree1")	-- get the plant sprite from the scene pipeline
	if tree1 ~= nil then
		tree1:setPivotPoint("bottom")
		tree1:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,5000 )
			local dur2 = math.Random( 3000,5000 )
			local dur3 = math.Random( 3000,5000 )
			local dur4 = math.Random( 3000,5000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree1:animate(
				{skewx = (math.Random( 2, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -2, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -2.5 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -2.5, .5 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	
	-- PALM TREE 1 - PALM 1 --------------------------------	
	local tree1Palm1 = scene:child("Tree1Palm1")	-- get the plant sprite from the scene pipeline
	if tree1Palm1 ~= nil then
		tree1Palm1:setPivotPoint("top")
		tree1Palm1:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree1Palm1:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 1 - PALM 2 --------------------------------	
	local tree1Palm2 = scene:child("Tree1Palm2")	-- get the plant sprite from the scene pipeline
	if tree1Palm2 ~= nil then
		tree1Palm2:setPivotPoint("topleft")
		tree1Palm2:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree1Palm2:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 1 - PALM 3 --------------------------------	
	local tree1Palm3 = scene:child("Tree1Palm3")	-- get the plant sprite from the scene pipeline
	if tree1Palm3 ~= nil then
		tree1Palm3:setPivotPoint("top")
		tree1Palm3:doEvery(0, function()								-- repeat this stuff
			local dur1 = math.Random( 1000,3000 )
			local dur2 = math.Random( 1000,3000 )
			local totalDuration = dur1 + dur2 
			tree1Palm3:animate(
				{skewx = (math.Random( -1.7, 1.7 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -1.7, 1.7 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	
	-- PALM TREE 1 - PALM 4 --------------------------------	
	local tree1Palm4 = scene:child("Tree1Palm4")	-- get the plant sprite from the scene pipeline
	if tree1Palm4 ~= nil then
		tree1Palm4:setPivotPoint("bottomright")
		tree1Palm4:doEvery(0, function()								-- repeat this stuff
			local dur1 = math.Random( 1000,3000 )
			local totalDuration = dur1
			tree1Palm4:animate(
				{skewy = math.Random( -0.035, 0.035 ), duration = dur1, style="easeInOut" }	-- math.Random makes a random number between lower and upper INTEGER
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	
	-- PALM TREE 1 - PALM 5 --------------------------------	
	local tree1Palm5 = scene:child("Tree1Palm5")	-- get the plant sprite from the scene pipeline
	if tree1Palm5 ~= nil then
		tree1Palm5:setPivotPoint("right")
		tree1Palm5:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree1Palm5:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
end

function SCENESELECTION_palmTree2()
	-- PALM TREE 2 --------------------------------
	local tree2 = scene:child("Tree2")	-- get the plant sprite from the scene pipeline
	if tree2 ~= nil then
		tree2:setPivotPoint("bottom")
		tree2:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,5000 )
			local dur2 = math.Random( 3000,5000 )
			local dur3 = math.Random( 3000,5000 )
			local dur4 = math.Random( 3000,5000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree2:animate(
				{skewx = (math.Random( 2, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -2, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 3, -2 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -2, 0.5 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	
	-- PALM TREE 2 - PALM 1 --------------------------------	
	local tree2Palm1 = scene:child("Tree2Palm1")	-- get the plant sprite from the scene pipeline
	if tree2Palm1 ~= nil then
		tree2Palm1:setPivotPoint("top")
		tree2Palm1:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree2Palm1:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 2 - PALM 2 --------------------------------	
	local tree2Palm2 = scene:child("Tree2Palm2")	-- get the plant sprite from the scene pipeline
	if tree2Palm2 ~= nil then
		tree2Palm2:setPivotPoint("topleft")
		tree2Palm2:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree2Palm2:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 2 - PALM 3 --------------------------------	
	local tree2Palm3 = scene:child("Tree2Palm3")	-- get the plant sprite from the scene pipeline
	if tree2Palm3 ~= nil then
		tree2Palm3:setPivotPoint("bottomleft")
		tree2Palm3:doEvery(0, function()								-- repeat this stuff
			local dur1 = math.Random( 1000,3000 )
			local totalDuration = dur1
			tree2Palm3:animate(
				{skewy = math.Random( -0.035, 0.035 ), duration = dur1, style="easeInOut" }	-- math.Random makes a random number between lower and upper INTEGER
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	
	-- PALM TREE 2 - PALM 4 --------------------------------	
	local tree2Palm4 = scene:child("Tree2Palm4")	-- get the plant sprite from the scene pipeline
	if tree2Palm4 ~= nil then
		tree2Palm4:setPivotPoint("bottomright")
		tree2Palm4:doEvery(0, function()								-- repeat this stuff
			local dur1 = math.Random( 1000,3000 )
			local totalDuration = dur1
			tree2Palm4:animate(
				{skewy = math.Random( -0.035, 0.035 ), duration = dur1, style="easeInOut" }	-- math.Random makes a random number between lower and upper INTEGER
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	
	-- PALM TREE 2 - PALM 5 --------------------------------	
	local tree2Palm5 = scene:child("Tree2Palm5")	-- get the plant sprite from the scene pipeline
	if tree2Palm5 ~= nil then
		tree2Palm5:setPivotPoint("right")
		tree2Palm5:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree2Palm5:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
end

function SCENESELECTION_palmTree3()
-- PALM TREE 3 ---------------------------------------------------------
	local tree3 = scene:child("Tree3")	-- get the plant sprite from the scene pipeline
	if tree3 ~= nil then
		tree3:setPivotPoint("bottom")
		tree3:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,6000 )
			local dur2 = math.Random( 3000,6000 )
			local dur3 = math.Random( 3000,6000 )
			local dur4 = math.Random( 3000,6000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree3:animate(
				{skewx = (math.Random( 2, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -2, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -2 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -2, 1 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 3 - PALM 1 --------------------------------	
	local tree3Palm1 = scene:child("Tree3Palm1")	-- get the plant sprite from the scene pipeline
	if tree3Palm1 ~= nil then
		tree3Palm1:setPivotPoint("top")
		tree3Palm1:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree3Palm1:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 3 - PALM 3 --------------------------------	
	local tree3Palm3 = scene:child("Tree3Palm3")	-- get the plant sprite from the scene pipeline
	if tree3Palm3 ~= nil then
		tree3Palm3:setPivotPoint("topleft")
		tree3Palm3:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree3Palm3:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 3 - PALM 4 --------------------------------	
	local tree3Palm4 = scene:child("Tree3Palm4")	-- get the plant sprite from the scene pipeline
	if tree3Palm4 ~= nil then
		tree3Palm4:setPivotPoint("top")
		tree3Palm4:doEvery(0, function()								-- repeat this stuff
			local dur1 = math.Random( 1000,3000 )
			local totalDuration = dur1
			tree3Palm4:animate(
				{skewy = math.Random( -0.035, 0.035 ), duration = dur1, style="easeInOut" }	-- math.Random makes a random number between lower and upper INTEGER
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
end

function SCENESELECTION_palmTree4()
	-- PALM TREE 4 --------------------------------
	local tree4 = scene:child("Tree4")	-- get the plant sprite from the scene pipeline
	if tree4 ~= nil then
		tree4:setPivotPoint("bottom")
		tree4:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,5000 )
			local dur2 = math.Random( 3000,5000 )
			local dur3 = math.Random( 3000,5000 )
			local dur4 = math.Random( 3000,5000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree4:animate(
				{skewx = (math.Random( 3, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -3, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -3 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -3, 1 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	
	-- PALM TREE 4 - PALM 1 --------------------------------	
	local tree4Palm1 = scene:child("Tree4Palm1")	-- get the plant sprite from the scene pipeline
	if tree4Palm1 ~= nil then
		tree4Palm1:setPivotPoint("top")
		tree4Palm1:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree4Palm1:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 4 - PALM 2 --------------------------------	
	local tree4Palm2 = scene:child("Tree4Palm2")	-- get the plant sprite from the scene pipeline
	if tree4Palm2 ~= nil then
		tree4Palm2:setPivotPoint("topleft")
		tree4Palm2:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree4Palm2:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 4 - PALM 3 --------------------------------	
	local tree4Palm3 = scene:child("Tree4Palm3")	-- get the plant sprite from the scene pipeline
	if tree4Palm3 ~= nil then
		tree4Palm3:setPivotPoint("bottomright")
		tree4Palm3:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree4Palm3:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 4 - PALM 4 --------------------------------	
	local tree4Palm4 = scene:child("Tree4Palm4")	-- get the plant sprite from the scene pipeline
	if tree4Palm4 ~= nil then
		tree4Palm4:setPivotPoint("bottomright")
		tree4Palm4:doEvery(0, function()								-- repeat this stuff
			local dur1 = math.Random( 1000,3000 )
			local totalDuration = dur1
			tree4Palm4:animate(
				{skewy = math.Random( -0.035, 0.035 ), duration = dur1, style="easeInOut" }	-- math.Random makes a random number between lower and upper INTEGER
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	
	-- PALM TREE 4 - PALM 5 --------------------------------	
	local tree4Palm5 = scene:child("Tree4Palm5")	-- get the plant sprite from the scene pipeline
	if tree4Palm5 ~= nil then
		tree4Palm5:setPivotPoint("right")
		tree4Palm5:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local dur3 = math.Random( 2000,3000 )
			local dur4 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree4Palm5:animate(
				{skewy = (math.Random( 4, -3 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewy = (math.Random( -4, -3 )*0.01), duration = dur2, style="easeIn" },
				{skewy = (math.Random( 3, -4.5 )*0.01), duration = dur3, style="easeOut" },
				{skewy = (math.Random( -4.5, 3 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
end

function SCENESELECTION_startAmbients()

 -- CLOUDS ------------------------------
 	local cloud1 = scene:child("Cloud1")	-- get the cloud sprite from the scene pipeline
	if cloud1 ~= nil then
		cloud1:animate(
			{x = 1300, duration = 150000},	-- move clouds left to right
			{call=function() SCENESELECTION_loopCloud1() end}
		)
	end
	
	local cloud2 = scene:child("Cloud2")	-- get the cloud sprite from the scene pipeline
	if cloud2 ~= nil then
		cloud2:doEvery(0, function()		-- repeat this stuff
			cloud2:animate(
				{x = 1300, duration = 190000},	-- move clouds left to right
				{x = -182}
			)
			return 191000		-- this number is delay before repeating; must be larger than duration of stuff we do above.
			end
		)
	end
	
	local cloud3 = scene:child("Cloud3")	-- get the cloud sprite from the scene pipeline
	if cloud3 ~= nil then
		cloud3:doEvery(0, function()		-- repeat this stuff
			cloud3:animate(
				{x = 1300, duration = 280000},	-- move clouds left to right
				{x = -162}
			)
			return 281000		-- this number is delay before repeating; must be larger than duration of stuff we do above.
			end
		)
	end
	
 -- LIGHT RAYS ------------------------------	
	local rays = scene:child("LightRays")	-- get the light ray sprite from the scene pipeline
	if rays ~= nil then
		rays:doEvery(0, function()		-- repeat this stuff
			rays:animate(
				{alpha=0.6, duration = math.Random( 2000,5000 )},	-- fade out the light rays
				{alpha=math.Random( 0.8, 1.0 ), duration = math.Random( 2000,5000 )}	-- fade in the light rays
			)
			return math.Random( 11000,13000 )		-- this number is delay before repeating; must be larger than duration of stuff we do above.
			end
		)
	end
	
	SCENESELECTION_palmTree1()
	SCENESELECTION_palmTree2()	
	SCENESELECTION_palmTree3()	
	SCENESELECTION_palmTree4()
	
	-- PALM TREE 5 --------------------------------
	local tree5 = scene:child("Tree5")	-- get the plant sprite from the scene pipeline
	if tree5 ~= nil then
		tree5:setPivotPoint("bottom")
		tree5:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,6000 )
			local dur2 = math.Random( 3000,6000 )
			local dur3 = math.Random( 3000,6000 )
			local dur4 = math.Random( 3000,6000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree5:animate(
				{skewx = (math.Random( 2, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -2, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -2 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -2, 1 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 6 --------------------------------
	local tree6 = scene:child("Tree6")	-- get the plant sprite from the scene pipeline
	if tree6 ~= nil then
		tree6:setPivotPoint("bottom")
		tree6:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,6000 )
			local dur2 = math.Random( 3000,6000 )
			local dur3 = math.Random( 3000,6000 )
			local dur4 = math.Random( 3000,6000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree6:animate(
				{skewx = (math.Random( 2, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -2, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -2 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -2, 1 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 7 --------------------------------
	local tree7 = scene:child("Tree7")	-- get the plant sprite from the scene pipeline
	if tree7 ~= nil then
		tree7:setPivotPoint("bottom")
		tree7:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 3000,4000 )
			local dur2 = math.Random( 3000,4000 )
			local dur3 = math.Random( 3000,4000 )
			local dur4 = math.Random( 3000,4000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree7:animate(
				{skewx = (math.Random( 2, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -2, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -2 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -2, 1 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	-- PALM TREE 8 --------------------------------
	local tree8 = scene:child("Tree8")	-- get the plant sprite from the scene pipeline
	if tree8 ~= nil then
		tree8:setPivotPoint("bottom")
		tree8:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,6000 )
			local dur2 = math.Random( 2000,6000 )
			local dur3 = math.Random( 2000,6000 )
			local dur4 = math.Random( 2000,6000 )
			local totalDuration = dur1 + dur2 + dur3 + dur4
			tree8:animate(
				{skewx = (math.Random( 3, -1 )*0.01), duration = dur1, style="easeOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random( -3, -1 )*0.01), duration = dur2, style="easeIn" },
				{skewx = (math.Random( 1, -3 )*0.01), duration = dur3, style="easeOut" },
				{skewx = (math.Random( -3, 1 )*0.01), duration = dur4, style="easeIn" }
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
	
	SCENESELECTION_CrocBlinkEyesController() 
	SCENESELECTION_CrocSplashController()
end

function SCENESELECTION_CrocBlinkEyesController()
	local blinkSprite = scene:child("CROC_BLINK")
	
	if blinkSprite ~= nil then
		blinkSprite:doEvery(0, function()		-- repeat this stuff
			if MENU_CROCODILE_SPLASHING == false then
				local dur1 = 80 * 23
				local dur2 = math.Random( 5000, 15000 )
				local totalDuration = dur1 + dur2
				blinkSprite:animate("CROC_BLINK", 
					{visible = true, startFrame=0, endFrame=23, frameTime = 80},
					{delay=dur1},	
					{frame=0}	
				)
				return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
				end
			end
		)
	end	
end

function SCENESELECTION_CrocSplashController()
	local crocSprite = scene:child("CROC_SPLASH")
	
	if crocSprite ~= nil then
		crocSprite:doEvery(math.Random( 3000, 7000), function()		-- repeat this stuff
			local blinkSprite = scene:child("CROC_BLINK")
			if blinkSprite ~= nil then
				local dur1 = 80 * 35
				local dur2 = math.Random( 10000, 15000 )
				local totalDuration = dur1 + dur2
				
				ghf.completeAnimation("CROC_BLINK")
				MENU_CROCODILE_SPLASHING = true
				crocSprite:animate(
					{sprite = blinkSprite, visible = false},
					{play = "SOUND_MAINMENU_CROC_JAW:sceneselection"},
					{visible = true, startFrame=0, endFrame=35, frameTime = 80},
					{delay=dur1},
					{sprite = blinkSprite, visible = true, frame=0},
					{call=function() SCENESELECTION_ClearCrocInfo() end}
				)
				return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
				end
			end
		)
	end	
end

function SCENESELECTION_ClearCrocInfo()
	MENU_CROCODILE_SPLASHING = false
end

--{play = "SOUND_MAINMENU_CHARACTER_BLINK:sceneselection"}
function SCENESELECTION_bringInAvatar(aShowCreditsButton)
 	local avitar = scene:child("Avitar")	-- get the Avitar sprite from the scene pipeline
 	local avitarHead = scene:child("AvitarHead")	-- get the Avitar Head sprite from the scene pipeline
 	local avitarBody = scene:child("AvitarBody")	-- get the Avitar Body sprite from the scene pipeline

	local blinkSprite = avitar:child("AvitarBlink")
	blinkSprite:setVisible(false)
	
	local creditsOrExtrasButton 
	if aShowCreditsButton == true then
		creditsOrExtrasButton = scene:child("BUTTON_CREDITS")
	else
		creditsOrExtrasButton = scene:child("BUTTON_EXTRAS")
	end
	
	if avitar ~= nil then
		
		if (avitarHead ~= nil) then
			 avitarHead:setVisible(true)
		end
		
		if (avitarBody ~= nil) then
			avitarBody:setVisible(true)
		end
		
		avitar:setVisible(false)
		
		endX = avitar:x()
		endY = avitar:y()

		local upDuration = 28
		local downDuration = 18
		avitar:animate(
			{play = "SOUND_MAINMENU_CHARACTER_JUMP:sceneselection"},	
			{x= -132, y = 169, visible=true},
			{x= -125, y = 159, duration=upDuration},
			{x= -119, y = 152, duration=upDuration},
			{x= -112, y = 144, duration=upDuration},
			{x= -105, y = 138, duration=upDuration},
			{x= -96, y = 131, duration=upDuration},						
			{x= -87, y = 125, duration=upDuration},
			{x= -76, y = 120, duration=upDuration},	
			{x= -63, y = 116, duration=upDuration},
			{x= -55, y = 115, duration=upDuration},	
			{x= -33, y = 117, duration=upDuration},
			{x= -25, y = 119, duration=upDuration},	
			{x= -17, y = 122, duration=upDuration},
			{x= -9, y = 126, duration=upDuration},	
			{x= -2, y = 131, duration=upDuration},
			{x= 1, y = 135, duration=downDuration},				
			{x= 7, y = 142, duration=downDuration},
			{x= 11, y = 148, duration=downDuration},	
			{x= 15, y = 156, duration=downDuration},
			{x= 19, y = 165, duration=downDuration},
			{x= 24, y = 178, duration=downDuration},
			{x= 29, y = 196, duration=downDuration},	
			{x= 32, y = 210, duration=downDuration},
			{x= 35, y = 226, duration=downDuration},
			{x= 38, y = 247, duration=downDuration},	
			{x= 40, y = 264, duration=downDuration},
			{x= 42, y = 282, duration=downDuration},
			{x= 43, y = 306, duration=downDuration},	
			{x= 44, y = 326, duration=downDuration},
			{x= 45, y = 351, duration=downDuration},
			{x= 45, y = 367, duration=downDuration},	
			{x= 45, y = 383, duration=downDuration},
			{x= 45, y = 397, duration=downDuration},
			{x= 45, y = 416, duration=downDuration},	
			{x= 44, y = 434, duration=downDuration},
			{y = 431, duration = 100},
			{y = 426, duration = 100},	
			{y = 434, duration = 100},
			{
				{sprite=scene:child("BUTTON_PLAY_QUEST"), visible=true, alpha=1.0, duration=500},
				{sprite=scene:child("BUTTON_PLAY_QUICKPLAY"), visible=true, alpha=1.0, duration=500}	
			},
			{delay=100},
			{command = "IntroSequenceComplete", target = scene},
			{
				{sprite=scene:child("BUTTON_SETTINGS"), visible=true, alpha=1.0, duration=500},
				{sprite=scene:child("BUTTON_HOWTOPLAY"), visible=true, alpha=1.0, duration=500},
				{sprite=scene:child("BUTTON_HIGHSCORES"), visible=true, alpha=1.0, duration=500},
				{sprite=creditsOrExtrasButton, visible=true, alpha=1.0, duration=500},	
				{sprite=scene:child("BUTTON_QUIT"), visible=true, alpha=1.0, duration=500},
					
			},
			{call = function() SCENESELECTION_AvatarBlinkEyesController() end}
		)
	end
end

-- TODO: Move to SuperCollapse4.lua because this isn't ambient-specific ?
-- Called from SceneSelection::OnActivate
function SCENESELECTION_dropLogo(aShowCreditsButton)
	-- Note that other timing is in TRANSITION_LOADED
 	local logo = scene:child("Logo")	-- get the logo sprite from the scene pipeline
	if logo ~= nil then
		logoHeight = logo:height()
		endY = logo:y()
		logo:animate(
			{play = "SOUND_MAINMENU_LOGO_FALLING:default"},	
			{y = endY - logoHeight - 200, visible=true},
			{y = endY + 16, duration = 200, style="easeOut"},	-- drop the logo
			{
				{play = "SOUND_MAINMENU_LOGO_HIT:default"},	
				{y = endY - 8, duration = 100},
			},
			{y = endY + 4, duration = 100},
			{y = endY - 2, duration = 100},	
			{y = endY, duration = 100},
			{delay = 250},
			{call=function() SCENESELECTION_bringInAvatar(aShowCreditsButton) end}
		)
	end

	local rays = scene:child("LightRays")	-- get the light ray sprite from the scene pipeline
	rays:animate(
		{delay = 900},
		{alpha = 1.0}
	)

	-- Do the vines at slightly different rates
	local	vine1 = scene:child("TopVines")
	if vine1 ~= nil then
		vine1:animate(
			{delay = 995},
			{dx = -200, visible = true},
			{dx = 200, duration = 195}
		)
	end
	-- Several items on the right are done with the exact same animation sequence
	local	vine2 = scene:child("TopVines2")
	local	rightSequence = {
		{delay = 1000},
		{dx = 200, visible = true},
		{dx = -200, duration = 205, style = "easeOut"}
	}
	if vine2 ~= nil then
		vine2:animate(rightSequence)
	end
	local	changeName = scene:child("BUTTON_CHANGENAME")
	if changeName ~= nil then
		changeName:animate(rightSequence)
	end
	local	playerName = scene:child("LABEL_PLAYERNAME")
	if playerName ~= nil then
		playerName:animate(rightSequence)
	end
	local	welcome = scene:child("LABEL_WELCOME")
	if welcome ~= nil then
		welcome:animate(rightSequence)
	end

	local	debug = scene:child("BUTTON_DEBUGMENU")
	if debug ~= nil then
		debug:animate({delay = 1000}, {visible = true})
	end

end


function SCENESELECTION_AvatarBlinkEyesController()

	local parent = scene:child("Avitar")
	
	if parent ~= nil then
		local blinkSprite = parent:child("AvitarBlink")
		
		if blinkSprite ~= nil then
			blinkSprite:setVisible(false)
			
			if blinkSprite ~= nil then
				blinkSprite:doEvery(0, function()		-- repeat this stuff
					local dur1 = math.Random( 5000, 6000 )
					local totalDuration = dur1
					blinkSprite:animate("AVITAR_BLINK", 
						{visible = true},
						{delay=100},	
						{visible = false}	
					)
					return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
					end	
				)
			end	
		end
	end
end

-- Called from SceneSelection::OnShow
function SCENESELECTION_prepareLogo()
 	local	logo = scene:child("Logo")
 	local	head = scene:child("AvitarHead")
 	local	body = scene:child("AvitarBody")
	local	vine1 = scene:child("TopVines")
	local	vine2 = scene:child("TopVines2")
	local	changeName = scene:child("BUTTON_CHANGENAME")
	local	playerName = scene:child("LABEL_PLAYERNAME")
	local	quest = scene:child("BUTTON_PLAY_QUEST")
	local	quick = scene:child("BUTTON_PLAY_QUICKPLAY")
	local	welcome = scene:child("LABEL_WELCOME")
	local	settings = scene:child("BUTTON_SETTINGS")
	local	howtoplay = scene:child("BUTTON_HOWTOPLAY")	
	local	highscores = scene:child("BUTTON_HIGHSCORES")
	local	extras = scene:child("BUTTON_EXTRAS")
	local	quit = scene:child("BUTTON_QUIT")
	local   credits = scene:child("BUTTON_CREDITS")
		
	logo:setVisible(false)
	head:setVisible(false)
	body:setVisible(false)
	quest:setAlpha(0)
	quick:setAlpha(0)
	quest:setVisible(false)
	quick:setVisible(false)
	vine1:setVisible(false)
	vine2:setVisible(false)
	changeName:setVisible(false)
	playerName:setVisible(false)
	welcome:setVisible(false)
	settings:setAlpha(0)
	howtoplay:setAlpha(0)
	highscores:setAlpha(0)
	extras:setAlpha(0)
	credits:setAlpha(0)
	quit:setAlpha(0)
	settings:setVisible(false)
	howtoplay:setVisible(false)
	highscores:setVisible(false)
	extras:setVisible(false)
	quit:setVisible(false)
	extras:setVisible(false)
	credits:setVisible(false)
	
	local rays = scene:child("LightRays")	-- get the light ray sprite from the scene pipeline
	rays:setAlpha(0)

	local	debug = scene:child("BUTTON_DEBUGMENU")
	if debug ~= nil then
		debug:setVisible(false)
	end
end

function SCENELANDMAP_BlinkEyes(aSprite, aX, aY)
	if aSprite ~= nil then
		aSprite:setPivotPoint("center")
		aSprite:setX(aX)
		aSprite:setY(aY)
		aSprite:doEvery(0, function()		-- repeat this stuff
			aSprite:setScale(1.0)
			aSprite:setVisible(false)
			local dur1 = math.Random( 300, 500 )
			local dur2 = math.Random( 20000, 60000 )
			local dur3 = math.Random( 2000, 5000 )
			local totalDuration = dur1 + dur1 + dur2 + dur3
			aSprite:animate(
				{scaley=0.0, visible=true},
				{scale=1.0, duration = dur1},
				{delay=dur3},
				{scaley = 0.0, duration = dur1, style="easeOut" },
				{visible=false},
				{delay=dur2}		
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end	
end


function SCENELANDMAP_JungleSetupEyes(aNodeIndex, aEyesIndex, aSprite, aOffsetX, aOffsetY)
	local startDelay = math.Random( 1000, 40000 )
	if aNodeIndex == 0 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 275 - aOffsetX, 420 - aOffsetY) end})
	elseif aNodeIndex == 1 then
		if aEyesIndex == 1 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 50 - aOffsetX, 190 - aOffsetY) end})
		elseif aEyesIndex == 2 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 160 - aOffsetX, 65 - aOffsetY) end})
		elseif aEyesIndex == 3 then			
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 210 - aOffsetX, 147 - aOffsetY) end})
		elseif aEyesIndex == 4 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 340 - aOffsetX, 40 - aOffsetY) end})
		elseif aEyesIndex == 5 then			
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 395 - aOffsetX, 315 - aOffsetY) end})
		end
	elseif aNodeIndex == 2 then
		if aEyesIndex == 1 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 490 - aOffsetX, 5 - aOffsetY) end})
		elseif aEyesIndex == 2 then			
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 630 - aOffsetX, 40 - aOffsetY) end})
		end
	elseif aNodeIndex == 3 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 840 - aOffsetX, 25 - aOffsetY) end})
	elseif aNodeIndex == 4 then
		if aEyesIndex == 1 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1125 - aOffsetX, 20 - aOffsetY) end})
		elseif aEyesIndex == 2 then			
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1230 - aOffsetX, 80 - aOffsetY) end})
		end
	elseif aNodeIndex == 5 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1485 - aOffsetX, 45 - aOffsetY) end})
	elseif aNodeIndex == 6 then
		if aEyesIndex == 1 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 45 - aOffsetX, 570 - aOffsetY) end})
		elseif aEyesIndex == 2 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 130 - aOffsetX, 745 - aOffsetY) end})
		elseif aEyesIndex == 3 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 45 - aOffsetX, 570 - aOffsetY) end})
		end
	elseif aNodeIndex == 7 then
		if aEyesIndex == 1 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 385 - aOffsetX, 415 - aOffsetY) end})
		elseif aEyesIndex == 2 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 550 - aOffsetX, 750 - aOffsetY) end})
		end
	elseif aNodeIndex == 8 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 830 - aOffsetX, 560 - aOffsetY) end})
	elseif aNodeIndex == 9 then
		if aEyesIndex == 1 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1150 - aOffsetX, 56 - aOffsetY) end})
		elseif aEyesIndex == 2 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1075 - aOffsetX, 730 - aOffsetY) end})
		end
	elseif aNodeIndex == 10 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1290 - aOffsetX, 500 - aOffsetY) end})
	elseif aNodeIndex == 11 then
		return
	elseif aNodeIndex == 12 then
		if aEyesIndex == 1 then	
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 495 - aOffsetX, 380 - aOffsetY) end})
		elseif aEyesIndex == 2 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 590 - aOffsetX, 300 - aOffsetY) end})
		elseif aEyesIndex == 3 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 590 - aOffsetX, 400 - aOffsetY) end})
		elseif aEyesIndex == 4 then			
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 700 - aOffsetX, 290 - aOffsetY) end})
		elseif aEyesIndex == 5 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 785 - aOffsetX, 240 - aOffsetY) end})
		elseif aEyesIndex == 6 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 850 - aOffsetX, 510 - aOffsetY) end})
		elseif aEyesIndex == 7 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1005 - aOffsetX, 335 - aOffsetY) end})
		elseif aEyesIndex == 8 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 960 - aOffsetX, 275 - aOffsetY) end})
		end
	elseif aNodeIndex == 13 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1600 - aOffsetX, 100 - aOffsetY) end})
	elseif aNodeIndex == 14 then
		if aEyesIndex == 1 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1630 - aOffsetX, 35 - aOffsetY) end})
		elseif aEyesIndex == 2 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1710 - aOffsetX, 70 - aOffsetY) end})
		elseif aEyesIndex == 3 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1705 - aOffsetX, 175 - aOffsetY) end})
		elseif aEyesIndex == 4 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1865 - aOffsetX, 40 - aOffsetY) end})
		elseif aEyesIndex == 5 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1900 - aOffsetX, 150 - aOffsetY) end})
		elseif aEyesIndex == 6 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1820 - aOffsetX, 235 - aOffsetY)	 end})
		end	
	elseif aNodeIndex == 15 then
		aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, 1185 - aOffsetX, 290 - aOffsetY) end})
	elseif aNodeIndex == 17 then
		if aEyesIndex == 1 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -290 - aOffsetX, 570 - aOffsetY) end})
		elseif aEyesIndex == 2 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -350 - aOffsetX, 680 - aOffsetY) end})
		elseif aEyesIndex == 3 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -360 - aOffsetX, 525 - aOffsetY) end})
		elseif aEyesIndex == 4 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -305 - aOffsetX, 210 - aOffsetY) end})
		end
	elseif aNodeIndex == 18 then
		if aEyesIndex == 1 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -60 - aOffsetX, 565 - aOffsetY) end})
		elseif aEyesIndex == 2 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -100 - aOffsetX, 675 - aOffsetY) end})
		elseif aEyesIndex == 3 then
			aSprite:animate({delay=startDelay},{call=function() SCENELANDMAP_BlinkEyes(aSprite, -185 - aOffsetX, 5 - aOffsetY) end})
		end
	end
end	


function SCENELANDMAP_UnderwaterStartBubbles()
	local parent = scene:child("mapitemscontainer")
	local bubble1 = parent:newChildSprite({class = "ParticleEffect", x = 287, y = 196, library = "PARTICLE_AMBIENT_BUBBLE_1", section = "scenelandunderwater", name = "Bubble1", play = true})	
	if bubble1 ~= nil then
		bubble1:play()
		bubble1:addInitialTime(5000)
	end
	
	local bubble2 = parent:newChildSprite({class = "ParticleEffect", x = 1082, y = 388, library = "PARTICLE_AMBIENT_BUBBLE_1", section = "scenelandunderwater", name = "Bubble2", play = true})	
	if bubble2 ~= nil then
		bubble2:play()
		bubble2:addInitialTime(5000)
	end
	
	local bubble3 = parent:newChildSprite({class = "ParticleEffect", x = 1607, y = 318, library = "PARTICLE_AMBIENT_BUBBLE_1", section = "scenelandunderwater", name = "Bubble3", play = true})	
	if bubble3 ~= nil then
		bubble3:play()
		bubble3:addInitialTime(5000)
	end			

	local bubble4 = parent:newChildSprite({class = "ParticleEffect", x = 429, y = 392, library = "PARTICLE_AMBIENT_BUBBLE_2", section = "scenelandunderwater", name = "Bubble4", play = true})	
	if bubble4 ~= nil then
		bubble4:play()
		bubble4:addInitialTime(5000)
	end		
	
	local bubble5 = parent:newChildSprite({class = "ParticleEffect", x = 1463, y = 112, library = "PARTICLE_AMBIENT_BUBBLE_2", section = "scenelandunderwater", name = "Bubble5", play = true})	
	if bubble5 ~= nil then
		bubble5:play()
		bubble5:addInitialTime(5000)
	end		
	
	local bubble6 = parent:newChildSprite({class = "ParticleEffect", x = 523, y = 740, library = "PARTICLE_AMBIENT_BUBBLE_3", section = "scenelandunderwater", name = "Bubble6", play = true})	
	if bubble6 ~= nil then
		bubble6:play()
		bubble6:addInitialTime(5000)
	end	
	
	local bubble7 = parent:newChildSprite({class = "ParticleEffect", x = 1240, y = 478, library = "PARTICLE_AMBIENT_BUBBLE_2", section = "scenelandunderwater", name = "Bubble7", play = true})	
	if bubble7 ~= nil then
		bubble7:play()
		bubble7:addInitialTime(5000)
	end	
	
	local bubble8 = parent:newChildSprite({class = "ParticleEffect", x = 1981, y = 692, library = "PARTICLE_AMBIENT_BUBBLE_2", section = "scenelandunderwater", name = "Bubble8", play = true})	
	if bubble8 ~= nil then
		bubble8:play()
		bubble5:addInitialTime(5000)
	end			
end

function SCENELANDMAP_AddBombWorldFuse(aX, aY, aName)
	local parent = scene:child("mapitemscontainer")
	local smoke = parent:newChildSprite({class = "ParticleEffect", x = aX, y = aY, library = "PARTICLE_FUSESMOKE", section = "scenelandbomb", name = aName.."Smoke", play = true})		
	local fuse = parent:newChildSprite({class = "ParticleEffect", x = aX, y = aY, library = "PARTICLE_FUSE", section = "scenelandbomb", name = aName.."Fuse", play = true})
	local mineCart = parent:child("MINE_CART")
	if smoke ~= nil then
		smoke:moveBehind(mineCart)
		smoke:play()
		smoke:addInitialTime(5000)
	end
	if fuse ~= nil then
		fuse:moveBehind(mineCart)
		fuse:play()
		fuse:addInitialTime(5000)
	end
end

function SCENELANDMAP_AddBombWorldRain(aX, aY, aName)
	local parent = scene:child("mapitemscontainer")
	
	local rainParticle = parent:child("aName")
	
	if rainParticle == nil then
		rainParticle = parent:newChildSprite({class = "ParticleEffect", x = aX, y = aY, library = "PARTICLE_BOMBWORLD_RAIN", section = "scenelandbomb", name = aName, play = true})		
		if rainParticle ~= nil then
			rainParticle:play()
			rainParticle:addInitialTime(5000)
		end
	end
end

function SCENELANDMAP_BombWorldStartMineCart()
	
	local parent = scene:child("mapitemscontainer")
	local mineCart = parent:child("MINE_CART")
	if mineCart ~= nil then
		mineCart:setY(833)
		mineCart:setVisible(true)
		mineCart:doEvery(0, function()		-- # tells animation how long to wait before starting
			local point1_x = 1060
			local point1_y = 833
			
			local point2_x = 1934
			local point2_y = -222
			
			local destX
			local destY
			
			if mineCart:y() == point1_y then
				destX = point2_x
				destY = point2_y
			else
				destX = point1_x
				destY = point1_y
			end
			
			travelDuration = 5000
			mineCart:animate(
				{x=destX, y=destY, duration = travelDuration},
				{delay = travelDuration}
			)
			return math.Random( 15000, 25000 )	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENELANDMAP_CityStartAmbients()
	local carBlinker1 = scene:child("CAR_BLINKERS01")
	if carBlinker1 ~= nil then
		carBlinker1:doEvery(0, function()		-- # tells animation how long to wait before starting
			carBlinker1:animate(
				{alpha = 0, duration = 150},
				{delay = 450},
				{alpha = 1, duration = 150}
			)
			return 750	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
	
	local carBlinker2 = scene:child("CAR_BLINKERS02")
	if carBlinker2 ~= nil then
		carBlinker2:doEvery(0, function()		-- # tells animation how long to wait before starting
			carBlinker2:animate(
				{alpha = 0, duration = 150},
				{delay = 450},
				{alpha = 1, duration = 150}
			)
			return 750	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
	
	local coffeeSign = scene:child("COFFEE_SIGN01")
	if coffeeSign ~= nil then
		coffeeSign:setVisible(false)
		coffeeSign:doEvery(math.Random( 5000, 10000 ), function()		-- # tells animation how long to wait before starting
			local randPick = math.Random(1,3)
			if randPick == 1 then
				coffeeSign:animate(
					{visible=true},
					{delay = 80},
					{visible=false},
					{delay = 100},
					{visible=true},
					{delay = 200},
					{visible=false},
					{delay = 80},
					{visible=true},
					{delay = 100},
					{visible=false}
				)
			elseif randPick == 2 then
				coffeeSign:animate(
					{visible=true},
					{delay = 80},
					{visible=false},
					{delay = 200},
					{visible=true},
					{delay = 200},
					{visible=false}
				)
			else
				coffeeSign:animate(
					{visible=true},
					{delay = 200},
					{visible=false},
					{delay = 100},
					{visible=true},
					{delay = 80},
					{visible=false}
				)
			end
			return math.Random( 5000, 10000 )	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end

	SCENELANDMAP_CityAddParticle(1847, 321, "PARTICLE_SHORTCIRCUIT", "ParticleShortCircuit1")
	SCENELANDMAP_CityAddParticle(1321, 227, "PARTICLE_SHORTCIRCUIT", "ParticleShortCircuit2")
		
	SCENELANDMAP_CityAddParticle(1559, 421, "PARTICLE_WIRESPARKS", "ParticleWireSparks1")
	SCENELANDMAP_CityAddParticle(1157, 381, "PARTICLE_WIRESPARKS", "ParticleWireSparks2")
	
	SCENELANDMAP_CityAddParticle(913, 740, "PARTICLE_STEAM", "ParticleSteam1")
	SCENELANDMAP_CityAddParticle(1221, 243, "PARTICLE_STEAM", "ParticleSteam2")
	SCENELANDMAP_CityAddParticle(108, 66, "PARTICLE_STEAM", "ParticleSteam3")
	SCENELANDMAP_CityAddParticle(821, 906, "PARTICLE_STEAM", "ParticleSteam4")
end

function SCENELANDMAP_CityAddParticle(aX, aY, aLibrary, aName)
	local parent = scene:child("mapitemscontainer")	
	local particle = parent:newChildSprite({class="ParticleEffect", x=aX, y=aY, library=aLibrary, section="scenelandcity", name=aName, true })
	if particle ~= nil then
		particle:play()
		particle:addInitialTime(5000)
	end
end

function SCENELANDMAP_CityMoveWater(aSprite, aPixelCounts, aStartY)

	if aSprite ~= nil then
		aSprite:doEvery(0, function()		-- # tells animation how long to wait before starting
			local waveDelay = 300
			aSprite:animate(
				{y = aStartY + aPixelCounts[1]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[2]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[3]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[4]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[5]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[6]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[7]},
				{delay = waveDelay},
				{y = aStartY + aPixelCounts[8]},
				{delay = waveDelay}
			)
			return (waveDelay * 8) 	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENELANDMAP_SnowStartSnowing()
	local parent = scene:child("mapitemscontainer")	
	local snow1 = parent:newChildSprite({class="ParticleEffect", x=200, y=50, library="PARTICLE_SNOW_1", section="scenelandsnow", name="ParticleSnow1", true })
	if snow1 ~= nil then
		snow1:play()
		snow1:addInitialTime(25000)
	end
end

function SCENELANDMAP_DesertStartRockTilt()
	local rock = scene:child("ROCK_TILT")
	if rock ~= nil then
		if not scene:child("SPOT_OVERLAY_17"):visible() then
			rock:animate({ visible = true, startFrame=0, endFrame=15, frameTime = 200, loops="forever", type="pingpong" })
		else
			rock:setVisible(false)
		end
	end
end

function SCENELANDMAP_SetNumberOfDesertTornados(aNumTornados)
	DESERT_NUM_TORNADOS = aNumTornados
end

function SCENELANDMAP_AddDesertTornado(aX, aY)
	DESERT_NUM_TORNADOS = DESERT_NUM_TORNADOS + 1
	local zOrderNode = scene:child("AVATAR_ZORDER_PLACEHOLDER")
	local parent = scene:child("AMBIENT_TORNADO_CONTROLLER")
	local tornado = parent:newChildSprite({class = "ParticleEffect", x = aX, y = aY, library = "PARTICLE_DESERTLANDMAP_TORNADO", section = "scenelanddesert", name = "Tornado"..DESERT_NUM_TORNADOS, play = false})		
	if tornado ~= nil then
		if zOrderNode ~= nil then
			tornado:moveBehind(zOrderNode)
		end
	end
end

function SCENELANDMAP_StartDesertTornados()
	if DESERT_NUM_TORNADOS > 0 then
		
		local parent = scene:child("mapitemscontainer")
		local tornadoController = parent:child("AMBIENT_TORNADO_CONTROLLER")
		
		if tornadoController ~= nil then
			tornadoController:doEvery(0, function()								-- repeat this stuff
				
				local totalDuration = 6000
					
				local rnd = math.Random(1, DESERT_NUM_TORNADOS)
				local tornado = parent:child("Tornado"..rnd)
				if tornado ~= nil then
				
					local tornadoX = tornado:x()
					local tornadoY = tornado:y()
					tornado:removeFromParent()
					tornado = tornadoController:newChildSprite({class = "ParticleEffect", x = tornadoX, y = tornadoY, library = "PARTICLE_DESERTLANDMAP_TORNADO", section = "scenelanddesert", name = "Tornado"..rnd, play = false})		
						
					if tornado ~= nil then
						local zOrderNode = scene:child("AVATAR_ZORDER_PLACEHOLDER")
						if zOrderNode ~= nil then
							tornado:moveBehind(zOrderNode)
							tornado:animate{visible=true}
							tornado:play()
						end
					end
				end
				return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
				end
			)	
		end
	end
end

function SCENELANDMAP_StartDesertSnakeTail(aIndex)
	local parent = scene:child("mapitemscontainer")	
	local snakeTail = parent:child("SNAKE_TAIL0"..aIndex)
				
	if snakeTail ~= nil then
		snakeTail:doEvery(math.Random(30000, 40000), function()								-- repeat this stuff
				
			local totalDuration = math.Random(30000, 40000)
			
			local snakeTailY = snakeTail:y()
			snakeTail:animate(
				{y=snakeTailY-50, duration=300},
				{delay=math.Random(5000, 6000)},
				{y=snakeTailY, duration=300}
			)
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
end

function SCENELANDMAP_StartGardenAmbients()
	local parent = scene:child("mapitemscontainer")	
	dandelion = parent:newChildSprite({class="ParticleEffect", x=parent:x() + 2048, y=parent:y() + 768, library="PARTICLE_DANDELION", section="scenelandgarden", name="ParticleDandelion1", true })
	dandelion:play()
	dandelion:addInitialTime(25000)		
end

function SCENELANDMAP_AlienAddParticle(aLibraryName, aSectionName, aX, aY, aName)
	local parent = scene:child("mapitemscontainer")
	local particle = parent:newChildSprite({class = "ParticleEffect", x = aX, y = aY, library = aLibraryName, section = aSectionName, name = aName, play = true})		
	if particle ~= nil then
print("PARTICLE: ", aName)	
		particle:play()
		particle:addInitialTime(math.Random(3000, 10000))	
	end
end

function SCENELANDMAP_AlienFadeOutFogOfWar()
	local parent = scene:child("mapitemscontainer")
	local particle = parent:child("ParticleFogOfWar")
	if particle ~= nil then
		particle:animate(
			{alpha=0.0, duration=1000}
		)
	end	
end

function SCENELANDMAP_FadeOutAlienParticle(aName)
	local parent = scene:child("mapitemscontainer")
	local particle = parent:child(aName)
	if particle ~= nil then
		particle:animate(
			{alpha=0.0, duration=1000}
		)
	end	
end

function SCENELANDMAP_AlienBlinkLights()
	local parent = scene:child("mapitemscontainer")
	local ufoLight1 = parent:child("UFO_LIGHT_BLINK01")
	local ufoLight2 = parent:child("UFO_LIGHT_BLINK02")
	local ufoLight3 = parent:child("UFO_LIGHT_BLINK03")
	local ufoLight4 = parent:child("UFO_LIGHT_BLINK04")
	local ufoLight5 = parent:child("UFO_LIGHT_BLINK05")
	local ufoLight6 = parent:child("UFO_LIGHT_BLINK06")
	local ufoLight7 = parent:child("UFO_LIGHT_BLINK07")
	local ufoLight8 = parent:child("UFO_LIGHT_BLINK08")
	local ufoLight9 = parent:child("UFO_LIGHT_BLINK09")
	local ufoLight10 = parent:child("UFO_LIGHT_BLINK10")
	local ufoLight11 = parent:child("UFO_LIGHT_BLINK11")
	local ufoLight12 = parent:child("UFO_LIGHT_BLINK12")
	local ufoLight13 = parent:child("UFO_LIGHT_BLINK13")
	local ufoLight14 = parent:child("UFO_LIGHT_BLINK14")
	local ufoLight15 = parent:child("UFO_LIGHT_BLINK15")	
	

	ufoLight1:doEvery(0, function()		-- repeat this stuff	
		
		local rnd = math.Random(1, 6)
		local startDelay
		if rnd < 5 then
			startDelay = 4500 
			local blinkDelay = 150
			ufoLight1:animate(
				{visible=false},
				{delay=blinkDelay},
				{
					{visible=true},
					{sprite=ufoLight2, visible=false},
				},
				{delay=blinkDelay},
				{
					{sprite=ufoLight2, visible=true},
					{sprite=ufoLight3, visible=false},
				},
				{delay=blinkDelay},
				{
					{sprite=ufoLight3, visible=true},
					{sprite=ufoLight4, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight4, visible=true},
					{sprite=ufoLight5, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight5, visible=true},
					{sprite=ufoLight6, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight6, visible=true},
					{sprite=ufoLight7, visible=false},
				},			
				{delay=blinkDelay},
				{
					{sprite=ufoLight7, visible=true},
					{sprite=ufoLight8, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight8, visible=true},
					{sprite=ufoLight9, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight9, visible=true},
					{sprite=ufoLight10, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight10, visible=true},
					{sprite=ufoLight11, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight11, visible=true},
					{sprite=ufoLight12, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight12, visible=true},
					{sprite=ufoLight13, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight13, visible=true},
					{sprite=ufoLight14, visible=false},
				},		
					
				{delay=blinkDelay},
				{
					{sprite=ufoLight14, visible=true},
					{sprite=ufoLight15, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight15, visible=true},
				}	
			)
		elseif rnd == 5 then
			local blinkDelay = 150 
			startDelay = 150 * 4
			ufoLight1:animate(
				{delay=blinkDelay},
				{
					{visible=true},
					{sprite=ufoLight11, visible=false},
				},
				{delay=blinkDelay},
				{
					{sprite=ufoLight11, visible=true},
					{sprite=ufoLight9, visible=false},
				},
				{delay=blinkDelay},
				{
					{sprite=ufoLight9, visible=true},
					{sprite=ufoLight4, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight4, visible=true},
					{sprite=ufoLight2, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight2, visible=true},
					{sprite=ufoLight10, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight10, visible=true},
					{sprite=ufoLight5, visible=false},
				},			
				{delay=blinkDelay},
				{
					{sprite=ufoLight5, visible=true},
					{sprite=ufoLight3, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight3, visible=true},
					{sprite=ufoLight8, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight8, visible=true},
					{sprite=ufoLight15, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight15, visible=true},
					{sprite=ufoLight11, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight11, visible=true},
					{sprite=ufoLight7, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight7, visible=true},
					{sprite=ufoLight15, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight15, visible=true},
					{sprite=ufoLight14, visible=false},
				},		
					
				{delay=blinkDelay},
				{
					{sprite=ufoLight14, visible=true},
					{sprite=ufoLight6, visible=false},
				},		
				{delay=blinkDelay},
				{
					{sprite=ufoLight6, visible=true},
				}	
			)
		elseif rnd == 6 then
			local blinkDelay = 150 
			startDelay = 150 * 4
			ufoLight1:animate(
				{
					{visible=false},
					{delay=blinkDelay},
					
					{sprite=ufoLight2, visible=false},
					{sprite=ufoLight3, visible=false},
					{sprite=ufoLight4, visible=false},
					{sprite=ufoLight5, visible=false},
					{sprite=ufoLight6, visible=false},
					{sprite=ufoLight7, visible=false},
					{sprite=ufoLight8, visible=false},
					{sprite=ufoLight9, visible=false},
					{sprite=ufoLight10, visible=false},
					{sprite=ufoLight11, visible=false},
					{sprite=ufoLight12, visible=false},
					{sprite=ufoLight13, visible=false},
					{sprite=ufoLight14, visible=false},
					{sprite=ufoLight15, visible=false},
				},
				{delay=blinkDelay},
				{
					{visible=true},
					{sprite=ufoLight2, visible=true},
					{sprite=ufoLight3, visible=true},
					{sprite=ufoLight4, visible=true},
					{sprite=ufoLight5, visible=true},
					{sprite=ufoLight6, visible=true},
					{sprite=ufoLight7, visible=true},
					{sprite=ufoLight8, visible=true},
					{sprite=ufoLight9, visible=true},
					{sprite=ufoLight10, visible=true},
					{sprite=ufoLight11, visible=true},
					{sprite=ufoLight12, visible=true},
					{sprite=ufoLight13, visible=true},
					{sprite=ufoLight14, visible=true},
					{sprite=ufoLight15, visible=true},
				},
				{delay=blinkDelay},
				{
					{visible=false},
					{sprite=ufoLight2, visible=false},
					{sprite=ufoLight3, visible=false},
					{sprite=ufoLight4, visible=false},
					{sprite=ufoLight5, visible=false},
					{sprite=ufoLight6, visible=false},
					{sprite=ufoLight7, visible=false},
					{sprite=ufoLight8, visible=false},
					{sprite=ufoLight9, visible=false},
					{sprite=ufoLight10, visible=false},
					{sprite=ufoLight11, visible=false},
					{sprite=ufoLight12, visible=false},
					{sprite=ufoLight13, visible=false},
					{sprite=ufoLight14, visible=false},
					{sprite=ufoLight15, visible=false},
				},
				{delay=blinkDelay},
				{
					{visible=true},
					{sprite=ufoLight2, visible=true},
					{sprite=ufoLight3, visible=true},
					{sprite=ufoLight4, visible=true},
					{sprite=ufoLight5, visible=true},
					{sprite=ufoLight6, visible=true},
					{sprite=ufoLight7, visible=true},
					{sprite=ufoLight8, visible=true},
					{sprite=ufoLight9, visible=true},
					{sprite=ufoLight10, visible=true},
					{sprite=ufoLight11, visible=true},
					{sprite=ufoLight12, visible=true},
					{sprite=ufoLight13, visible=true},
					{sprite=ufoLight14, visible=true},
					{sprite=ufoLight15, visible=true},
				}
			)
		end	
		return startDelay   		-- this number is delay before repeating; must be larger than the total of the longest times above
		end
	)
end

function SCENEWORLDMAP_StartAmbientAnimations()
	local parent = scene:child("mapitemscontainer")
	if parent ~= nil then
		local snow = parent:newChildSprite({class = "ParticleEffect", x = 776, y = 0, library = "PARTICLE_WORLDMAP_SNOW", section = "sceneworldmap", name = "WorldMapSnow", play = true})		
		if snow ~= nil then
			snow:play()
			snow:addInitialTime(3000)	
		end
	end

	local smoke1 = parent:newChildSprite({class = "ParticleEffect", x = 1606, y = 408, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke1", play = true})		
	local fuse1 = parent:newChildSprite({class = "ParticleEffect", x = 1606, y = 408, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse1", play = true})
	smoke1:play()
	fuse1:play()
	smoke1:addInitialTime(5000)
	fuse1:addInitialTime(5000)
	
	local smoke2 = parent:newChildSprite({class = "ParticleEffect", x = 1775, y = 389, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke2", play = true})		
	local fuse2 = parent:newChildSprite({class = "ParticleEffect", x = 1775, y = 389, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse2", play = true})
	smoke2:play()
	fuse2:play()
	smoke2:addInitialTime(5000)
	fuse2:addInitialTime(5000)	
	
	local smoke3 = parent:newChildSprite({class = "ParticleEffect", x = 1918, y = 493, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke3", play = true})		
	local fuse3 = parent:newChildSprite({class = "ParticleEffect", x = 1918, y = 493, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse3", play = true})
	smoke3:play()
	fuse3:play()
	smoke3:addInitialTime(5000)
	fuse3:addInitialTime(5000)	
	
	local smoke4 = parent:newChildSprite({class = "ParticleEffect", x = 2016, y = 520, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke4", play = true})		
	local fuse4 = parent:newChildSprite({class = "ParticleEffect", x = 2016, y = 520, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse4", play = true})
	smoke4:play()
	fuse4:play()
	smoke4:addInitialTime(5000)
	fuse4:addInitialTime(5000)	
	
	local smoke5 = parent:newChildSprite({class = "ParticleEffect", x = 1859, y = 686, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke5", play = true})		
	local fuse5 = parent:newChildSprite({class = "ParticleEffect", x = 1859, y = 686, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse5", play = true})
	smoke5:play()
	fuse5:play()
	smoke5:addInitialTime(5000)
	fuse5:addInitialTime(5000)	
	
	local smoke6 = parent:newChildSprite({class = "ParticleEffect", x = 1691, y = 699, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke6", play = true})		
	local fuse6 = parent:newChildSprite({class = "ParticleEffect", x = 1691, y = 699, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse6", play = true})
	smoke6:play()
	fuse6:play()
	smoke6:addInitialTime(5000)
	fuse6:addInitialTime(5000)	
	
	local smoke7 = parent:newChildSprite({class = "ParticleEffect", x = 1798, y = 569, library = "PARTICLE_WORLDMAPFUSESMOKE", section = "sceneworldmap", name = "Smoke7", play = true})		
	local fuse7 = parent:newChildSprite({class = "ParticleEffect", x = 1798, y = 569, library = "PARTICLE_WORLDMAPFUSE", section = "sceneworldmap", name = "Fuse7", play = true})
	smoke7:play()
	fuse7:play()	
	smoke7:addInitialTime(5000)
	fuse7:addInitialTime(5000)	

	local dandelion = parent:newChildSprite({class = "ParticleEffect", x = 1512, y = 222, library = "PARTICLE_DANDELION", section = "sceneworldmap", name = "Dandelion", play = true})		
	dandelion:play()
	dandelion:addInitialTime(5000)
	
	local tornadoController = scene:child("AMBIENT_TORNADO_CONTROLLER")

	if tornadoController ~= nil then
		tornadoController:doEvery(0, function()								-- repeat this stuff
			local totalDuration = math.Random( 8000, 12000 )
	
			local tornado = parent:child("Tornado")
			if tornado ~= nil then
				tornado:removeFromParent()
			end
			
			tornado = parent:newChildSprite({class = "ParticleEffect", x = 1992, y = 196, library = "PARTICLE_TORNADO", section = "sceneworldmap", name = "Tornado", play = true})		
		
			local rnd = math.Random(1, 3)			
			
			if rnd == 1 then
				tornado:setX(1992)
				tornado:setY(196)
			elseif rnd == 2 then
				tornado:setX(1788)
				tornado:setY(331)
			elseif rnd == 3 then
				tornado:setX(1680)
				tornado:setY(37)
			end
			tornado:play()
			return totalDuration  		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)	
	end
	
	local treeSway1 = parent:child("TREE_SWAY01")
	if treeSway1 ~= nil then
		treeSway1:setPivotPoint("bottom")
		treeSway1:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2
			treeSway1:animate(
				{skewx = (math.Random(4, 1)*0.01), duration = dur1, style="easeInOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random(-1, -4)*0.01), duration = dur2, style="easeInOut" }
			)
			return totalDuration		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end

	local treeSway2 = parent:child("TREE_SWAY02")
	if treeSway2 ~= nil then
		treeSway2:setPivotPoint("bottom")
		treeSway2:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2
			treeSway2:animate(
				{skewx = (math.Random(4, 1)*0.01), duration = dur1, style="easeInOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random(-1, -4)*0.01), duration = dur2, style="easeInOut" }
			)
			return totalDuration		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	
	local treeSway3 = parent:child("TREE_SWAY03")
	if treeSway3 ~= nil then
		treeSway3:setPivotPoint("bottom")
		treeSway3:doEvery(0, function()		-- repeat this stuff
			local dur1 = math.Random( 2000,3000 )
			local dur2 = math.Random( 2000,3000 )
			local totalDuration = dur1 + dur2
			treeSway3:animate(
				{skewx = (math.Random(4, 1)*0.01), duration = dur1, style="easeInOut" },	-- math.Random makes a random number between lower and upper INTEGER
				{skewx = (math.Random(-1, -4)*0.01), duration = dur2, style="easeInOut" }
			)
			return totalDuration		-- this number is delay before repeating; must be larger than the total of the longest times above
			end
		)
	end
	

	SCENEWORLDMAP_StartWaterRipple1()
	SCENEWORLDMAP_StartWaterRipple2()
	SCENEWORLDMAP_StartWaterRipple3()
	SCENEWORLDMAP_StartWaterRipple4()
	SCENEWORLDMAP_StartWaterRipple5()
	SCENEWORLDMAP_StartWaterRipple6()
	SCENEWORLDMAP_StartWaterRipple7()
	
	local carBlinker1 = scene:child("CAR_LIGHT_01")
	if carBlinker1 ~= nil then
		carBlinker1:doEvery(450, function()		-- # tells animation how long to wait before starting
			carBlinker1:animate(
				{alpha = 0, duration = 150},
				{delay = 450},
				{alpha = 1, duration = 150}
			)
			return 750	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
	
	local carBlinker2 = scene:child("CAR_LIGHT_02")
	if carBlinker2 ~= nil then
		carBlinker2:doEvery(0, function()		-- # tells animation how long to wait before starting
			carBlinker2:animate(
				{alpha = 0, duration = 150},
				{delay = 450},
				{alpha = 1, duration = 150}
			)
			return 750	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
	
	local carBlinker3 = scene:child("CAR_LIGHT_03")
	if carBlinker3 ~= nil then
		carBlinker3:doEvery(450, function()		-- # tells animation how long to wait before starting
			carBlinker3:animate(
				{alpha = 0, duration = 150},
				{delay = 450},
				{alpha = 1, duration = 150}
			)
			return 750	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
	
end

function SCENEWORLDMAP_StartWaterRipple1()
					
	local waterRipple = scene:child("WAVES01")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_1 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_1 + 10
			local middleX = WORLDMAP_RIPPLE_X_1
			local endX = WORLDMAP_RIPPLE_X_1 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartWaterRipple2()
					
	local waterRipple = scene:child("WAVES02")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_2 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_2 + 10
			local middleX = WORLDMAP_RIPPLE_X_2
			local endX = WORLDMAP_RIPPLE_X_2 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartWaterRipple3()
					
	local waterRipple = scene:child("WAVES03")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_3 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_3 + 10
			local middleX = WORLDMAP_RIPPLE_X_3
			local endX = WORLDMAP_RIPPLE_X_3 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartWaterRipple4()
					
	local waterRipple = scene:child("WAVES04")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_4 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_4 + 10
			local middleX = WORLDMAP_RIPPLE_X_4
			local endX = WORLDMAP_RIPPLE_X_4 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartWaterRipple5()
					
	local waterRipple = scene:child("WAVES05")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_5 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_5 + 10
			local middleX = WORLDMAP_RIPPLE_X_5
			local endX = WORLDMAP_RIPPLE_X_5 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartWaterRipple6()
					
	local waterRipple = scene:child("WAVES06")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_6 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_6 + 10
			local middleX = WORLDMAP_RIPPLE_X_6
			local endX = WORLDMAP_RIPPLE_X_6 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartWaterRipple7()
					
	local waterRipple = scene:child("WAVES07")
	if waterRipple ~= nil then
		
		WORLDMAP_RIPPLE_X_7 = waterRipple:x();
		
		waterRipple:animate(
			{ visible = true, startFrame=0, endFrame=5, frameTime = math.Random( 175, 225 ), loops="forever", type="pingpong" })
			
		waterRipple:doEvery(0, function()		-- # tells animation how long to wait before starting
			local startX = WORLDMAP_RIPPLE_X_7 + 10
			local middleX = WORLDMAP_RIPPLE_X_7
			local endX = WORLDMAP_RIPPLE_X_7 - 10			
			
			local driftDuration = math.Random( 1000, 1200 )	
			local fadeDuration = 100

			waterRipple:animate(
				{x = startX, alpha=0.0},
				{x = middleX, alpha = 1.0, duration = driftDuration},
				{x = endX, alpha=0.0, duration = driftDuration}
			)
			return driftDuration + driftDuration + 100	-- this number is delay before repeating; must be larger than duration of stuff we do above
			end
		)
	end
end

function SCENEWORLDMAP_StartFogOfWar()
	local parent = scene:child("WORLDMAP_BG01")
	local fogOfWar = parent:newChildSprite({class = "ParticleEffect", x = 1288, y = 574, library = "PARTICLE_FOGOFWAR", section = "sceneworldmap", name = "FogOfWar", play = true})		
	fogOfWar:play()
	fogOfWar:addInitialTime(5000)
end

SNOWFLAKE_INDEX_CTR = 1
MENU_CROCODILE_SPLASHING = false
DESERT_NUM_TORNADOS = 0

WORLDMAP_RIPPLE_X_1 = 0
WORLDMAP_RIPPLE_X_2 = 0
WORLDMAP_RIPPLE_X_3 = 0
WORLDMAP_RIPPLE_X_4 = 0
WORLDMAP_RIPPLE_X_5 = 0
WORLDMAP_RIPPLE_X_6 = 0
WORLDMAP_RIPPLE_X_7 = 0