

function interface:initAP()
	local roots, widgets, groups = element.gui:loadLayout(resources.getPath("cmd.lua"), "")

	self._igmTween = false
	self._tweenDefeat = false
	self._warnOnFewJewels = false
	if (nil ~= widgets.backGround) then
	  self._igmBgPanel = widgets.backGround.window
	  print("BG PANEL REGISTERED")
	else
		print("ONE FAIL")
	end

	if (nil ~= widgets.pauseButton) then
	  self._igmButton = widgets.pauseButton.window
	 self._igmButton:registerEventHandler(self._igmButton.EVENT_BUTTON_CLICK, nil, _handleIGMPressed)
	  print("BG PANEL REGISTERED")
	else
		print("ONE FAIL")
	end

	if (nil ~= widgets.bgPanel) then
		self._bgPanel = widgets.bgPanel.window
	else

	end

	if (nil ~= widgets.quitMMButton) then
		self._quitMainMenuButton = widgets.quitMMButton.window
		self._quitMainMenuButton:registerEventHandler(self._quitMainMenuButton.EVENT_BUTTON_CLICK, nil, _handleQuitToMM)
	  print("BG PANEL REGISTERED")
	else
		print("ONE FAIL")
	end

	if (nil ~= widgets.restartButton) then
		self._restartButton = widgets.restartButton.window
		self._restartButton:registerEventHandler(self._restartButton.EVENT_BUTTON_CLICK, nil, _handleRestart)
	  print("BG PANEL REGISTERED")
	else
		print("ONE FAIL")
	end

	self._dungeonDepthLabel = widgets.dungeonLevelLabel.window

	self._defeatBG = widgets.defeatPanel.window

	self._defeatImage = widgets.typeImage.window

	self._supplyWarning = widgets.alertIMG.window
	--restartButton
	--quitMMButton
end

function interface:setDefeatState(_state)
	self._tweenDefeat = _state
end

function interface:setCauseOfDeathIMG(_type)
	if _type == 1 then
		self._defeatImage:setImage(element.resources.getPath( "health_finish.png" ))
	else
		self._defeatImage:setImage(element.resources.getPath( "ruby_finish.png"  ))
	end
end

function interface:getTweenStatus( )
	local bool = false

	if self._igmTween == true or self._tweenDefeat == true then
		bool = true
	end

	return bool
end

function interface:initGGJMM(  )
	local roots, widgets, groups = element.gui:loadLayout(resources.getPath("mainMenu.lua"), "")

	if (nil ~= widgets.btnStart) then
	 self._startButton = widgets.btnStart.window
	 self._startButton:registerEventHandler(self._startButton.EVENT_BUTTON_CLICK, nil, _goToAp)
	  print("BG PANEL REGISTERED")
	else
		print("ONE FAIL")
	end	--btnStar

	self._quitButton = widgets.quitBattle.window
	self._quitButton:registerEventHandler(self._quitButton.EVENT_BUTTON_CLICK, nil, _Quit)

end

function interface:updateIGM( )
	self._dungeonDepthLabel:setText("Dungeon Level:"..map:getDepth( ).."")
	if self._igmTween == false then
		self._bgPanel:tweenPos(2.5, -90, 0.2)
	else
		self._tweenDefeat = false
		self._bgPanel:tweenPos(2.5, 10, 0.2)
	end

	if self._tweenDefeat == false then
		self._defeatBG:tweenPos(2.5, 110, 0.2)
	else
		self._defeatBG:tweenPos(2.5, 10, 0.2)
	end

	if self._warnOnFewJewels == true then
		self._supplyWarning:setPos(14, 2)
	else
		self._supplyWarning:setPos(-2014, 2)
	end
end

function interface:setSupplyWarning(_state)
	self._warnOnFewJewels = _state
end

function interface:setBgPanelTween(_state)
	self._igmTween = _state
end

function  interface:getBgpanelTween( )
	return self._igmTween
end

function _handleIGMPressed( )
	interface:setBgPanelTween(not interface:getBgpanelTween())
	--map:reset( )
end

function _handleQuitToMM( )

	_bGuiLoaded = false
	_bGameLoaded = false
	map:destroyAll( )
	
	MOAISim.forceGarbageCollection( )
	Game:dropUI(g, resources )
	player:dropXPbar( )
	currentState = 15
end

function _goToAp( )
	effect:dropAll( )
	anim:dropAll( )
	_bGuiLoaded = false
	_bGameLoaded = false
	
	MOAISim.forceGarbageCollection( )
	Game:dropUI(g, resources )
	player:dropXPbar( )
	currentState = 14
end

function _handleRestart( )
	interface:setBgPanelTween(not interface:getBgpanelTween( ))
	_bGuiLoaded = false
	_bGameLoaded = false
	map:destroyAll( )
	player:dropXPbar( )
	MOAISim.forceGarbageCollection( )
	Game:dropUI(g, resources )
	currentState = 14
end

function _Quit( )
	os.exit( )
end