pause={}
pauseSpeed = 20
pauseFade  = 1
pauseOffset = 0
-----------------------------------------------------------
-- PAUSE MENU 
-----------------------------------------------------------

function pause:updatePause()
	if game.paused then 

	  	pause:navigateItems()

		-- SET POSTION OF DOTS ON THE SIDE
		selectorY = easeTo(selectorY, menu.fontSize*2*(pauseSelection), 8)
		pauseOffset = -selectorY/2

		--[[ SELECTIONZ TIME]]
		if aButtonDown then
			-- RESUME
			if pauseItems[pauseSelection]=="Resume" then
				game.unPause()
			end

			-- SAVE
			if pauseItems[pauseSelection]=="Save" then
				saveVals = {n=currentWorld,m=currentLevel}
				love.filesystem.write("Dream.sav", Tserial.pack(saveVals))
			end

			-- QUIT
			if pauseItems[pauseSelection]=="Quit" then
				
				editor.exitEditor()

			end

			-- EDIT
			if  pauseItems[pauseSelection]=="Edit" then
				editor.resumeEdit()
	   		end
		end
		
		if bButtonDown then
			if pauseSelect then 
				game.unPause() 
			end
			if(resolutionSelect) then resolutionSelect=false; pauseSelect=true end
		end
	end

	
end

function pause:checkPause()
	if startButtonDown  then
		if not startButton and (game.state=="Game" or game.state=="Edit") then
			if game.paused==true then 	
				game.unPause()  
			else 					
				game.pause() 
			end
		end
		startButton=true 
	else 
		startButton=false
	end
end

-----------------------------------------------------------
-- GO UP AND DOWN
-----------------------------------------------------------
function pause:navigateItems()
	-- GO UP AN OPTION 
	if upButtonDown then -- MOVE UP
		if(up==false)then
			if(pauseSelect and pauseSelection>1) then pauseSelection = pauseSelection-1 end; 
		end;
	up=true else up =false end;

	-- GO DOWN AN OPTION 
	if downButtonDown then -- MOVE DOWN
		if(down==false)then 
			if(pauseSelect and pauseSelection<#pauseItems) then pauseSelection = pauseSelection+1 end; 
		end;
	down=true else down =false end;
end

-----------------------------------------------------------
-- DRAW THE PAUSE MENU
-----------------------------------------------------------
function pause:drawPause()
	if pauseFade==0 or pauseCanvas==nil then return end

	menu:drawBackground(pauseCanvas) 
	gfx.setCanvas(pauseCanvas)
	
	gfx.setFont(Aracne,menu.fontSize)
	gfx.draw(getImage("SelectorWhite"),pauseCenter.x-16,pauseCenter.y+selectorY+4+pauseOffset)
	for i=1, #pauseItems do
		gfx.printf(pauseItems[i], pauseCenter.x, pauseCenter.y+menu.fontSize*2*i+pauseOffset,  pauseCenter.w, "center"); 
	end 

	local overfade= exitingGame and fade or 1
	gfx.setColor(overfade,overfade,overfade,pauseFade) 
	gfx.setCanvas()
	gfx.draw(pauseCanvas,0,0,0,screenWidth/launchWidth,screenHeight/launchHeight)
	gfx.setShader()

end

-----------------------------------------------------------
-- ACTUALLY PAUSE/UNPAUSE THE GAME
-----------------------------------------------------------
function game.unPause() 
	game.paused=false
	pauseSelect=false
	if game.state=="Edit" then
		pauseFade 	= 0
		pauseCanvas = nil
	end
end

function game.pause() 

	game.paused 			= true; 
	pauseSelect 	= true;  
	pauseCanvas 	= newCanvas(launchWidth,launchHeight)
	pauseItems  	= game.state=="Edit" and {"Resume"} or {"Resume","Quit"}
	pauseCenter.x 	= 120
	pauseCenter.y 	= launchHeight-200-menu.fontSize*2
	pauseCenter.h 	= #pauseItems*menu.fontSize*2

end



