function chooseStatesIconsMenu(originalBGImage)
	local ovImg=Image.load("images/menus/skin_choose_statesIcons.png")
	
	local nbIcons=nil
	local i=0
	local prop=nil
	local currentSelection=1
	local names=nil
	if statesPreviews==nil then
		-- loading
		screen:blit(0, 0, originalBGImage, true)
		alert("loading")
		
		statesPreviews={}
		names=getFolderList("images/icons/states")
		nbIcons=tableLength(names)
		for i=1,nbIcons do
			statesPreviews[i]={}
			statesPreviews[i]["num"]=i
			prop=loadPropertiesFile("images/icons/states/"..names[i].."/statesIcons.properties")
			statesPreviews[i]["author"]=prop["author"]
			statesPreviews[i]["name"]=prop["name"]
			statesPreviews[i]["description"]=prop["description"]
			statesPreviews[i]["folderName"]=names[i]
			statesPreviews[i]["language"]=prop["language"]
			statesPreviews[i]["copyright"]=prop["copyright"]
			statesPreviews[i]["in_game"]=Image.load("images/icons/states/"..names[i].."/in_game.png")
			statesPreviews[i]["leader"]=Image.load("images/icons/states/"..names[i].."/leader.png")
			statesPreviews[i]["passed"]=Image.load("images/icons/states/"..names[i].."/passed.png")
			statesPreviews[i]["finished"]=Image.load("images/icons/states/"..names[i].."/finished.png")
			statesPreviews[i]["not_playing"]=Image.load("images/icons/states/"..names[i].."/not_playing.png")
			
			
			if USERPREF["statesIcons"]==names[i] then --this is what the user is using
				currentSelection=i
			end
		end
	else
		nbIcons=tableLength(statesPreviews)
		for i=1,nbIcons do
			if USERPREF["statesIcons"]==statesPreviews[i]["folderName"] then --this is what the user is using
				currentSelection=i
			end
		end
	end
	
	while true do
		updateInputs(Controls.read())
		

		--specific inputs
		if inputFirstPress("left") or inputIsRepeating("left") then
			if currentSelection>1 then
				currentSelection=currentSelection-1
			else
				currentSelection=nbIcons
			end
			drawStatesIconsMenu(originalBGImage, currentSelection, nbIcons, ovImg)
		elseif inputFirstPress("right") or inputIsRepeating("right") then
			if currentSelection<nbIcons then
				currentSelection=currentSelection+1
			else
				currentSelection=1
			end
			drawStatesIconsMenu(originalBGImage, currentSelection, nbIcons, ovImg)
		elseif inputFirstPress("l") or inputIsRepeating("l") then
			if currentSelection>3 then --1+4
				currentSelection=currentSelection-3
			else
				currentSelection=1
			end
			drawStatesIconsMenu(originalBGImage, currentSelection, nbIcons, ovImg)
		elseif inputFirstPress("r") or inputIsRepeating("r") then
			if currentSelection<nbIcons-2 then
				currentSelection=currentSelection+3
			else
				currentSelection=nbIcons
			end
			drawStatesIconsMenu(originalBGImage, currentSelection, nbIcons, ovImg)
		end
		
		--selection
		if inputFirstPress("cross") or inputFirstPress("circle") then
			alert("loading...")
			selectStatesIcons(statesPreviews[currentSelection]["folderName"])
			return "changed"
		end
		
		
		
		
		
		--usual inputs
		if inputFirstPress("start") then
			return "quitMenu"
		end
		
		if inputFirstPress("square") then
			return "cancel"
		end
		
		drawStatesIconsMenu(originalBGImage, currentSelection, nbIcons, ovImg)
	end
end

function drawStatesIconsMenu(originalBGImage, currentSelection, nbIcons, ovImg)
	local xref=90
	local yref=70

	screen:blit(0, 0, originalBGImage, true)
	screen:blit(0, 0, ovImg, true)
	
	printBicolor(screen, xref+270, yref+10, currentSelection.."/"..nbIcons, black, white)
	printBicolor(screen, xref, yref+10, statesPreviews[currentSelection]["name"], black, white)
	
	printBicolor(screen, xref, yref+55, "Author:", black, white)
	printBicolor(screen, xref+85, yref+55, statesPreviews[currentSelection]["author"], black, white)
	printBicolor(screen, xref, yref+65, "Language:", black, white)
	printBicolor(screen, xref+85, yref+65, statesPreviews[currentSelection]["language"], black, white)
	
	printWithCR(screen, xref, yref+80, statesPreviews[currentSelection]["description"], white, 8, black)
	printU(screen, xref, yref+128, statesPreviews[currentSelection]["copyright"], white, false, "default", 8, 8, 8, black)
	
	screen:blit(xref, yref+25, statesPreviews[currentSelection]["in_game"], true)
	screen:blit(xref+25, yref+25, statesPreviews[currentSelection]["leader"], true)
	screen:blit(xref+50, yref+25, statesPreviews[currentSelection]["passed"], true)
	screen:blit(xref+75, yref+25, statesPreviews[currentSelection]["finished"], true)
	screen:blit(xref+100, yref+25, statesPreviews[currentSelection]["not_playing"], true)
	
	screen.flip()
	screen.waitVblankStart()
end







