function selectBubblesSkin(folderName)
	USERPREF["speechbubbles"]=folderName
	BUBBLESPREF=loadPropertiesFile("images/speechbubbles/"..USERPREF["speechbubbles"].."/speechbubbles.properties")
	bubbleImages=loadBubbleImages(USERPREF["speechbubbles"])
	FONTS=loadFonts() --in case the user hot-installed a skin
end

function selectAvatar(folderName, playerNum)
	USERPREF["avatarPlayer"..playerNum]=folderName
	local prop=loadPropertiesFile("images/avatars/"..folderName.."/avatar.properties")
	players[playerNum]["avatar"]=loadAvatarImage(folderName)
	if playerNum==1 and USERPREF["usePersonalColor"]==true then
		--nothing, let him continue using his color
	else
		players[playerNum]["colorOut"]=prop["colorOut"]
		players[playerNum]["colorIn"]=prop["colorIn"]
	end
	
	if playerNum==1 and USERPREF["usePersonalName"]==true then --special case for player 1, who can use his name
		--nothin let him continue using his own name
	else
		players[playerNum]["name"]=prop["name"]
	end
end

function selectCards(folderName)
	USERPREF["cards"]=folderName
	CARDSPREF=loadPropertiesFile("images/cards/"..USERPREF["cards"].."/cards.properties")
	cardImages=loadCardImages(USERPREF["cards"])
end

function selectCarpet(folderName)
	--TODO: remove?
	FONTS=loadFonts() --in case the user hot-installed a skin
	USERPREF["carpet"]=folderName
	background=Image.load("images/carpets/"..USERPREF["carpet"].."/carpet.png")
	CARPETPREF=loadPropertiesFile("images/carpets/"..USERPREF["carpet"].."/carpet.properties")
end

function selectCursor(folderName)
	USERPREF["cursor"]=folderName
	CURSORPREF=loadPropertiesFile("images/cursors/"..USERPREF["cursor"].."/cursor.properties")
	ingameCursor["image"]=loadCursorImage(USERPREF["cursor"])
	if cursorIsAvailable() then
		replaceCursor()
	end
end

function selectPlayersNumIcons(folderName)
	USERPREF["playersNumIcons"]=folderName
	ICONSPREF["playersNum"]=loadPropertiesFile("images/icons/playersNum/"..USERPREF["playersNumIcons"].."/playersNumIcons.properties")
	iconImages["playersNum"]=loadPlayersNumIconImages(USERPREF["playersNumIcons"])
end

function selectRanksIcons(folderName)
	USERPREF["ranksIcons"]=folderName
	ICONSPREF["ranks"]=loadPropertiesFile("images/icons/ranks/"..USERPREF["ranksIcons"].."/ranksIcons.properties")
	iconImages["ranks"]=loadRankIconImages(USERPREF["ranksIcons"])
end

function selectStatesIcons(folderName)
	USERPREF["statesIcons"]=folderName
	ICONSPREF["states"]=loadPropertiesFile("images/icons/states/"..USERPREF["statesIcons"].."/statesIcons.properties")
	iconImages["states"]=loadStatesIconImages(USERPREF["statesIcons"])
end

function selectTheme(folderName)
	USERPREF["theme"]=folderName
	local themePref=loadPropertiesFile("images/themes/"..folderName.."/theme.properties")
	for i=1,4 do
		if themePref["avatarPlayer"..i]~=nil and themePref["avatarPlayer"..i]~="" then
			selectAvatar(themePref["avatarPlayer"..i], i)
		end
	end
	if themePref["speechbubbles"]~=nil and themePref["speechbubbles"]~="" then
		selectBubblesSkin(themePref["speechbubbles"])
	end
	if themePref["cards"]~=nil and themePref["cards"]~="" then
		selectCards(themePref["cards"])
	end
	if themePref["carpet"]~=nil and themePref["carpet"]~="" then
		selectCarpet(themePref["carpet"])
	end
	if themePref["cursor"]~=nil and themePref["cursor"]~="" then
		selectCursor(themePref["cursor"])
	end
	if themePref["playersNumIcons"]~=nil and themePref["playersNumIcons"]~="" then
		selectPlayersNumIcons(themePref["playersNumIcons"])
	end
	if themePref["ranksIcons"]~=nil and themePref["ranksIcons"]~="" then
		selectRanksIcons(themePref["ranksIcons"])
	end
	if themePref["statesIcons"]~=nil and themePref["statesIcons"]~="" then
		selectStatesIcons(themePref["statesIcons"])
	end
end












