LoseState = class(Group, function(o, substate)
	Group.init(o)
	o.substate = substate
	o:setup()
end)
function LoseState:setup()
	local o = self
	o.blackout = o:add(Object(0,0,bludG.camera.w, bludG.camera.h))
	o.blackout:setColor(0,0,0,0)
	o.blackout.sprite = sprites['tiles']['white.png']
	o.blackout.drawType = 'stretched'
	o.blackout:setScrollFactor(Vec2(0,0))
	Tweener:addTween(o.blackout.tint, {a=191}, {time=1, onComplete=function()
		o.gameOver = true
		-- add the svg overlay

		o.bg = o:add(Object(0,-bludG.camera.h,bludG.camera.w, bludG.camera.h))
		o.bg.svg = SvgLoader(svg_root .. "interface/loss_blue_bg.svg", false)
		o.bg.drawType = 'svg'
		o.bg.svg:scale(bludG.camera.w/o.bg.svg:getMaxX(), bludG.camera.h/1024)
		o.bg.svg:setScrollFactor(0,0)
		o.iscale = bludG.camera.h/1024

		local interfacesvg = SvgLoader(svg_root .. "interface/loss_blue.svg", false)
		o.interface = o:add(Object(bludG.camera.w/2-interfacesvg:getMaxX()/2*o.iscale,-bludG.camera.h,bludG.camera.w, bludG.camera.h))
		o.interface.svg = interfacesvg
		o.interface.drawType = 'svg'
		o.interface.svg:setScrollFactor(0,0)
		o.interface.svg:scale(o.iscale, o.iscale)

		Tweener:addTween(o.bg.pos, {y=0}, {func='outElastic'})
		Tweener:addTween(o.interface.pos, {y=0}, {func='outElastic', onComplete=function()
			local lossText = o:add(StringObject(0,0,"YOU FAIL", nil, 0.8))
			lossText:setColor(0,0,0) 
			lossText:setScrollFactor(Vec2(0,0))
			local topOff = 160/1024
			topOff = topOff*bludG.camera.h
			lossText:setPosition(-lossText.w, topOff)
			Tweener:addTween(lossText.pos, {x=bludG.camera.w/2-lossText.w/2})
			-- add the buttons for replay, etc
			if o.interface.svg.id then
				-- should move this into the svg loader
				for key, rbd in pairs(o.interface.svg.id) do
					local button = o:add(CameraButton(rbd.minX*o.iscale+o.interface.pos.x, rbd.minY*o.iscale+o.interface.pos.y, (rbd.maxX-rbd.minX)*o.iscale, (rbd.maxY-rbd.minY)*o.iscale))
					button.scrollFactor = Vec2(0,0)
					button.onPress = function()
						if o[key .. "_callback"] then o[key .. "_callback"](o) end
					end
					button:setColor(0,0,0,0)
				end
			end

		end})
	end})

	-- analytics:logEvent("level_loss", {['filename']=o.substate.waveData.filename, ['losstime']=o.substate.waveController.time})
	-- analytics:levelRangedMetric("lose_time", o.substate.waveData.filename, o.substate.waveController.time)
	pd:startList("fromOF")
	pd:addSymbol("levelLose")
	pd:addFloat(1)
	pd:finish("fromOF")
end
function LoseState:draw()
	self.substate:draw()
	Group.draw(self)
end
function LoseState:levelselectbutton_callback()
	mainState:changeState(LevelSelectState())
end
function LoseState:replaybutton_callback()
	mainState:changeState(PlayState(self.substate.waveData))
end
