--x = screen.print(x,10,"texto",0.77,color.new(255,0,0),color.new(0,0,0),"scroll_through",300);
function actdir(scrollbar,nowdir,tabledir,pos1,pos2,type)
if not type then type = files end
local tabledir = type.list(nowdir)
for i=1, #tabledir do
tabledir[i].name2 = files.nopath(tabledir[i].name)
	if screen.textwidth(tabledir[i].name2)>300 then
		for k = #tabledir[i].name2,1,-1 do 
			if screen.textwidth(string.sub(tabledir[i].name2,1,k,size))<300 then
				tabledir[i].name2 = string.sub(tabledir[i].name2,1,k)
				tabledir[i].name2 = tabledir[i].name2.."..."..files.ext(tabledir[i].name)
				break
			end
		end
	end
end
if nowdir != "ms0:/" then table.insert(tabledir,1,{name='..',name2 = '..', tabledir=false})
elseif nowdir == "ms0:/" then table.insert(tabledir,#tabledir+1,{name=createfoldertext,name2 = createfoldertext, tabledir=false}) end
if not pos1 then pos1=1 end
if not pos2 then pos2=4 end
scrollbar.pos=pos1
scrollbar.posfiles=pos2
return tabledir
end

function showfiles(dir,scrollbar)
	if #dir > 1 then
		for i = 1, #dir do	
			screen.print(10,5+spacing*(i-1)+(spacing*scrollbar.posfiles),dir[i].name2,size,colortext,alpha)
		end	
	else screen.print(10,5+(spacing*scrollbar.posfiles),'..',size,colortext,alpha)
		screen.print(10,5+10+(spacing*scrollbar.posfiles),nofiles,size,colortext,alpha)	
	end
--if tiempo:time() >= 0 and tiempo:time() <= 250 then
	if #dir > 1 then draw.rect(5,4+spacing*(scrollbar.pos-1)+(spacing*scrollbar.posfiles),10+screen.textwidth(dir[scrollbar.pos].name2,size),size*2*10,colorselec)
	elseif #dir < 2 then draw.rect(5,4+(spacing*scrollbar.posfiles),10+screen.textwidth('..',size),size*2*10,colorselec)
	end
--elseif tiempo:time() >= 500 then tiempo:reset()
--end	
end

function drawscrollbar(dir,scrollbar)
scrollbar.h1 = 232/#dir
if controls.press("up") then 
	scrollbar.pos = scrollbar.pos - 1 
	if #dir>16 then
		if scrollbar.pos+scrollbar.posfiles <= 3 and scrollbar.pos+scrollbar.posfiles >1 then
			scrollbar.posfiles = scrollbar.posfiles + 1
		end
	end
end
if controls.press("down") then 
	scrollbar.pos = scrollbar.pos + 1
	if #dir>16 then
		if scrollbar.pos+scrollbar.posfiles >= 17 and scrollbar.pos+scrollbar.posfiles <#dir then
			scrollbar.posfiles = scrollbar.posfiles - 1
		end
	end

end
if scrollbar.pos <1 then
	if #dir>16 then 
		scrollbar.pos = #dir
		 scrollbar.posfiles=(18-#dir)	
	elseif #dir<=17 then
		scrollbar.pos = #dir
		scrollbar.posfiles=4

	end
end
if scrollbar.pos> #dir then scrollbar.pos=1 scrollbar.posfiles=4 end 
draw.fillrect(scrollbar.x,scrollbar.y,scrollbar.w,scrollbar.h,colormainbar) --main bar 
draw.fillrect(scrollbar.x,math.ceil(scrollbar.y+(scrollbar.pos-1)*scrollbar.h1),scrollbar.w,scrollbar.h1,colorscrollbar) --moving bar
end

function movemainscrollbar()
if controls.press("circle") and currentdir != "ms0:/" then
	currentdir = files.nofile(currentdir)
	filescdir= actdir(mainscrollbar,currentdir,filescdir)	
end
if controls.press("cross") then
	if filescdir[mainscrollbar.pos].directory == true then
		currentdir = filescdir[mainscrollbar.pos].name
		filescdir = actdir(mainscrollbar,currentdir,filescdir)
	elseif filescdir[mainscrollbar.pos].name == '..' then
		currentdir =files.nofile(currentdir)
		filescdir= actdir(mainscrollbar,currentdir,filescdir)		
	elseif files.ext(filescdir[mainscrollbar.pos].name) == "zip" then
		zipfunctions(filescdir[mainscrollbar.pos].name)
	elseif files.ext(filescdir[mainscrollbar.pos].name) == "png" or files.ext(filescdir[mainscrollbar.pos].name) == "jpg" or 
		files.ext(filescdir[mainscrollbar.pos].name) == "jpeg" or files.ext(filescdir[mainscrollbar.pos].name) =="gif" then
		showimages(filescdir[mainscrollbar.pos].name,mainscrollbar)
	elseif files.ext(filescdir[mainscrollbar.pos].name) == "iso" or files.ext(filescdir[mainscrollbar.pos].name) =="cso" or 
		files.ext(filescdir[mainscrollbar.pos].name) == "pbp" or files.ext(filescdir[mainscrollbar.pos].name) == "PBP" then
		runespecialfiles(filescdir[mainscrollbar.pos].name)
	elseif files.ext(filescdir[mainscrollbar.pos].name) == "mp3" or files.ext(filescdir[mainscrollbar.pos].name) == "at3" or 
		files.ext(filescdir[mainscrollbar.pos].name) == "bgm" or files.ext(filescdir[mainscrollbar.pos].name) == "wav" then
		mp3player(filescdir[mainscrollbar.pos].name,mainscrollbar)
	elseif filescdir[mainscrollbar.pos].name == createfoldertext then
		createfolder(currentdir)
		filescdir= actdir(mainscrollbar,currentdir,filescdir)
	end
end

if controls.press("triangle") and filescdir[mainscrollbar.pos].name != createfoldertext then
--tiempo:reset()
filesmenu(mainscrollbar,filescdir,currentdir,filescdir[mainscrollbar.pos].directory,files.ext(filescdir[mainscrollbar.pos].name))
filescdir = actdir(mainscrollbar,currentdir,filescdir,mainscrollbar.pos,mainscrollbar.posfiles)
end
cross.currentdir = screen.print(cross.currentdir,2,currentdir,size,white,alpha,"scroll_left",300)
end

function getdir(messagest,text,tableinsert)
getdirdir="ms0:/"
function actgetdir()
getcdir = files.list(getdirdir)
for i=1, #getcdir do
getcdir[i].name2 = files.nopath(getcdir[i].name)
	if screen.textwidth(getcdir[i].name2)>300 then
		for k = #getcdir[i].name2,1,-1 do 
			if screen.textwidth(string.sub(getcdir[i].name2,1,k,size))<300 then
				getcdir[i].name2 = string.sub(getcdir[i].name2,1,k)
				getcdir[i].name2 = getcdir[i].name2.."..."..files.ext(getcdir[i].name)
				break
			end
		end
	end
end
table.insert(getcdir,#getcdir+1,{name=getdirdir,name2 = tableinsert, directory=false})
if getdirdir != "ms0:/" then table.insert(getcdir,1,{name='..',name2 = '..', getcdir=false});end	
getdirscrollbar.pos=1
getdirscrollbar.posfiles=4
return getcdir
end
getcdir = actgetdir()
while true do
controls.read()
if song != null then 
	equalizer.blit() 
	if controls.press("select") then
		mp3player(playing)
	end
end
batteryandtime()
if controls.press("cross") then
	if getcdir[getdirscrollbar.pos].directory then
		getdirdir = getcdir[getdirscrollbar.pos].name
		getcdir = actgetdir()
	elseif getcdir[getdirscrollbar.pos].name == '..' then
		getdirdir = files.nofile(getdirdir)
		getcdir = actgetdir()
	elseif getcdir[getdirscrollbar.pos].name2 == tableinsert then
		os.message(messagest,1)
		break
	elseif files.ext(filescdir[mainscrollbar.pos].name) == "mp3" or files.ext(filescdir[mainscrollbar.pos].name) == "at3" or 
		files.ext(filescdir[mainscrollbar.pos].name) == "bgm" or files.ext(filescdir[mainscrollbar.pos].name) == "wav" then
		mp3player(filescdir[mainscrollbar.pos].name,mainscrollbar)
	end
end
if controls.press("circle") then
	if os.message(canceldir,1)==1 then
	
		break
	end
end

drawscrollbar(getcdir,getdirscrollbar)
showfiles(getcdir,getdirscrollbar,red,green)
draw.fillrect(0,0,480,16,black)
draw.fillrect(0,272-16,480,16,black)
screen.print(-10,10,"--------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
screen.print(-10,272-20,"-------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
screen.print(10,272-13,text,size,white,alpha)
cross.getdirdir = screen.print(cross.getdirdir,2,getdirdir,size,white,alpha,"scroll_left",300)
batteryandtime()
screen.flip()
if controls.l() and controls.r() then xerpi() end---------------
end
getdirscrollbar={x=445,y=20,w=9,h=232,pos=nil,posfiles=0,color1=alphawhite,color2=blue}
return getdirdir
end

function zipfunctions(zipdir)
freedir=zipdir
freecdir=actdir(freescrollbar,freedir,freecdir,false,false,zip)
table.insert(freecdir,#freecdir+1,{name=extractall,name2 = extractall, directory=false})
while true do
if song != null then 
	equalizer.blit()
	if controls.press("select") then
		mp3player(playing)
	end	
end
controls.read()
showfiles(freecdir,freescrollbar)
drawscrollbar(freecdir,freescrollbar)
if controls.press("cross") then
	if freecdir[freescrollbar.pos].name2 == extractall then
		os.message(selectdir)
		dirto.extract = getdir(getdir1..vzip,selectdir,extracthere)
		if os.message(suretoextract1..zipdir..to..dirto.extract.."?",1) == 1 then 
			zip.extract(zipdir,dirto.extract,1)
			os.message(correctlyextracted)
			break
		end	
	
	elseif freecdir[freescrollbar.pos].name2 != exctractall and freecdir[freescrollbar.pos].name2 != '..' then
		os.message(selectdir,false)
		dirto.extract = getdir(getdir1..vzip,selectdir,extracthere)
		if os.message(suretoextract1..freecdir[freescrollbar.pos].name..to..dirto.extract.."?",1) == 1 then
			zip.extract(zipdir,freecdir[freescrollbar.pos].name,dirto.extract.."/"..freecdir[freescrollbar.pos].name,1)
			os.message(correctlyextracted)
			break
		end
	elseif freecdir[freescrollbar.pos].name2 == '..' then
		break
	elseif files.ext(filescdir[mainscrollbar.pos].name) == "mp3" or files.ext(filescdir[mainscrollbar.pos].name) == "at3" or 
		files.ext(filescdir[mainscrollbar.pos].name) == "bgm" or files.ext(filescdir[mainscrollbar.pos].name) == "wav" then
		mp3player(filescdir[mainscrollbar.pos].name,mainscrollbar)
	elseif freecdir[freescrollbar.pos].name == createfoldertext then
		createfolder(freecdir)
		actdir(freescrollbar,freedir,freecdir,false,false,zip)
	end
end
draw.fillrect(0,0,480,16,black)
draw.fillrect(0,272-16,480,16,black)
screen.print(-10,10,"--------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
screen.print(-10,272-20,"-------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
cross.freedir = screen.print(cross.freedir,2,freedir,size,white,alpha,"scroll_left",300)
if controls.l() and controls.r() then xerpi() end---------------
batteryandtime()
screen.flip()
end
freescrollbar={x=445,y=20,w=9,h=232,pos=nil,posfiles=0,color1=alphawhite,color2=blue}
end

function runespecialfiles(dir)
if files.ext(dir) == "iso" or files.ext(dir) == "cso" and os.message(runiso,1)==1 then
	os.runiso(dir)
elseif files.ext(dir) == "pbp" then
	if files.exists(files.nofile(dir).."/keys.bin") then
		if os.message(runpsx,1)==1 then os.startPSX(dir) end
	elseif not files.exists(files.nofile(dir).."/keys.bin") then
		if os.message(runeboot,1)==1 then os.runeboot(dir) end
	end
end
end

function movethings(dir,directory)
if dir != "ms0:/" and dir != "ms0:/PSP" and dir != "ms0:/GAME" then
	os.message(selectdir)
	dirto.move = getdir(getdir1..vmove,selectdir,movehere)
	if os.message(suretomove1..dir..to..dirto.move.."?",1) == 1 then
		if directory then files.mkdir(dirto.move.."/"..files.nopath(dir)) end
		files.copy(dir,dirto.move.."/"..files.nopath(dir),true,true)
		files.remove(dir,true) 
		dirto.move=nil
	end
elseif dir == "ms0:/" or dir == "ms0:/PSP" or dir == "ms0:/GAME" then
	os.message(cantmovepsp)
end
end

function copythings(dir,directory)
os.message(selectdir)
dirto.copy = getdir(getdir1..vcopy,selectdir,copyhere)
if os.message(suretocopy1..dir..to..dirto.copy.."?",1) == 1 then
	if directory then files.mkdir(dirto.copy.."/"..files.nopath(dir)); files.copy(dir,dirto.copy.."/"..files.nopath(dir),true,true)
	else files.copy(dir,dirto.copy.."/"..files.nopath(dir),true,true)
	end
	dirto.copy=nil
end
end

function filesmenu(scrollbar,yourdir,actualdir,isdir,ext)
local menupos=1
local minimenu={move,delete,copy,renameto,send}
if ext == "zip" then table.insert(minimenu,#minimenu,extractto..to.."...")
elseif ext == "mp3" or ext == "at3" or ext == "bgm" or ext == "wav" then table.insert(minimenu,#minimenu,play)
end
local x=25+screen.textwidth(files.nopath(yourdir[scrollbar.pos].name))
local y=5+spacing*(scrollbar.pos-1)+(spacing*scrollbar.posfiles)
if y +17*#minimenu >272-13 then y = spacing*(scrollbar.pos-1)+(spacing*scrollbar.posfiles)-(17*#minimenu)+5 end
if yourdir[scrollbar.pos].name == '..' then minimenu={} minimenu ={createfoldertext} end
while true do
if song != null then 
	equalizer.blit() 
end
controls.read()
---
showfiles(filescdir,mainscrollbar)
draw.fillrect(0,0,480,16,black)
draw.fillrect(0,272-16,480,16,black)
draw.fillrect(scrollbar.x,scrollbar.y,scrollbar.w,scrollbar.h,colormainbar) --main bar 
draw.fillrect(scrollbar.x,math.ceil(scrollbar.y+(scrollbar.pos-1)*scrollbar.h1),scrollbar.w,scrollbar.h1,colorscrollbar) --moving bar
screen.print(-10,10,"--------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
screen.print(-10,272-20,"-------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
screen.print(10,2,actualdir,size,white,alpha)
----
if yourdir[scrollbar.pos].name == '..' then
draw.fillrect(x,y,20+screen.textwidth(createfoldertext),17*#minimenu,yellow)
else draw.fillrect(x,y,20+math.max(screen.textwidth(minimenu[2]),screen.textwidth(minimenu[4],size)),17*#minimenu,yellow) end
for i=1,#minimenu do
screen.print(x+10,y+5+15*(i-1),minimenu[i],size,colortext,alpha)
end
if controls.press("cross") then
	if minimenu[menupos] == move then
			movethings(yourdir[scrollbar.pos].name,yourdir[scrollbar.pos].directory)
			actdir(scrollbar,actualdir,yourdir)
			break
	elseif minimenu[menupos] == delete then
			deletethings(yourdir[scrollbar.pos].name,yourdir[scrollbar.pos].directory)
			actdir(scrollbar,actualdir,yourdir)
			break
	elseif minimenu[menupos] == copy then
			copythings(yourdir[scrollbar.pos].name,yourdir[scrollbar.pos].directory)
			actdir(scrollbar,actualdir,yourdir)
			break
	elseif minimenu[menupos] == send then
	
	elseif minimenu[menupos] == renameto then
			renamethings(yourdir[scrollbar.pos].name)
			actdir(scrollbar,actualdir,yourdir)
		break
	elseif minimenu[menupos] == extractto..to.."..." then
		os.message(selectdir,false)
		dirto.extract = getdir(getdir1..vzip,selectdir,extracthere)
		if os.message(suretoextract1..yourdir[scrollbar.pos].name..to..dirto.extract.."?",1) == 1 then 
			zip.extract(yourdir[scrollbar.pos].name,dirto.extract,1)
			os.message(correctlyextracted)
			break
		end
	elseif minimenu[menupos] == play then
		mp3player(yourdir[scrollbar.pos].name,scrollbar)
	elseif minimenu[menupos] ==createfoldertext  then
		createfolder(actualdir)
		actdir(scrollbar,actualdir,yourdir)
		break
	end
end

if controls.press("up") then
	if menupos ==1 then menupos = #minimenu
	else menupos =menupos-1 end
elseif controls.press("down") then
	if menupos ==#minimenu then menupos = 1
	else menupos = menupos+1 end
end
draw.rect(x+5,y+4+15*(menupos-1),10+screen.textwidth(minimenu[menupos],size),size*2*10,colorselec)
if controls.press("circle") then break end
batteryandtime()
screen.flip()
end
local menupos=nil
local minimenu=nil
local x=nil
local y=nil
end

function createfolder(dir)
os.message(newfolder)
files.mkdir(dir.."/"..os.osk(newfolder,"",30,5,0)) return true
end

function showimages(imagedir,scrollbar)
currentimage = image.load(imagedir)
imageposition= scrollbar.pos-1
imagesdirectory=files.list(files.nofile(imagedir))
imgx=240-currentimage:width()/2
imgy=136-currentimage:height()/2
imgw=currentimage:width()
imgh=currentimage:height()
width=currentimage:width()
height=currentimage:height()
while true do
if song != null then 
	equalizer.blit() 
	if controls.press("select") then
		mp3player(playing)
	end
end
controls.read()
draw.fillrect(0,0,480,272,color.new(0,0,0,124)) 
if controls.press("cross") or controls.press("circle") then
break
end
if controls.press("l") then
		for i= imageposition-1,1,-1 do	
			if files.ext(imagesdirectory[i].name) == "png" or files.ext(imagesdirectory[i].name) == "jpg" or 
			files.ext(imagesdirectory[i].name) == "jpeg" or files.ext(imagesdirectory[i].name) =="gif" then
			currentimage:free()
			currentimage=image.load(imagesdirectory[i].name);
			imageposition=i
			imgx=240-currentimage:width()/2
			imgy=136-currentimage:height()/2
			imgw=currentimage:width()
			imgh=currentimage:height()
			break
		end
	end
end
if controls.press("r") then
	for i= imageposition+1,#imagesdirectory do	
			if files.ext(imagesdirectory[i].name) == "png" or files.ext(imagesdirectory[i].name) == "jpg" or 
			files.ext(imagesdirectory[i].name) == "jpeg" or files.ext(imagesdirectory[i].name) =="gif" then
			currentimage:free()
			currentimage=image.load(imagesdirectory[i].name); 
			imageposition=i
			imgx=240-currentimage:width()/2
			imgy=136-currentimage:height()/2
			imgw=currentimage:width()
			imgh=currentimage:height()
			break
		end
	end
end

if controls.up() then imgh=imgh-2 currentimage:resize(imgw,imgh);  end
if controls.down() then imgh=imgh+2 currentimage:resize(imgw,imgh);  end
if controls.right() then imgw=imgw+2 currentimage:resize(imgw,imgh);  end
if controls.left() then imgw=imgw-2 currentimage:resize(imgw,imgh);  end
if math.abs(controls.analogx())>20 then imgx = imgx + controls.analogx()/40 end
if math.abs(controls.analogy())>20 then imgy = imgy + controls.analogy()/40 end
if controls.press("start") then  currentimage:resize(width,height) imgx=240-currentimage:width()/2 imgy=136-currentimage:height()/2 end

currentimage:blit(imgx,imgy)
screen.flip()
end
currentimage:free()
end

function renamethings(dir)
local newname=os.osk(renamedir,files.nopath(dir),30,5,0)
if os.message(suretorename1..dir..to.." "..newname.." ?",0) == 1 then
	--os.message("1:"..dir.."    2:"..files.nofile(dir)..newname)
	files.rename(dir,files.nofile(dir)..newname)
	newname=nil
end
end

function deletethings(dir,isdir)
if dir != "ms0:/" and dir != "ms0:/PSP" and dir != "ms0:/GAME" then
	if isdir == true then 
		if os.message(suretodeletedir1..dir..suretodeletedir2,1) == 1 then
			files.remove(dir,1)
		end
	elseif isdir == false then 
		if os.message(suretodeletefile..dir.." ?",1) == 1 then
			files.remove(dir,1)
		end
	end
elseif dir == "ms0:/" or dir == "ms0:/PSP" or dir == "ms0:/GAME" then
	os.message(cantdeletepsp)
end
end

function optionsmenu()
position = 1
x,y = 20,20
lengtrue=nil
while true do
if song != null then 
	equalizer.blit() 
end
controls.read()
if controls.press("circle") then break end
draw.rect(x-5,y-2+(15*position),10+screen.textwidth(options[position].text,size),size*2*10,colorselec)
for i = 1, #options do
	screen.print(x,y+i*15,options[i].text,size,colortext,alpha)
end
if controls.press("up") then position = position -1 end
if controls.press("down") then position = position +1 end
if position >= #options+1 then position = 1 end
if position <=0 then position = #options end
if controls.press("cross") then
if position==1 then
	position=1
	while true do
	controls.read()
	if controls.press("up") then position = position -1 end
	if controls.press("down") then position = position +1 end
	if position > 4 then position = 1 end
	if position <=0 then position = 4 end
	draw.rect(x-5,y-2+(15*position),10+screen.textwidth(options[1][position],size),size*2*10,colorselec)

		screen.print(x,y+1*15,options[1][1],size,colortext,alpha)
		screen.print(x,y+2*15,options[1][2],size,colorselec,alpha)
		screen.print(x,y+3*15,options[1][3],size,colormainbar,alpha)
		screen.print(x,y+4*15,options[1][4],size,colorscrollbar,alpha)
		
	if controls.press("right") then 
		if position ==1 then
			textpos=textpos+1
			if textpos>=#colorstab+1 then textpos=1 end
		elseif position ==2 then
			selecpos=selecpos+1
			if selecpos>=#colorstab+1 then selecpos=1 end
		elseif position ==3 then
			mainbarpos=mainbarpos+1
			if mainbarpos>#colorstab then mainbarpos=1 end
		elseif position ==4 then
			scrollbarpos=scrollbarpos+1
			if scrollbarpos>=#colorstab+1 then scrollbarpos=1 end
		end
		colortext=colorstab[textpos]
		colorselec=colorstab[selecpos]
		colormainbar=colorstab[mainbarpos]
		colorscrollbar=colorstab[scrollbarpos]
	end		
	if controls.press("left") then 
		if position ==1 then
			textpos=textpos-1
			if textpos<1 then textpos=#colorstab end
		elseif position ==2 then
			selecpos=selecpos-1
			if selecpos<1 then selecpos=#colorstab end
		elseif position ==3 then
			mainbarpos=mainbarpos-1
			if mainbarpos<1 then mainbarpos=#colorstab end
		elseif position ==4 then
			scrollbarpos=scrollbarpos-1
			if scrollbarpos<1 then scrollbarpos=#colorstab end
		end
		colortext=colorstab[textpos]
		colorselec=colorstab[selecpos]
		colormainbar=colorstab[mainbarpos]
		colorscrollbar=colorstab[scrollbarpos]
	end
	
	if controls.press("circle") then position = 1 break end
	batteryandtime()
	screen.flip()
	end
	
elseif position == 2 then
	while true do
	controls.read()
	if spanish then screen.print(x,y+1*15,"Español",size,colortext,alpha)
	elseif catalan then screen.print(x,y+1*15,"Català",size,colortext,alpha)
	elseif french then screen.print(x,y+1*15,"Français",size,colortext,alpha)
	elseif english then screen.print(x,y+1*15,"English",size,colortext,alpha) end
	if controls.press("right") then 
		if spanish == true then spanish = false catalan = true dofile("languages.ini")
		elseif catalan == true then catalan = false english = true dofile("languages.ini")
		elseif english == true then english = false french = true dofile("languages.ini")
		elseif french == true then french = false spanish = true dofile("languages.ini")
		end
		options={
			{textcolor,seleccolor,mainbarcolor,scrollbarcolor,text=changecolors},
			{french,spanish,catalan,english,text=languages},
			{"Default equalizer", text= "Default equalizer"},
			{text=leave}
			}
	end
	if controls.press("left") then 
		if spanish == true then spanish = false french = true dofile("languages.ini")
		elseif catalan == true then catalan = false spanish = true dofile("languages.ini")
		elseif english == true then english = false catalan = true dofile("languages.ini")
		elseif french == true then french = false english= true dofile("languages.ini")
		end
		options={
				{textcolor,seleccolor,mainbarcolor,scrollbarcolor,text=changecolors},
				{french,spanish,catalan,english,text=languages},
				{"Default equalizer", text= "Default equalizer"},
				{text=leave}
				}
	end
	
	if controls.press("circle") then position = 1 break end
	screen.flip()
	end
elseif controls.press("cross") and position == 3 then EQ={} EQ=EQdefault
elseif position == 4 then break end
end
batteryandtime()
screen.flip()
end
end

function mp3player(mp3dir,scrollbar)
if mp3dir != playing then 
equalizer.list = files.listfiles(files.nofile(mp3dir))
equalizer.songposition= scrollbar.pos-1
equalizer.id3={}
equalizer.id3=sound.id3(mp3dir) 
song=sound.load(mp3dir); 
song:play(); 
end
while true do
equalizer.blit()	
controls.read()
if controls.press("l") and song:percent() >=1 then
	song:percent(0)
end
if controls.l() and controls.r() then song:stop() xerpi() end
equalizer.changesong()
if controls.press("circle") and equalizer.showmenu == false then song:stop(); song:free(); song=null break; end
if controls.press("select") and equalizer.showmenu == false then break end
if equalizer.showmenu then equalizer.menu() end
--equalizer.move()
if equalizer.showinformation == true then equalizer.information()end

if controls.right() and song:percent() <99 then
	equalizer.xcent = equalizer.xcent + 0.7
	song:percent(equalizer.xcent)		
end
if controls.left() and song:percent() >0.1 then
	equalizer.xcent = equalizer.xcent - 0.7
	song:percent(equalizer.xcent)		
end
equalizer.xcent=song:percent()

screen.flip()
if controls.press("square") then
	if equalizer.showmenu==false then equalizer.showmenu = true; equalizer.show();
	else  equalizer.showmenu=false; equalizer.hide()
	end
end
if controls.press("triangle") then
	if equalizer.showinformation==false then equalizer.showinformation = true equalizer.showinf(); 
	else equalizer.showinformation=false equalizer.hideinf() 
	end
end
if controls.press("start") then song:pause() end
end
end

function sendadhoc()
--aun no tiene adhoc luadev ¬¬ pero no pasa nada, pronto tendrá :)
end

function main()
if song != null then 
	equalizer.blit() 
	if controls.press("select") then
		mp3player(playing)
	end
end
--screen.print(460,5,mainscrollbar.pos,size,white,alpha)
--screen.print(460,20,scrollbar.posfiles,size,white,alpha)
showfiles(filescdir,mainscrollbar)
draw.fillrect(0,0,480,16,black)
draw.fillrect(0,272-16,480,16,black)
drawscrollbar(filescdir,mainscrollbar)
movemainscrollbar()
screen.print(-10,10,"--------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
screen.print(-10,272-20,"-------------------------------------------------------------------------------------------------------------------------------------",size,green,alpha)
batteryandtime()
end