--[[
In-game Animation sequences

02/03/09  md		Created

--]]

function GAMEOVER_showSequence(nDelay)
	local gameOver = scene:child("GAME_OVER")
	gameOver:bringToFront()

	gameOver:animate(
		{delay=nDelay},
		{visible=true, alpha=0.0},
		{alpha = 1.0, duration = 1000}
	)
	
	local secondaryText = scene:child("SECONDARY_LOSE")
	if secondaryText ~= nil then
		secondaryText:bringToFront()
		
		secondaryText:animate(
			{delay=nDelay},
			{visible=true, alpha=0.0},
			{alpha = 1.0, duration = 1000}
		)
	end
		
end

function LEVELCOMPLETE_playParticle(aX, aY)
	local levelComplete = scene:child("LEVEL_COMPLETE")
	if levelComplete ~= nil then
		local particle = scene:newChildSprite({class = "ParticleEffect", x = aX, y = aY, library = "PARTICLE_LEVEL_COMPLETE", section = "default", name = "LevelCompleteParticle", play = true})	
		particle:moveBehind(levelComplete)
		particle:play()
	end
end

function LEVELCOMPLETE_showSequence(nDelay)
	local levelComplete = scene:child("LEVEL_COMPLETE")
	
	
	local dropDuration = 600
	local waffleDuration = 250
	
	if levelComplete ~= nil then
		local levelCompleteInitialY = levelComplete:y()
		local levelCompleteStartX = levelComplete:x();
		local levelCompleteStartY = -levelComplete:height()
		local levelCompleteEndY = levelComplete:y()
		local levelCompleteMiddleY = levelCompleteEndY + 12
		local levelCompleteRaisedY = levelCompleteEndY - 8
		local levelCompleteMiddleY_2 = levelCompleteEndY + 4
		local levelCompleteRaisedY_2 = levelCompleteEndY - 2	
		
		levelComplete:setY(levelCompleteStartY)
		levelComplete:animate(
			{delay=nDelay},
			{visible=true, alpha=1.0, y=levelCompleteMiddleY, duration=dropDuration},
			{call=function() LEVELCOMPLETE_playParticle(levelCompleteStartX, levelCompleteInitialY) end},
			{y=levelCompleteRaisedY, duration=waffleDuration},
			{y=levelCompleteMiddleY_2, duration=waffleDuration},
			{y=levelCompleteRaisedY_2, duration=waffleDuration},
			{y=levelCompleteEndY, duration=waffleDuration}
		)
	end
	
	local levelCompleteText = scene:child("LEVEL_COMPLETE_TEXT")
	if levelCompleteText ~= nil then

		local levelCompleteTextStartY = -levelCompleteText:height()
		local levelCompleteTextEndY = levelCompleteText:y()
		local levelCompleteTextMiddleY = levelCompleteTextEndY + 12
		local levelCompleteTextRaisedY = levelCompleteTextEndY - 8
		local levelCompleteTextMiddleY_2 = levelCompleteTextEndY + 4
		local levelCompleteTextRaisedY_2 = levelCompleteTextEndY - 2	
		
		levelCompleteText:setY(levelCompleteTextStartY)
		levelCompleteText:animate(
			{delay=nDelay},
			{visible=true, alpha=1.0, y=levelCompleteMiddleY, duration=dropDuration},
			{y=levelCompleteText, duration=waffleDuration},
			{y=levelCompleteTextMiddleY_2, duration=waffleDuration},
			{y=levelCompleteTextRaisedY_2, duration=waffleDuration},
			{y=levelCompleteTextEndY, duration=waffleDuration}
		)
	end
end
		
function LEVELCOMPLETE_hideSequence()
	local levelComplete = scene:child("LEVEL_COMPLETE")
	if levelComplete ~= nil then
		levelComplete:animate(
			{visible=true, alpha=0.0, duration=1000},
			{command = "OnLevelCompleteSequenceDone", target = scene}
		)
	end
	
	local levelCompleteText = scene:child("LEVEL_COMPLETE_TEXT")
	if levelCompleteText ~= nil then
		levelCompleteText:animate(
			{visible=true, alpha=0.0, duration=1000}
		)
	end
end

function animateScoreBonusSprite(aBonusSprite)
	aBonusSprite:bringToFront()
	aBonusSprite:animate(
		{y = aBonusSprite:y() - 150, alpha = 0.0, duration=1500},
		{visible = false}
	)
end


function animateAvatarHop(aAvatarSprite)

	
end
