function chooseThemeMenu(originalBGImage)
	local ovImg=Image.load("images/menus/skin_choose_theme.png")
	local nbThemes=nil
	local i=0
	local prop=nil
	local currentSelection=1
	local names=nil
	
	if themePreviews==nil then
		-- loading
		screen:blit(0, 0, originalBGImage, true)
		alert("loading")
		--screen.waitVblankStart()
		--screen.flip()
		
		themePreviews={}
		names=getFolderList("images/themes")
		nbThemes=tableLength(names)
		for i=1,nbThemes do
			themePreviews[i]={}
			themePreviews[i]["num"]=i
			themePreviews[i]["previewImage"]=Image.load("images/themes/"..names[i].."/preview.png")
			prop=loadPropertiesFile("images/themes/"..names[i].."/theme.properties")
			themePreviews[i]["author"]=prop["author"]
			themePreviews[i]["name"]=prop["name"]
			themePreviews[i]["description"]=prop["description"]
			themePreviews[i]["language"]=prop["language"]
			themePreviews[i]["folderName"]=names[i]
			themePreviews[i]["copyright"]=prop["copyright"]
			if USERPREF["theme"]==names[i] then --this is what the user is using
				currentSelection=i
			end
		end
	else
		nbThemes=tableLength(themePreviews)
		for i=1,nbThemes do
			if USERPREF["theme"]==themePreviews[i]["folderName"] then --this is what the user is using
				currentSelection=i
			end
		end
	end
	
	drawThemeMenu(originalBGImage, currentSelection, nbThemes, ovImg)
	
	
	--main loop to get the input
	while true do
		updateInputs(Controls.read())
		

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

function drawThemeMenu(originalBGImage, currentSelection, nbThemes, ovImg)
	--fdebug(currentSelection.." "..nbThemes)
	local xref=90
	local yref=45
	screen:blit(0, 0, originalBGImage, true)
	screen:blit(0, 0, ovImg, true)
	
	screen:blit(xref, yref+15, themePreviews[currentSelection]["previewImage"], true)
	--fdebug(currentSelection.."/"..nbThemes)
	printBicolor(screen, xref+270, yref, currentSelection.."/"..nbThemes, black, white)
	--fdebug(themePreviews[currentSelection]["name"])
	printBicolor(screen, xref, yref, themePreviews[currentSelection]["name"], black, white)
	
	printBicolor(screen, xref+170, yref+30, "Author:", black, white)
	--fdebug(themePreviews[currentSelection]["author"])
	printBicolor(screen, xref+180, yref+40, themePreviews[currentSelection]["author"], black, white)
	
	printBicolor(screen, xref+170, yref+60, "Language:", black, white)
	--fdebug(themePreviews[currentSelection]["language"])
	printBicolor(screen, xref+180, yref+70, themePreviews[currentSelection]["language"], black, white)
	
	---fdebug(themePreviews[currentSelection]["copyright"])
	printU(screen, xref, yref+177, themePreviews[currentSelection]["copyright"], white, false, "default", 8, 8, 8, black)
	
	--fdebug(themePreviews[currentSelection]["description"])
	printWithCR(screen, xref, yref+109, themePreviews[currentSelection]["description"], white, 8, black)
	
	screen.flip()
	screen.waitVblankStart()
end







