resourceRoot = getResourceRootElement(getThisResource())
localPlayer = getLocalPlayer()
sx, sy = guiGetScreenSize(), getThisResource()

addEventHandler("onClientResourceStart", resourceRoot, function()
  fadeCamera(true)
  --setCameraMatrix(6320.54, -2364, 40, 6311, -2285, 24)
  setCameraMatrix(6237, -2027, 40, 6269, -2029, 27)
  startInfoWindow()
end
)

local screenWidth,screenHeight = guiGetScreenSize()
local buttArrow = dxCreateTexture ( "play.png" )
local buttArrowDown = dxCreateTexture ( "play_on.png" )
local buttArrowClick = dxCreateTexture ( "play_click.png" )
local helpB = dxCreateTexture ( "help.png" )
local helpOnB = dxCreateTexture ( "help_on.png" )
local helpClickB = dxCreateTexture ( "help_click.png" )
local infoB = dxCreateTexture ( "info.png" )
local infoOnB = dxCreateTexture ( "info_on.png" )
local infoClickB = dxCreateTexture ( "info_click.png" )
local playerB = dxCreateTexture ( "player.png" )
local playerOnB = dxCreateTexture ( "player_on.png" )
local playerClickB = dxCreateTexture ( "player_click.png" )

function drawDayzLogo ()
	dxDrawImage ( screenWidth/2-556, screenHeight/2-256, 512, 256, 'logo.png' )
end

function startInfoWindow ()
	exports.imageButton:createImageButton ( 'play_button', screenWidth/2-456, screenHeight/2, 256, 59, 0, buttArrow, buttArrowClick, buttArrowDown )
	exports.imageButton:createImageButton ( 'info_button', screenWidth/2-456, screenHeight/2+89, 256, 59, 0, infoB, infoClickB, infoOnB )
	exports.imageButton:createImageButton ( 'help_button', screenWidth/2-456, screenHeight/2+178, 256, 59, 0, helpB, helpClickB, helpOnB )
	exports.imageButton:createImageButton ( 'player_button', screenWidth/2-456, screenHeight/2+267, 256, 59, 0, playerB, playerClickB, playerOnB )
	addEventHandler ( "onClientRender", root, drawDayzLogo )
	addEvent ( "imageButtonClicked", true )
	addEventHandler ( 'imageButtonClicked', root, showWeaponSelect)
	showCursor ( true )
	showPlayerHudComponent ( 'radar', false )
end

function drawInfoText ()
	dxDrawRectangle ( screenWidth/2-30, screenHeight/2-230, screenWidth/2-100, screenHeight-230, tocolor(36,35,32,235) )
	dxDrawText ( 'Добро пожаловать на сервер MTA DayZ | Survival or Die\nГруппа сервера Вконтакте vk.com/dayz_survival_die\nАрендовать/купить базу,vip панель и другие услуги можно в группе vk.com/dayz_survival_die\nГлавный Администратор сервера Red_Wolf skype vladzver13\nПравила сервера\n1.	На сервере запрещено\n1.	Дюпать.\n2.	Проникать на чужие базы.\n3.	Использовать баги сервера.\n4.	Оскорблять игроков и администрацию.\n5.	Оскорбительное поведение в отношении администрации.\n6.	Обманывать или вводить администрация в заблуждение.\n7.	Загораживать спавны игроков или затруднять движение.\n8.	Кемперить спавны кепок.\n9.	Рекламировать дургие сервера,проекты и сообщества.\n	Всю остальную информацию вы можете узнать в группе сервера vk.com/dayz_survival_die ', screenWidth/2, screenHeight/2-200, screenWidth-200, screenHeight-200, tocolor ( 255, 255, 255 ), 1, 'default', 'left', 'top', false, true )
end

function drawHelpText ()
	dxDrawRectangle ( screenWidth/2-30, screenHeight/2-230, screenWidth/2-100, screenHeight-230, tocolor(36,35,32,235) )
	--dxDrawText ( 'Помощь\nпо\nигре\nhkdgshdskghkasgjldhbkjsdglkahguighaihgsdfhawiouethiagubj;adgshi;uagsjagbkj;agdhuaigiu;agsdbiugabuiagriu;dasghagdjkadad;fbabbagi;giajgiai;agdsh', screenWidth/2, screenHeight/2-200, screenWidth-200, screenHeight-200, tocolor ( 255, 255, 255 ), 1.5, 'default', 'left', 'top', false, true )
	dxDrawText ( 'Этот раздел ещё не доработан.', screenWidth/2, screenHeight/2-200, screenWidth-200, screenHeight-200, tocolor ( 255, 255, 255 ), 1.5, 'default', 'left', 'top', false, true )
end

showHelp = false
showInfo = false


function showWeaponSelect (button)
	if button.name == 'play_button' then
		showCursor ( false )
		guiSetVisible(background_front, false)
		triggerServerEvent("loginPlayerBySeral", localPlayer)
		exports.imagebutton:destroyImageButtonByName("play_button")
		exports.imagebutton:destroyImageButtonByName("info_button")
		exports.imagebutton:destroyImageButtonByName("help_button")
		exports.imagebutton:destroyImageButtonByName("player_button")
		removeEventHandler ( "onClientRender", root, drawDayzLogo )
		removeEventHandler ( 'imageButtonClicked', root, showWeaponSelect)
		if showHelp then
			removeEventHandler ( "onClientRender", root, drawHelpText )
			showHelp = false
		end
		if showInfo then
			removeEventHandler ( "onClientRender", root, drawInfoText )
			showInfo = false
		end
	elseif button.name == 'info_button' then
		if not showInfo then
			addEventHandler ( "onClientRender", root, drawInfoText )
			showInfo = true
			if showHelp then
				removeEventHandler ( "onClientRender", root, drawHelpText )
				showHelp = false
			end
		end
	elseif button.name == 'player_button' then
		showCursor ( false )
		guiSetVisible(background_front, false)
		exports.cloth:showClothWindow()
		exports.imagebutton:destroyImageButtonByName("play_button")
		exports.imagebutton:destroyImageButtonByName("info_button")
		exports.imagebutton:destroyImageButtonByName("help_button")
		exports.imagebutton:destroyImageButtonByName("player_button")
		removeEventHandler ( "onClientRender", root, drawDayzLogo )
		removeEventHandler ( 'imageButtonClicked', root, showWeaponSelect)
		if showHelp then
			removeEventHandler ( "onClientRender", root, drawHelpText )
			showHelp = false
		end
		if showInfo then
			removeEventHandler ( "onClientRender", root, drawInfoText )
			showInfo = false
		end
	elseif button.name == 'help_button' then
		if not showHelp then
			showHelp = true
			addEventHandler ( "onClientRender", root, drawHelpText )
			if showInfo then
				removeEventHandler ( "onClientRender", root, drawInfoText )
				showInfo = false
			end
		end
	end
end

