screenWidth,screenHeight = guiGetScreenSize()
mainWidth,mainHeight = 550,352
regWidth,regHeight = 400,344

function loginPanel()
	setPlayerHudComponentVisible("radar",false)  
	setPlayerHudComponentVisible("area_name",false)  
    toggleControl("radar",false)
	showChat(false)	
	local PositionX,PositionY,PositionZ = 2067.5349,41.928261,34.788815;
	local LookAtX,LookAtY,LookAtZ = 2067.5349,41.928261,34.788815;
	setCameraMatrix(PositionX,PositionY,PositionZ,LookAtX,LookAtY,LookAtZ) 
	fadeCamera(true) 	
	function CameraPosition ()
		PositionX = PositionX+0.03; 
		LookAtX = LookAtX+0.3;
		setCameraMatrix(PositionX,PositionY,PositionZ,LookAtX,LookAtY,LookAtZ)
	end
	addEventHandler("onClientPreRender",getRootElement(),CameraPosition)	
	mainWindow = guiCreateWindow(screenWidth/2-mainWidth/2,screenHeight/2-mainHeight/2,mainWidth,mainHeight,"",false)
	guiWindowSetSizable(mainWindow,false)
	btnLogin = guiCreateButton(165,270,242,74,"ИГРАТЬ",false,mainWindow)
	guiSetFont(btnLogin,"clear-normal")
	guiCreateStaticImage(140,23,300,155,"logo.png",false,mainWindow)
	guiSetVisible(mainWindow,true)
	guiSetInputEnabled(true)
	showCursor(true)
	addEventHandler("onClientGUIClick",btnLogin,onClickLogin)	
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),loginPanel)

function onClickLogin(button,state)
	if(button == "left" and state == "up") then
		if (source == btnLogin) then
		    playSound("button.mp3")
			playSound("dayzsounds.mp3")
		    triggerServerEvent("onRequestEnter",getLocalPlayer())
		end
	end
end

function hideLoginWindow()
	removeEventHandler("onClientPreRender",getRootElement(),CameraPosition)
	setCameraTarget(getLocalPlayer())
	showChat(true)
	guiSetInputEnabled(false)
	guiSetVisible(mainWindow,false)
	showCursor(false)
end
addEvent("hideLoginWindow",true)
addEventHandler("hideLoginWindow",getRootElement(),hideLoginWindow)

function startSound()
    randomus = math.random(1,9) 
    sound = playSound("sounds/sd"..randomus..".mp3") 
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startSound)
 
function stopMySound()
    if isElement(sound) then
        destroyElement(sound)
    end
end
addEventHandler("onClientPlayerSpawn",localPlayer,stopMySound)