--[[

Casino Games Animation sequences

--]]

function HILO_dealCard(aIndex, aCardPile)

	local cardBase = scene:child("CARD_BASE_"..aIndex)
	local cardFace = scene:child("CARD_FACE_"..aIndex)
	local cardBack = scene:child("CARD_BACK_"..aIndex)
	local pile = scene:child("PLAYER_PILE_"..aCardPile)
	local destX = pile:x()
	local destY = pile:y()
	
	local deck = scene:child("DECK")
	local deckX = deck:x()
	local deckY = deck:y()
	
	local dealDuration = 500
	
	if cardFace ~= nil and cardBase ~= nil and cardBack ~= nil then
		cardBack:bringToFront()
		cardBase:bringToFront()
		cardFace:bringToFront()
		cardBase:setVisible(false)
		cardFace:setVisible(false)
		cardBack:setVisible(true)
		cardBack:animate(
			{
				{x=deckX, y=deckY},
				{sprite=cardBase, x=deckX, y=deckY},
				{sprite=cardFace, x=deckX, y=deckY}
			},
			{
				{sprite=cardBase, visible=false, x=destX, y=destY, scaleX=0},
				{sprite=cardFace, visible=false, x=destX, y=destY, scaleX=0}
			},
			{delay=50},
			{play = "SOUND_HILO_DEAL:scenehilo"},
			{x = destX, y = destY, duration = dealDuration},
			{
				{play = "SOUND_HILO_FLIP:scenehilo"},
				{scaleX=0, duration=200},
				{sprite=cardBase, visible=true, scaleX = 1, duration=200},
				{sprite=cardFace, visible=true, scaleX = 1, duration=200}
			}
		)
	end
end

function HILO_foldCards(aIndex)

	if aIndex >= 0 then
	
		local deck = scene:child("DECK")
		if deck ~= nil then
			local deckX = deck:x()
			local deckY = deck:y()
		
			local cardBase = scene:child("CARD_BASE_"..aIndex)
			local cardFace = scene:child("CARD_FACE_"..aIndex)
			local cardBack = scene:child("CARD_BACK_"..aIndex)

			local flyDuration = 400
			
			if cardFace ~= nil and cardBase ~= nil and cardBack ~= nil then
				cardBase:bringToFront()
				cardFace:bringToFront()
				cardBack:bringToFront()
				cardBase:setVisible(false)
				cardFace:setVisible(false)
				cardFace:animate(
					{
						{play = "SOUND_HILO_FLIP:scenehilo"},	
						{sprite=cardBase, scaleX=0, duration=200},
						{scaleX=0, duration=200},
						{sprite=cardBase, visible=false},
						{visible=false},
						{sprite=cardBack, visible=true, scaleX = 1, duration=200}
					},
					{delay=200},
					{sprite=cardBack, x=deckX, y=deckY, duration = flyDuration, style = "easeInOut"},
					{
						{sprite=cardBase, x=deckX, y=deckY},
						{x=deckX, y=deckY},
						{sprite=cardBack, x=deckX, y=deckY}
					}
				)
			end
		end
	end
end
