function chooseAvatarMenu(originalBGImage, playerNum)
	local ovImg=Image.load("images/menus/skin_choose_avatar.png")
	
	local avatarFolderNames=nil
	local nbAvatars=nil
	local i=0
	local prop=nil
	local currentSelection=1
	
	if avatarPreviews==nil then
		-- loading
		screen:blit(0, 0, originalBGImage, true)
		alert("loading")
		avatarPreviews={}
		avatarFolderNames=getFolderList("images/avatars")
		nbAvatars=tableLength(avatarFolderNames)
		for i=1,nbAvatars do
			avatarPreviews[i]={}
			avatarPreviews[i]["num"]=i
			avatarPreviews[i]["previewImage"]=Image.load("images/avatars/"..avatarFolderNames[i].."/avatar.png")
			prop=loadPropertiesFile("images/avatars/"..avatarFolderNames[i].."/avatar.properties")
			avatarPreviews[i]["author"]=prop["author"]
			avatarPreviews[i]["name"]=replaceCRsWithSpaces(prop["name"])
			avatarPreviews[i]["description"]=prop["description"]
			avatarPreviews[i]["colorOut"]=prop["colorOut"]
			avatarPreviews[i]["colorIn"]=prop["colorIn"]
			avatarPreviews[i]["folderName"]=avatarFolderNames[i]
			avatarPreviews[i]["language"]=prop["language"]
			avatarPreviews[i]["copyright"]=prop["copyright"]
			
			if USERPREF["avatarPlayer"..playerNum]==avatarFolderNames[i] then --this is what the user is using
				currentSelection=i
			end
		end	
	else
		nbAvatars=tableLength(avatarPreviews)
		for i=1,nbAvatars do
			if USERPREF["avatarPlayer"..playerNum]==avatarPreviews[i]["folderName"] then --this is what the user is using
				currentSelection=i
			end
		end
	end
	
	drawAvatarsMenu(originalBGImage, currentSelection, nbAvatars, ovImg)
	
	while true do
		updateInputs(Controls.read())
		
		
		
		--specific inputs
		if inputFirstPress("left") or inputIsRepeating("left") then
			if currentSelection>1 then
				currentSelection=currentSelection-1
			else
				currentSelection=nbAvatars
			end
			drawAvatarsMenu(originalBGImage, currentSelection, nbAvatars, ovImg)
		elseif inputFirstPress("right") or inputIsRepeating("right") then
			if currentSelection<nbAvatars then
				currentSelection=currentSelection+1
			else
				currentSelection=1
			end
			drawAvatarsMenu(originalBGImage, currentSelection, nbAvatars, ovImg)
		elseif inputFirstPress("l") or inputIsRepeating("l") then
			if currentSelection>3 then --1+4
				currentSelection=currentSelection-3
			else
				currentSelection=1
			end
			drawAvatarsMenu(originalBGImage, currentSelection, nbAvatars, ovImg)
		elseif inputFirstPress("r") or inputIsRepeating("r") then
			if currentSelection<nbAvatars-2 then
				currentSelection=currentSelection+3
			else
				currentSelection=nbAvatars
			end
			drawAvatarsMenu(originalBGImage, currentSelection, nbAvatars, ovImg)
		end
		
		--selection
		if inputFirstPress("cross") or inputFirstPress("circle") then
			alert("loading...")
			selectAvatar(avatarPreviews[currentSelection]["folderName"], playerNum)
			return "changed"
		end
		
		--usual inputs
		if inputFirstPress("start") then
			return "quitMenu"
		end
		
		if inputFirstPress("square") then
			return "cancel"
		end
		
	end
end

function drawAvatarsMenu(originalBGImage, currentSelection, nbAvatars, ovImg)
	local xref=90
	local yref=75
	
	screen:blit(0, 0, originalBGImage, true)
	screen:blit(0, 0, ovImg, true)
	
	screen:blit(xref, yref+2, avatarPreviews[currentSelection]["previewImage"], true)
	printBicolor(screen, xref+272, yref+2, currentSelection.."/"..nbAvatars, black, white)
	printBicolor(screen, xref+81, yref+11, avatarPreviews[currentSelection]["name"], avatarPreviews[currentSelection]["colorOut"], avatarPreviews[currentSelection]["colorIn"])
	printBicolor(screen, xref+80, yref+30, "Author :", black, white)
	printBicolor(screen, xref+165, yref+35, avatarPreviews[currentSelection]["author"], black, white)
	printBicolor(screen, xref+80, yref+45, "Language :", black, white)
	printBicolor(screen, xref+165, yref+45, avatarPreviews[currentSelection]["language"], black, white)
	printWithCR(screen, xref, yref+68, avatarPreviews[currentSelection]["description"], white, 8, black)
	printU(screen, xref, yref+122, avatarPreviews[currentSelection]["copyright"], white, false, "default", 8, 8, 8, black)
	
	screen.flip()
	screen.waitVblankStart()
end







