Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
113 kB
4
Indexable
/**
 * REQUIRED
 *//*
const { href } = window.location;

const segment = href.substr(href.indexOf('/huds/') + 6);
const HUDName = segment.substr(0, segment.lastIndexOf('/'));

io.on("readyToRegister", () => {
  io.emit("register", HUDName, false);
});

io.on("refreshHUD", window.top.location.reload);
*/
/**
 * ADDITIONAL FEATURES
 */
/*
const configs = new ConfigManager();
const actions = new ActionManager();

io.on("hud_config", configs.save);

io.on("hud_action", ({ data, action }) => {
  actions.execute(action, data);
});

io.on("keybindAction", actions.execute);
*/

/*
const GSI = new CSGOGSI();

io.on("update", data => {
  GSI.digest(data);
});

io.on("update_mirv", data => {
  GSI.digestMIRV(data)
});

const killIcon = (iconName, show) => `<div class="kill-icon ${show ? 'show' : ''}"><img src="./elements/${iconName}.png" /></div>`;

const killfeedEntry = kill => {
  const assistHTML = kill.assister ? `
  <div class="assist-container">
    <div class="plus">+</div>
    ${killIcon("flashed", kill.flashed)}
    <div class="assist-name ${kill.assister.team.side}">${kill.assister.name}</div>
  </div>
  `: ``
  const html = `
  <div class="kill-container"><div class="kill">
    ${killIcon("attackerblind", kill.attackerblind)}
    <div class="killer-name ${kill.killer.team.side}">${kill.killer.name}</div>
    ${assistHTML}
    <div class="kill-weapon">
      <img src="/files/img/weapons/${kill.weapon}.png" />
    </div>
    ${killIcon("noscope", kill.noscope)}
    ${killIcon("thrusmoke", kill.thrusmoke)}
    ${killIcon("wallbang", kill.wallbang)}
    ${killIcon("headshot", kill.headshot)}
    <div class="victim-name ${kill.victim.team.side}">${kill.victim.name}</div>
    </div> </div>  
`;
  return html
}
const addKill = kill => {
  const killHTML = killfeedEntry(kill);
  $("#killfeed").append($(killHTML));
}

GSI.on("kill", kill => {
  addKill(kill);
});
*/
/*
const playerAvatars = {};

const getAvatar = (steamid) => {
  if (!steamid) return;
  if (playerAvatars[steamid]) {
    return avatars[steamid];
  }
  playerAvatars[steamid] = new Promise((resolve, rej) => {
    fetch(`/api/players/avatar/steamid/${steamid}`)
      .then(res => res.json())
      .then(res => {
        resolve(res);
      })
      .catch(() => {
        playerAvatars[steamid] = null;
        resolve(null);
      });
  });
}

const fillAvatar = (side, number, steamid) => {
  if (!steamid) return;
  getAvatar(steamid);
  playerAvatars[steamid].then(avatar => {
    if (!avatar) return;
    if (!avatar.custom && !avatar.steam) return;
    if ($(`#players_${side} #player${number} #player_image`).attr("src") === (avatar.custom || avatar.steam)) return;
    $(`#players_${side} #player${number} #player_image`).attr("src", avatar.custom || avatar.steam);
  });
}
*/

const COLOR_CT = 'rgba(40, 120, 240, 1.0)'
const COLOR_T = 'rgba(229, 11, 11, 1.0)'
const COLOR_NEW_CT = 'rgba(40, 120, 240, 1.0)'
const COLOR_NEW_T = 'rgba(229, 11, 11, 1.0)'
const COLOR_RED = 'rgba(229, 11, 11, 1.0)'
const COLOR_MAIN_PANEL = 'rgba(12, 15, 18, 0.75)'
const COLOR_SUB_PANEL = 'rgba(12, 15, 18, 0.6)'
const COLOR_GRAY = 'rgba(191, 191, 191, 1.0)'
const COLOR_WHITE = 'rgba(250, 250, 250, 1.0)'
const COLOR_WHITE_HALF = 'rgba(250, 250, 250, 0.5)'
const COLOR_WHITE_DULL = 'rgba(250, 250, 250, 0.25)'
const PLAYER_ORANGE = 'rgba(237, 163, 56, 1.0)'
const PLAYER_GREEN = 'rgba(16, 152, 86, 1.0)'
const PLAYER_BLUE = 'rgba(104, 163, 229, 1.0)'
const PLAYER_YELLOW = 'rgba(230, 241, 61, 1.0)'
const PLAYER_PURPLE = 'rgba(128, 60, 161, 1.0)'
const DEV_PURPLE = 'rgba(200, 0, 255, 1.0)'
/*
const COLOR_CT = 'rgba(40, 120, 240, 1.0)'
const COLOR_T = 'rgba(229, 11, 11, 1.0)'
const COLOR_NEW_CT = 'rgba(40, 120, 240, 1.0)'
const COLOR_NEW_T = 'rgba(229, 11, 11, 1.0)'
const COLOR_RED = 'rgba(229, 11, 11, 1.0)'
const COLOR_MAIN_PANEL = 'rgba(12, 15, 18, 0.75)'
const COLOR_SUB_PANEL = 'rgba(12, 15, 18, 0.6)'
const COLOR_GRAY = 'rgba(191, 191, 191, 1.0)'
const COLOR_WHITE = 'rgba(250, 250, 250, 1.0)'
const COLOR_WHITE_HALF = 'rgba(250, 250, 250, 0.5)'
const COLOR_WHITE_DULL = 'rgba(250, 250, 250, 0.25)'
const PLAYER_ORANGE = 'rgba(237, 163, 56, 1.0)'
const PLAYER_GREEN = 'rgba(16, 152, 86, 1.0)'
const PLAYER_BLUE = 'rgba(104, 163, 229, 1.0)'
const PLAYER_YELLOW = 'rgba(230, 241, 61, 1.0)'
const PLAYER_PURPLE = 'rgba(128, 60, 161, 1.0)'
const DEV_PURPLE = 'rgba(200, 0, 255, 1.0)'
*/

var scoreboard_players_left = [
	['Nickname1', '3', '4', '2', '2.13', '1', 11 /*'10'*/],
	['Nickname2', '3', '4', '2', '2.13', '1', 12 /*'10'*/],
	['Nickname3', '3', '4', '2', '2.13', '1', 14 /*'10'*/],
	['Nickname4', '3', '4', '2', '2.13', '1', 13 /*'10'*/],
	['Nickname5', '3', '4', '2', '2.13', '1', 15 /*'10'*/],
]

var scoreboard_players_right = [
	['Nickname1', '3', '4', '2', '2.13', '1', 15 /*'10'*/],
	['Nickname2', '3', '4', '2', '2.13', '1', 12 /*'10'*/],
	['Nickname3', '3', '4', '2', '2.13', '1', 13 /*'10'*/],
	['Nickname4', '3', '4', '2', '2.13', '1', 11 /*'10'*/],
	['Nickname5', '3', '4', '2', '2.13', '1', 14 /*'10'*/],
]

var teams = {
	left: {},
	right: {},
	team_3: {},
	team_4: {},
	team_5: {},
	team_6: {},
}
var start_money = {}
var round_now = 0
var last_round = 0
var freezetime = false
var radarToggle = null



/*var round_now =
map.round + (round.phase == 'over' || round.phase == 'intermission' ? 0 : 1)
if ((round.phase == 'freezetime' && !freezetime) || round_now != last_round) {
	start_money = {}
}*/

function updatePage(data) {
	var matchup = data.getMatchType()
	var match = data.getMatch()
	var team_one = data.getTeamOne()
	var team_two = data.getTeamTwo()
	var team_three = data.getTeamThree()
	var team_for = data.getTeamFor()
	var team_five = data.getTeamFive()
	var team_six = data.getTeamSix()
	var team_ct = data.getCT()
	var team_t = data.getT()
	var phase = data.phase()
	var observed = data.getObserved()
	var players = data.getPlayers()
	var round = data.round()
	var map = data.map()
	live_map = map
	var previously = data.previously()
	var bomb = data.bomb()
	var round_now = map.round + (round.phase == "over" || round.phase == "intermission"
        ? 0
        : 1);
    if ((round.phase == "freezetime" && !freezetime) || round_now != last_round) {
        start_money = {};
    }

	var test_player = data.getPlayer(1)
	if (test_player) {
		teams.left = test_player.team.toLowerCase() == 'ct' ? team_ct : team_t
		teams.right = test_player.team.toLowerCase() != 'ct' ? team_ct : team_t


		teams.left.name = team_one.team_name || teams.left.name
		teams.right.name = team_two.team_name || teams.right.name
		teams.team_3.name = team_three.team_name || teams.team_3.name
		teams.team_4.name = team_for.team_name || teams.team_4.name
		teams.team_5.name = team_five.team_name || teams.team_5.name
		teams.team_4.name = team_six.team_name || teams.team_6.name
		teams.left.short_name = team_one.short_name || teams.left.short_name
		if (teams.left.short_name === undefined || teams.left.short_name === null) {
			if (teams.left.name == 'Counter-terrorists') {
				teams.left.short_name = 'CT'
			} else {
				teams.left.short_name = 'TT'
			}
		}
		teams.right.short_name = team_two.short_name || teams.right.short_name
		if (
			teams.right.short_name === undefined ||
			teams.right.short_name === null
		) {
			if (teams.right.name == 'Counter-terrorists') {
				teams.right.short_name = 'CT'
			} else {
				teams.right.short_name = 'TT'
			}
		}
		teams.left.logo = team_one.logo || null
		teams.right.logo = team_two.logo || null
		teams.team_3.logo = team_three.logo || null
		teams.team_4.logo = team_for.logo || null
		teams.team_5.logo = team_five.logo || null
		teams.team_6.logo = team_six.logo || null
		teams.left.flag = team_one.country_code || null
		teams.right.flag = team_two.country_code || null
	}
	if (_print_player_data) {
		printPlayerData(players)
	}

	if(teams.right.side == "ct"){
		//$("#right_background").addClass("defuse_background");
		$("#left_background").removeClass();
		$("#left_bar").removeClass();
		$('#left_img').removeClass();
		$("#right_background").removeClass();
		$("#right_bar").removeClass();
		$('#right_img').removeClass();
		$("#right_background").addClass("defuse_background2");
		$("#right_bar").addClass("defuse_bar");
		$('#right_img').addClass("defuse_img");
		$("#left_background").addClass("bomb_background");
		$("#left_bar").addClass("bomb_bar");
		$('#left_img').addClass("bomb_img");
		
	}
	else{
		$("#left_background").removeClass();
		$("#left_bar").removeClass();
		$('#left_img').removeClass();
		$("#right_background").removeClass();
		$("#right_bar").removeClass();
		$('#right_img').removeClass();
		$("#left_background").addClass("defuse_background");
		$("#left_bar").addClass("defuse_bar");
		$('#left_img').addClass("defuse_img");
		$("#right_background").addClass("bomb_background");
		$("#right_bar").addClass("bomb_bar");
		$('#right_img').addClass("bomb_img");
	}

	//Настройки Best of 1, Best of 3, Best of 5
	setupBestOf(matchup, match)
	if (matchup && matchup.toLowerCase() != 'none') {
		//var block = $("<div class='block'></div>")
		var left_bl = $('<div></div>')
		var right_bl = $('<div></div>')
		for (var x = 0; x < (matchup == 'bo5' ? 3 : 2); x++) {
			/*block
				.clone()
				.appendTo($(left_bl))
				.addClass(match.team_1.map_score > x ? 'win' : '')
			block
				.clone()
				.appendTo(right_bl)
				.addClass(match.team_2.map_score > x ? 'win' : '')*/
		}
		$('#match_one_info').show()
		$('#match_two_info').show()
		$('#match_one_info').html(left_bl)
		$('#match_two_info').html(right_bl)

		$('#match_info').show()
		$('#match_info').text(
			'Best Of ' +
				matchup.substr(2) /*+ ' | LIVE MAP: ' + live_map.name + ' ' /*+
				teams.left.name*/
		)

		/* информация о текущей карте live */
		/*
		$('#map_map').show()
		$('#map_map').text(match.team_1.map_map + '')*/

		$('#online_map').text(match.map.online_map + '' + match.map.team_pick_map)
		$('').show()
		/*$('#LIVE_map').text(match.team_3.map_map + '' + match.team_3.LIVE_map + '')*/

		/* Информация об чемпинате/лиге/мероприятии */
		$('#left_events').text(match.map.left_events + '')
		$('#left_events').show()
		$('#right_events').text(match.map.right_events + '')
		$('#right_events').show()

		/* текстовые данные по картам */
		/* пик 1 */
		$('.map_pick_1')
			.text(match.map.map_pick_1 + '')
			.show()
		$('.team_1_pick')
			.text(match.map.team_1_pick + '')
			.show()
		$('.score_map_1')
			.text(match.map.score_map_1 + '')
			.show()
		$('.playing_1')
			.text(match.map.playing_1 + '')
			.show()
		$('.win_map_1')
			.text(match.map.win_map_1 + '')
			.show()
		/* пик 2 */
		$('.map_pick_2')
			.text(match.map.map_pick_2 + '')
			.show()
		$('.team_2_pick')
			.text(match.map.team_2_pick + '')
			.show()
		$('.score_map_2')
			.text(match.map.score_map_2 + '')
			.show()
		$('.playing_2')
			.text(match.map.playing_2 + '')
			.show()
		$('.win_map_2')
			.text(match.map.win_map_2 + '')
			.show()

		/* decider */
		$('.decider_map')
			.text(match.map.decider_map + '')
			.show()
		$('.score_map_3')
			.text(match.map.score_map_3 + '')
			.show()
		$('.win_map_3')
			.text(match.map.win_map_3 + '')
			.show()
		$('.playing_3')
			.text(match.map.playing_3 + '')
			.show()

			/* fon pick map */
		$('#pick_map_team1').css(
		'background-image',
		'url(/storage/MAPS/' + match.map.pick_map_team1 + '.png)'
		)
		$('#pick_map_team2').css(
		'background-image',
		'url(/storage/MAPS/' + match.map.pick_map_team2 + '.png)'
		)
		$('#decider').css(
		'background-image',
		'url(/storage/MAPS/' + match.map.decider + '.png)'
		)
		$('#logo_champ').css(
			'background-image',
			'url(/storage/champ/' + match.map.logo_champ + '.png)'
			)

	} else {
		$('#match_one_info').hide()
		$('#match_two_info').hide()
		$('#match_info').hide()
		$('#map_map').hide()
		$('#logo_champ').hide()
		/*$('.pick_map_match').hide()
		$('#pick_map_team0').hide()
		$('#pick_map_team1').hide()
		$('#pick_map_team2').hide()
		$('#decider').hide()
		$('#left_events').hide()
		$('#right_events').hide()
		$('#online_map').hide()*/
	}

	

CSGOGSI.prototype.digestMIRV = function (raw) {
	if (!this.last) {
		return null;
	}
	var data = raw.keys;
	var killer = this.last.players.filter(function (player) { return player.steamid === data.attacker.xuid; })[0];
	var victim = this.last.players.filter(function (player) { return player.steamid === data.userid.xuid; })[0];
	var assister = this.last.players.filter(function (player) { return player.steamid === data.assister.xuid && data.assister.xuid !== '0'; })[0];
	if (!killer || !victim) {
		return null;
	}
const GSI = new CSGOGSI();

io.on("update", data => {
  GSI.digest(data);
});

io.on("update_mirv", data => {
  GSI.digestMIRV(data)
});
const killIcon = (iconName, show) => `<div class="kill-icon ${show ? 'show' : ''}"><img src="./elements/${iconName}.png" /></div>`;

const killfeedEntry = kill => {
  const assistHTML = kill.assister ? `
  <div class="assist-container">
    <div class="plus">+</div>
    ${killIcon("flashed", kill.flashed)}
    <div class="assist-name ${kill.assister.team.side}">${kill.assister.name}</div>
  </div>
  `: ``
  const html = `
  <div class="kill-container"><div class="kill">
    ${killIcon("attackerblind", kill.attackerblind)}
    <div class="killer-name ${kill.killer.team.side}">${kill.killer.name}</div>
    ${assistHTML}
    <div class="kill-weapon">
      <img src="/files/img/weapons/${kill.weapon}.png" />
    </div>
    ${killIcon("noscope", kill.noscope)}
    ${killIcon("thrusmoke", kill.thrusmoke)}
    ${killIcon("wallbang", kill.wallbang)}
    ${killIcon("headshot", kill.headshot)}
    <div class="victim-name ${kill.victim.team.side}">${kill.victim.name}</div>
    </div> </div>  
`;
  return html
}
const addKill = kill => {
  const killHTML = killfeedEntry(kill);
  $("#killfeed").append($(killHTML));
}

GSI.on("kill", kill => {
  addKill(kill);
});
}
	//История раундов
	const SlotSide = {
		left: 'left',
		right: 'right',
	}

	const getSlotSide = function (observerSlot) {
		return observerSlot !== 0 && observerSlot <= 5
			? SlotSide.left
			: SlotSide.right
	}

	const updateRoundWinPanel = (function () {
		const $roundHistoryPanel = $('#round_history_panel')
		const $round = $roundHistoryPanel.find('#ordinal_number')
		const $roundHistory = $roundHistoryPanel
			.find('#round_history')
			.children('li')

		const updateRoundLabel = function (isFirstHalf) {
			$round.text(isFirstHalf ? '1ST' : '2ND')
		}

		const getRoundWinIcon = function (reason) {
			const basePath = '/huds/fyflo_caster_avatar_full_team2_BO3/img/round'
			const roundWinIconMap = {
				ct_win_elimination: `${basePath}/ct/kill.png`,
				t_win_elimination: `${basePath}/t/kill.png`,
				t_win_bomb: `${basePath}/exploded.png`,
				ct_win_defuse: `${basePath}/icon_defuse_CT.png`,
				ct_win_time: `${basePath}/time3.png`,
			}
			const $img = $('<img />')
			$img.attr('src', roundWinIconMap[reason])
			return $img
		}

		let previousRoundWins = {}
		let previousRound = undefined
		return function (data) {
			const roundWins = { ...data.map().round_wins }
			// С учетом производительности обновлять экран только при изменении roundWins
			if (JSON.stringify(previousRoundWins) !== JSON.stringify(roundWins)) {
				if (!roundWins) {
					$roundHistory.each(function (index, element) {
						const $element = $(element)
						$element.find('.round').text(index + 1)
						$element.find('.left').html('')
						$element.find('.right').html('')
					})
					return
				}

				const shouldShowFirstHalfPanel = data.map().round < 15 // После завершения 15 раундов переключитесь на дисплей 2nd HALF.

				updateRoundLabel(shouldShowFirstHalfPanel)

				$roundHistory.each(function (index, element) {
					const $element = $(element)
					const round = shouldShowFirstHalfPanel ? index + 1 : index + 16 // Начиная с 16 во второй половине

					// Обновление метки круглого числа.
					$element.find('.round').text(round)

					const roundWinnerReason = roundWins[round.toString()]
					if (roundWinnerReason) {
						const $roundWinIcon = getRoundWinIcon(roundWinnerReason)
						const ctSlotSide =
							data.getCT().players.length !== 0
								? getSlotSide(data.getCT().players[0].observer_slot)
								: SlotSide.left
						const isCtWin = roundWinnerReason.startsWith('ct_')
						const isTWin = roundWinnerReason.startsWith('t_')

						// В случае отсутствия данных
						if (!isCtWin && !isTWin) {
							$element.find('.left').html('')
							$element.find('.right').html('')
							return
						}

						if (ctSlotSide === SlotSide.left) {
							$element.find('.left').html(isCtWin ? $roundWinIcon : '')
							$element.find('.right').html(isCtWin ? '' : $roundWinIcon)
						} else if (ctSlotSide === SlotSide.right) {
							$element.find('.left').html(isCtWin ? '' : $roundWinIcon)
							$element.find('.right').html(isCtWin ? $roundWinIcon : '')
						}
					} else {
						// Если нет информации о победителе раунда, например, раунд, который еще не был сыгран
						$element.find('.left').html('')
						$element.find('.right').html('')
					}
				})
			}
			previousRoundWins = roundWins
			previousRound = data.map().round
		}
	})()

	//история

	updateTopPanel()
	updatekMapTeam()
	updateLeague()
	updateRoundNow(round, map)
	updateScoreboard()
	updateRoundState(phase, round, map, previously, bomb, players)
	updateObserved(observed)
	updatePlayers(players, observed, phase, previously)
	updateTeamValues(teams.left, teams.right)
	countNades(teams.left, teams.right)
	freezetime = round.phase == 'freezetime'
	last_round = round_now
	updateRoundWinPanel(data)
	//handleKillFeed(data, players, observed, phase, previously)
	
	
	//fonMapPick()
	//backgrounds()
}

/* killfeed */
/*
$(function() {
    var tKillNames = data.getPlayer(1);;//вы можете добавить или удалить здесь больше "напарников"
    var ctKillNames = data.getPlayer(6);; //можно добавить сюда еще "врагов"
    var weapons = ["ssg", "ak47", "deagle", "awp", "g3sg1", "m4a4"]; //вы можете добавить или удалить здесь больше изображений оружия здесь
    var $killFeedContainer = $('.kill-feed');
    var $killFeedElement = $('.kill-feed > div').hide();

    function handleKillFeed() {
        var $newFeedElement = $killFeedElement.clone();
        $newFeedElement.find('.weapons img:first-child').attr('src', './images/' + weapons[Math.floor(Math.random() * weapons.length)] + '.png'); //рисование оружия
        $player.find('.t').text(tKillNames[Math.floor(Math.random() * tKillNames.length)]); //рисование «напарника»
        $player.find('.ct').text(ctKillNames[Math.floor(Math.random() * ctKillNames.length)]);//рисуем "врага"
        $killFeedContainer.append($player.show().delay(2000).fadeOut(1000, function() { //рисование контейнера
            $(this).remove()
        }))
    }
    $(document).on("contextmenu", function(e) {
        e.preventDefault()
    });
    window.setInterval(handleKillFeed, 450)// время между убийствами
}); 
*/
/* killfeed */

function setupBestOf(matchup, match) {
	if (matchup && matchup.toLowerCase() != 'none') {
		if (matchup == 'bo1') {
			$('#left_team .block2')
				.css('opacity', '1')
				.css('background-color', match.team_1.map_score >= 1 ? COLOR_WHITE : '')
			$('#right_team .block2')
				.css('opacity', '1')
				.css('background-color', match.team_2.map_score >= 1 ? COLOR_WHITE : '')
		} else if (matchup == 'bo3') {
			$('#left_team .block4')
				.css('opacity', '1')
				.css('background-color', match.team_1.map_score >= 1 ? COLOR_WHITE : '')
			$('#left_team .block5')
				.css('opacity', '1')
				.css('background-color', match.team_1.map_score >= 2 ? COLOR_WHITE : '')
			$('#right_team .block4')
				.css('opacity', '1')
				.css('background-color', match.team_2.map_score >= 1 ? COLOR_WHITE : '')
			$('#right_team .block5')
				.css('opacity', '1')
				.css('background-color', match.team_2.map_score >= 2 ? COLOR_WHITE : '')
		} else if (matchup == 'bo5') {
			$('#left_team .block1')
				.css('opacity', '1')
				.css('background-color', match.team_1.map_score >= 1 ? COLOR_WHITE : '')
			$('#left_team .block2')
				.css('opacity', '1')
				.css('background-color', match.team_1.map_score >= 2 ? COLOR_WHITE : '')
			$('#left_team .block3')
				.css('opacity', '1')
				.css('background-color', match.team_1.map_score >= 3 ? COLOR_WHITE : '')
			$('#right_team .block1')
				.css('opacity', '1')
				.css('background-color', match.team_2.map_score >= 1 ? COLOR_WHITE : '')
			$('#right_team .block2')
				.css('opacity', '1')
				.css('background-color', match.team_2.map_score >= 2 ? COLOR_WHITE : '')
			$('#right_team .block3')
				.css('opacity', '1')
				.css('background-color', match.team_2.map_score >= 3 ? COLOR_WHITE : '')
		}
	}
}

function updatekMapTeam() {
	$('#team_1_pick_map_1').attr(
		'src',
		'/storage/' + teams.team_3.logo /*+ '.png'*/
	)
	$('#team_1_pick_map_1_win_1').attr(
		'src',
		'/storage/' + teams.team_4.logo /*+ '.png'*/
	)
	$('#team_2_pick_map_2').attr(
		'src',
		'/storage/' + teams.team_5.logo /*+ '.png'*/
	)
	$('#team_2_pick_map_2_win_2').attr(
		'src',
		'/storage/' + teams.team_6.logo /*+ '.png'*/
	)
}

	/*//fon pick map
	function fonMapPick () {
		$('#pick_map_team1').css(
			'background-image',
			'url(/storage/MAPS/' + match.map.pick_map_team1 + '.png)'
		
		$('#pick_map_team1').attr(
			'src',
			'/storage/MAPS/' + match.map.pick_map_team1 + '.png')
	})*/

function updateTopPanel() {
	//#region Team Name
	$('#left_team #main')
		.text(teams.left.name.toUpperCase())
		.css('color', teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	$('#right_team #main')
		.text(teams.right.name.toUpperCase())
		.css('color', teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	//#endregion

	//#region Team Score
	$('#left_team #score')
		.text(teams.left.score)
		.css('color', teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	$('#right_team #score')
		.text(teams.right.score)
		.css('color', teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	//#endregion

	//#region Poles
	$('#left_team .bar').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#right_team .bar').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)

	//цвет фон кейтов и бомбы
	/*$('#players_left #player_bomb_kit2').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_right #player_bomb_kit3').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)*/
/*
	$('#players_left .player_bomb_kit4 ').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_right #player_bomb_kit4 ').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)*/
/*
	$(' #players_left #player_bomb_kit_image2').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)

	$(' #players_right #player_bomb_kit_image3').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)*/
	//цвет фон кейтов и бомбы

	// Цвет фона камеры

	$('#players_left #player_spec_bar').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_right #player_spec_bar').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_left #player_spec_bar_bg').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_right #player_spec_bar_bg').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)

	$('#players_left #player_spec_bar_bg2').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_right #player_spec_bar_bg2').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
// Цвет фона камеры //
	

	$('#left_team #alert #alert_pole_right').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#right_team #alert #alert_pole_left').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#match_pole_1').css(
		'background-color',
		teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#match_pole_2').css(
		'background-color',
		teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	//#endregion

	//#region Team Logos
	if (!teams.left.logo) {
		teams.left.logo = 'logo_' + teams.left.side.toLowerCase() + '_default.png'
	}
	if (!teams.right.logo) {
		teams.right.logo = 'logo_' + teams.right.side.toLowerCase() + '_default.png'
	}
	$('#left_team #team_logo').attr('src', '/storage/' + teams.left.logo)
	$('#right_team #team_logo').attr('src', '/storage/' + teams.right.logo)


	//#region Team Flag
	if (teams.left.flag && disp_team_flags) {
		$('#left_team #team_flag').css(
			'background-image',
			'url(/files/img/flags-50/' + teams.left.flag + '.png)'
		)
	} else {
		$('#left_team #team_flag').css('background-image', '')
	}
	if (teams.right.flag && disp_team_flags) {
		$('#right_team #team_flag').css(
			'background-image',
			'url(/files/img/flags-50/' + teams.right.flag + '.png)'
		)
	} else {
		$('#right_team #team_flag').css('background-image', '')
	}
	//#endregion
}

function updateLeague() {
	if (_displayRadar && radarToggle == null) {
		toggleRadar(true)
	}
	if (_displayOnlyMainImage) {
		$('#players_left #box_image').css('width', '405px')
		$('#players_left #box_image').css('height', '85px')
		$('#players_left #box_image').css('top', '0px')
		$('#players_left #box_image').css('right', '-5px')
		$('#players_left #box_image').css('top', '-5px')
		$('#players_left #box_image').attr('src', _leftOneImage)
		$('#players_left #box_image').css('border', 'none')
		$('#players_left #box_image2').css('opacity', 0)
		$('#players_left #box_image3').css('opacity', 0)
	} else {
		$('#players_left #box_image').attr('src', _left_image)
		$('#players_left #box_image2').attr('src', _left_image2)
		$('#players_left #box_image3').attr('src', _left_image3)
	}

	$('#players_left #main_primary').text(_left_primary)
	$('#players_left #main_secondary').text(_left_secondary)
	$('#players_right #box_image').attr('src', _right_image)
	$('#players_right #main_primary').text(_right_primary)
	$('#players_right #main_secondary').text(_right_secondary)
}



function updateRoundNow(round, map) {
	/*//оригинальный счетчит раундов и времени
	round_now = map.round + (round.phase == "over" || round.phase == "intermission" ? 0 : 1);
	$("#round_number").text("Round " + round_now + "/30");
	if ((round.phase == "freezetime" && !freezetime) || round_now != last_round) {
	  start_money = {};
	}*/
	
	//2 не оригинальный счетчит раундов и времени
	
	
	var ot_length = 0;
	var ot_count = 0;
	var run_once = 0;
	var round_now = map.round + (round.phase == "over" || round.phase == "intermission" ? 0 : 1);
//esea fix
if((teams.left.score + teams.right.score) > 14 && round_now <16){
	round_now = round_now + 15
}

//OT Count
//Played more than 30 rounds
//Add one to the OT counter
//Add only once per OT
//console.log(run_once)
if ((round_now - 30) > 0){
	if(((round_now - 36) % ot_length == 0 && run_once == 0 && round.phase == "freezetime") || round_now != last_round){
		ot_count++
		run_once = 1;
	}

	if(run_once == 1 && round.phase == 'Match is live'){
		run_once = 0;
	}
	$("#round_number").html("ОТ Round " + (round_now - 30 - ((ot_count-1) * ot_length)) + "/6");
	// if ((round_now - 37) % ot_length == 0 && run_once == 0){
	//     run_once = 1
	//     ot_count++
	// }
	// if (round.phase == "over"){
	//     run_once = 0
	// }
	if(ot_count > 0){
		if((teams.left.score + teams.right.score) > 30 && round_now <30){
			round_now = round_now + 1
		
		$("#round_number").css("font-size", "10px")
		$("#round_number").html("OT: " + ot_count + " Round " + (round_now - 30 - ((ot_count-1) * ot_length)) + "/6")
		}
	}
} else{
	$("#round_number").html("Round " + round_now + "/30");
}
		
}	
	

	
    

	//не оригинальный счетчит раундов и времени
/*
	var ot_length = 0;
	var round_now = map.round

    //esea fix
    if((teams.left.score + teams.right.score) > 14 && round_now <14){
        round_now = round_now + 15
    }

    //OT Count
    //Played more than 30 rounds
    //Add one to the OT counter
    //Add only once per OT
    console.log(run_once)
    if ((round_now - 30) > 0){
        if((round_now - 37) % ot_length == 0 && run_once == 0 && round.phase == "freezetime"){
            ot_count++
            run_once = 1;
        }
    
        if(run_once == 1 && round.phase == 'Match is live'){
            run_once = 0;
        }
        $("#round_number").html("Round " + (round_now - 30 - ((ot_count-1) * ot_length)) + "/6");
        // if ((round_now - 37) % ot_length == 0 && run_once == 0){
        //     run_once = 1
        //     ot_count++
        // }
        // if (round.phase == "over"){
        //     run_once = 0
        // }
        if(ot_count > 0){
            $("#round_number").css("font-size", "10px")
            $("#round_number").html("OT: " + ot_count + " Round " + (round_now - 30 - ((ot_count-1) * ot_length)) + "/6")
        }
    } else{
        $("#round_number").html("Round " + round_now + "/30");
    }
  }*/



function updateRoundState(phase, round, map, previously, bomb, players) {
	//console.log(phase.phase); // * freezetime/live/over/bomb/defuse/paused/timeout_t/timeout_ct
	// console.log(round.bomb); // * exploded/defused/planted NULL
	// console.log(round.win_team); // * CT/T

	//количество выживших родной
	/*
	var left_alive = checkAlivePlayers(teams.left.players)
	var right_alive = checkAlivePlayers(teams.right.players)
	$('#players_alive_bottom_left')
		.text(left_alive)
		.css('color', teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	$('#players_alive_bottom_right')
		.text(right_alive)
		.css('color', teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	if (left_alive == 1 || right_alive == 1) {
		$('#player_counter').find('#player_counter_text').text('Clutch Situation')
	} else {
		$('#player_counter').find('#player_counter_text').text('Players Alive')
	}
	$('#radar_border').css(
		'border-image',
		teams.left.side == 'ct'
			? 'linear-gradient(to right, ' + COLOR_NEW_CT + ', ' + COLOR_NEW_T + ') 1'
			: 'linear-gradient(to right, ' + COLOR_NEW_T + ', ' + COLOR_NEW_CT + ') 1'
	)
	*/

	//количество выживших не родной
	var left_alive = checkAlivePlayers(teams.left.players)
	var right_alive = checkAlivePlayers(teams.right.players)

	$('#player_counter')
		.find('#player_counter_numbers')
		.find('#left_number')
		.text(left_alive)
		.css('color', teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)

	$('#player_counter')
		.find('#player_counter_numbers')
		.find('#right_number')
		.text(right_alive)
		.css('color', teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)

	if (left_alive == 1 || right_alive == 1) {
		$('#player_counter').find('#player_counter_text').text('Clutch Situation')
	} else {
		$('#player_counter').find('#player_counter_text').text('Players Alive')
	} 

	switch (phase.phase) {
		case 'warmup':
			updateStateWarmup(phase)
			break
		case 'freezetime':
			updateStateFreezetime(phase, previously)
			break
		case 'live':
			updateStateLive(phase, bomb, players, previously)
			break
		case 'over':
			updateStateOver(phase, map, round, previously)
			break
		case 'bomb':
			updateStatePlanted(phase, round, previously)
			break
		case 'defuse':
			updateStateDefuse(phase, bomb, players)
			break
		case 'paused':
			updateStatePaused(phase, 'paused', previously)
			break
		case 'timeout_t':
			updateStatePaused(phase, 'timeout_t', previously)
			break
		case 'timeout_ct':
			updateStatePaused(phase, 'timeout_ct', previously)
			break
	}
}

function sortFunctionScoreboard(a, b) {
	if (a[6] === b[6]) {
		return 0
	} else {
		return a[6] > b[6] ? -1 : 1
	}
}

function toggleScoreboard(toggle) {
	if (toggle == true) {
		if ($('#live_page').hasClass('animated fadeIn')) {
			$('#live_page').removeClass('animated fadeIn')
		}
		$('#live_page').addClass('animated fadeOut')

		if ($('#scoreboard').hasClass('animated fadeOut')) {
			$('#scoreboard').removeClass('animated fadeOut')
		}
		$('#scoreboard').addClass('animated fadeIn')

		$('#scoreboard').css('opacity', 1)
	} else {
		if ($('#live_page').hasClass('animated fadeOut')) {
			$('#live_page').removeClass('animated fadeOut')
			$('#live_page').addClass('animated fadeIn')
		}
		if ($('#scoreboard').hasClass('animated fadeIn')) {
			$('#scoreboard').removeClass('animated fadeIn')
		}
		$('#scoreboard').addClass('animated fadeOut')
	}
}

function toggleRadar(toggle) {
	if (toggle == true) {
		radarToggle = true
		$('#radar_border').css('opacity', 1)
	} else {
		radarToggle = false
		$('#radar_border').css('opacity', 0)
	}
}

function updateScoreboard() {
	var today = new Date()
	var date =
		today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
	var time =
		today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds()
	var dateTime = date + ' ' + time
	$('#s_top_datetime').text(dateTime)
	$('#s_top_left #s_top_team').text(
		teams.left.name /*+ ' [' + teams.left.short_name.toUpperCase() + ']'*/
	)
	$('#s_top_right #s_top_team').text(
		teams.right.name /*+ ' [' + teams.right.short_name.toUpperCase() + ']'*/
	)
	$('#s_top_mid #s_top_map').text(live_map.name)
	$('#s_top_left #s_top_score')
		.text(teams.left.score)
		.css('color', teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	$('#s_top_right #s_top_score')
		.text(teams.right.score)
		.css('color', teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T)
	$('#s_top_left #s_team_logo').css(
		'background-image',
		'url(' + '/storage/' + teams.left.logo + ')'
	)
	$('#s_top_right #s_team_logo').css(
		'background-image',
		'url(' + '/storage/' + teams.right.logo + ')'
	)
	if (teams.left.side == 'ct') {
		$('#s_team #s_player1').css('background-color', 'rgba(40, 120, 240, 0.35)')
		$('#s_team #s_player3').css('background-color', 'rgba(40, 120, 240, 0.35)')
		$('#s_team #s_player5').css('background-color', 'rgba(40, 120, 240, 0.35)')
		$('#s_team2 #s_player1').css('background-color', 'rgba(229, 11, 11, 0.35)')
		$('#s_team2 #s_player3').css('background-color', 'rgba(229, 11, 11, 0.35)')
		$('#s_team2 #s_player5').css('background-color', 'rgba(229, 11, 11, 0.35)')
	} else {
		$('#s_team #s_player1').css('background-color', 'rgba(229, 11, 11, 0.35)')
		$('#s_team #s_player3').css('background-color', 'rgba(229, 11, 11, 0.35)')
		$('#s_team #s_player5').css('background-color', 'rgba(229, 11, 11, 0.35)')
		$('#s_team2 #s_player1').css('background-color', 'rgba(40, 120, 240, 0.35)')
		$('#s_team2 #s_player3').css('background-color', 'rgba(40, 120, 240, 0.35)')
		$('#s_team2 #s_player5').css('background-color', 'rgba(40, 120, 240, 0.35)')
	}

	scoreboard_players_left.sort(sortFunctionScoreboard)
	scoreboard_players_right.sort(sortFunctionScoreboard)

	if (teams.left.players) {
		for (var i = 0; i < 5; i++) {
			if (i >= teams.left.players.length) {
				let $scoreboard = $(
					'#scoreboard ' + '#s_teams ' + '#s_team' + ' #s_player' + (i + 1)
				)
				$scoreboard.find('#s_p_nickname').text('UNCONNECTED')

				$scoreboard.css('color', 'rgb(169,169,169)')
			} else {
				let $scoreboard = $(
					'#scoreboard ' + '#s_teams ' + '#s_team' + ' #s_player' + (i + 1)
				)
				$scoreboard.find('#s_p_nickname').text(scoreboard_players_left[i][0])
				$scoreboard.find('#s_p_kills').text(scoreboard_players_left[i][1])
				$scoreboard.find('#s_p_assists').text(scoreboard_players_left[i][2])
				$scoreboard.find('#s_p_deaths').text(scoreboard_players_left[i][3])
				$scoreboard.find('#s_p_killdeath').text(scoreboard_players_left[i][4])
				$scoreboard.find('#s_p_mvps').text(scoreboard_players_left[i][5])
				$scoreboard.find('#s_p_score').text(scoreboard_players_left[i][6])
				//$scoreboard.find('#s_p_adr').text(scoreboard_players_left[i][7])

				$scoreboard.css('color', 'white')
			}
		}
	}
	if (teams.right.players) {
		for (var i = 0; i < 5; i++) {
			if (i >= teams.right.players.length) {
				let $scoreboard = $(
					'#scoreboard ' + '#s_teams ' + '#s_team2' + ' #s_player' + (i + 1)
				)
				$scoreboard.find('#s_p_nickname').text('UNCONNECTED')

				$scoreboard.css('color', 'rgb(169,169,169)')
			} else {
				let $scoreboard = $(
					'#scoreboard ' + '#s_teams ' + '#s_team2' + ' #s_player' + (i + 1)
				)

				$scoreboard.find('#s_p_nickname').text(scoreboard_players_right[i][0])
				$scoreboard.find('#s_p_kills').text(scoreboard_players_right[i][1])
				$scoreboard.find('#s_p_assists').text(scoreboard_players_right[i][2])
				$scoreboard.find('#s_p_deaths').text(scoreboard_players_right[i][3])
				$scoreboard.find('#s_p_killdeath').text(scoreboard_players_right[i][4])
				$scoreboard.find('#s_p_mvps').text(scoreboard_players_right[i][5])
				$scoreboard.find('#s_p_score').text(scoreboard_players_right[i][6])

				$scoreboard.css('color', 'white')
			}
		}
	}
}

function updateStateWarmup(phase) {
	if (phase) {
		forceRemoveAlerts()
		for (let x = 1; x <= 5; x++) {
			$(
				'#players_left #player_section #player' + x + ' .player_stats_holder'
			).css('opacity', 0)
			$(
				'#players_right #player_section #player' + x + ' .player_stats_holder'
			).css('opacity', 0)
		}
		if (!$('#round_timer_text').hasClass('round_warmup'))
			animateRoundTimer('round_warmup', true)
	}
}

function updateStateFreezetime(phase, previously) {
	if (phase) {
		removeRoundTimeGraphics()
		resetBomb()
		showPlayerStats(phase)
		$('#players_left #box_utility').slideDown(500)
		$('#players_right #box_utility').slideDown(500)
		$('#players_left #box_monetary').slideDown(500)
		$('#players_right #box_monetary').slideDown(500)
		$('.loss_bonus_left').slideDown(500)
		$('.loss_bonus_right').slideDown(500)
		$('.pick_map_match').slideDown(500)
		$('#pick_map_team0').slideDown(500)
		//$('#pick_map_match').addClass('fadeInDown')
		$('.left_value').slideDown(500)
		$('.right_value').slideDown(500)
		$('.player_stats2').css('opacity', 1)
		$('.player_stats3').css('opacity', 1)
		//$('#player_counter').slideUp(500)
		//$('#pick_map_team0').slideDown(500)
		//$('#pick_map_team1').slideDown(500)
		//$('#pick_map_team2').slideDown(500)
		//$('#decider').slideDown(500)
		$('#freezetime_hud').slideDown(500)
		//$('#round_history').slideDown(80)
		//$('#round_history_panel').slideDown(500)
		$('#round_timer_text').css('color', COLOR_GRAY)
		if (previously.hasOwnProperty('round')) {
			if (previously.round.hasOwnProperty('win_team')) {
				if (previously.round.win_team == 'CT') {
					if (teams.left.side == 'ct') {
						// * CT alert on Left
						hideAlertSlide('#left_team')
					} else {
						// * CT alert on Right
						hideAlertSlide('#right_team')
					}
				} else if (previously.round.win_team == 'T') {
					if (teams.left.side == 't') {
						// * T alert on Left
						hideAlertSlide('#left_team')
					} else {
						// * T alert on Right
						hideAlertSlide('#right_team')
					}
				}
			}
		} else if (checkPrev(previously, 'paused')) {
			$('#alert_middle').removeClass()
			animateElement('#alert_middle', 'fadeOutDown', function () {
				$('#alert_middle').css('opacity', 0).removeClass()
			})
			$('#pause').removeClass()
			animateElement('#pause', 'fadeOutDown', function () {
				$('#pause').css('opacity', 0).removeClass()
			})
		} else if (
			checkPrev(previously, 'timeout_t') ||
			checkPrev(previously, 'timeout_ct')
		) {
			$('#alert_middle').removeClass()
			animateElement('#alert_middle', 'fadeOutDown', function () {
				$('#alert_middle').css('opacity', 0).removeClass()
			})
			$('#pause').removeClass()
			animateElement('#pause', 'fadeOutDown', function () {
				$('#pause').css('opacity', 0).removeClass()
			})
			hideAlert('#left_team')
			hideAlert('#right_team')
		}
		if (phase.phase_ends_in) {
			var clock_time = Math.abs(Math.ceil(phase.phase_ends_in))
			var count_minute = Math.floor(clock_time / 60)
			var count_seconds = clock_time - count_minute * 60
			if (count_seconds < 10) {
				count_seconds = '0' + count_seconds
			}
			$('#round_timer_text').text(count_minute + ':' + count_seconds)
		}
	}
}

function updateStateOver(phase, map, round, previously) {
	if (phase) {
		round_now =
			map.round +
			(round.phase == 'over' || round.phase == 'intermission' ? 0 : 1)
		if (_displayScoreboard) {
			if (round_now % 8 === 0) {
				toggleScoreboard(true)
			}
		}

		$('#round_timer_text').css('color', COLOR_GRAY)
		//#region Which Team Won
		if (round.win_team == 'CT') {
			if (teams.left.side == 'ct') {
				// * CT alert on Left
				showAlertSlide('#left_team', COLOR_NEW_CT, 'WINS THE ROUND')
				$('#left_team #logo #team_logo').addClass('animated fadeIn')
			} else {
				// * CT alert on Right
				showAlertSlide('#right_team', COLOR_NEW_CT, 'WINS THE ROUND')
				$('#right_team #logo #team_logo').addClass('animated fadeIn')
			}
		} else if (round.win_team == 'T') {
			if (teams.left.side == 't') {
				// * T alert on Left
				showAlertSlide('#left_team', COLOR_NEW_T, 'WINS THE ROUND')
				$('#left_team #logo #team_logo').addClass('animated fadeIn')
				if (checkPrev(previously, 'defuse')) {
					$('#right_team #alert').css('opacity', 0).removeClass()
				}
			} else {
				// * T alert on Right
				showAlertSlide('#right_team', COLOR_NEW_T, 'WINS THE ROUND')
				$('#right_team #logo #team_logo').addClass('animated fadeIn')
				if (checkPrev(previously, 'defuse')) {
					$('#left_team #alert').css('opacity', 0).removeClass()
				}
			}
		}
		//#endregion
		resetBomb()
		if (round.bomb == null) {
			if (round.win_team == 'T') {
				if (checkPrev(previously, 'live') || checkPrev(previously, 'bomb')) {
					if ($('#round_timer_text').hasClass('animated'))
						$('#round_timer_text').removeClass('animated')
					if ($('#round_timer_text').hasClass('flash'))
						$('#round_timer_text').removeClass('flash')
					animateRoundTimer('players_eliminated_T', false)
				}
			} else if (round.win_team == 'CT') {
				//var t_alive = checkAliveTerrorists(team_t.players);
				var t_alive = checkAliveTerrorists(
					teams.left.side == 't' ? teams.left.players : teams.right.players
				)
				if (checkPrev(previously, 'live'))
					if (t_alive) {
						// * CT RUN OUT THE CLOCK
						if (!$('#round_timer_text').hasClass('players_eliminated_CT')) {
							if ($('#round_timer_text').hasClass('animated'))
								$('#round_timer_text').removeClass('animated')
							if ($('#round_timer_text').hasClass('flash'))
								$('#round_timer_text').removeClass('flash')
							animateRoundTimer('round_time_reached', false)
						}
					} else if (!t_alive) {
						// * CT ELIMINATE T
						animateRoundTimer('players_eliminated_CT', false)
					}
			}
		} else if (round.bomb == 'planted') {
			if (checkPrev(previously, 'live'))
				animateRoundTimer('players_eliminated_T', false)
			if (checkPrev(previously, 'defuse')) {
				if ($('#round_timer_text').hasClass('animated'))
					$('#round_timer_text').removeClass('animated')
				if ($('#round_timer_text').hasClass('flash'))
					$('#round_timer_text').removeClass('flash')
				animateRoundTimer('players_eliminated_T', false)
			}
		} else if (round.bomb == 'exploded') {
			if (checkPrev(previously, 'bomb')) {
				if ($('#round_timer_text').hasClass('animated'))
					$('#round_timer_text').removeClass('animated')
				if ($('#round_timer_text').hasClass('flash'))
					$('#round_timer_text').removeClass('flash')
				animateRoundTimer('bomb_exploded', true)
				$('#round_timer_text')
					.css('animation-duration', '0.25s')
					.css('animation-iteration-count', '1')
			}
		} else if (round.bomb == 'defused') {
			if (checkPrev(previously, 'defuse')) {
				let _side = teams.left.side == 'ct' ? '#left_team' : '#right_team'
				animateElement(_side + ' #alert #alert_text', 'flash', function () {
					$(_side + ' #alert #alert_text').removeClass('animated flash')
				})
				animateRoundTimer('bomb_defused', true)
				$('#timers #defuse_bar').css('opacity', 0)
				$('#timers2 #defuse_bar2').css('opacity', 0)
				/*$('#left_container').css('opacity', 0)
				$('#bomb_bar2').css('opacity', 0)*/
				$('#left_team #bomb_defuse #icon').css('opacity', 0)
				$('#left_team #bomb_defuse #kit_bar').css('opacity', 0)
				$('#right_team #bomb_defuse #icon').css('opacity', 0)
				$('#right_team #bomb_defuse #kit_bar').css('opacity', 0)
			}
		}
	}
}

function updateStatePlanted(phase, round, previously) {
	if (phase) {
		if (round.bomb == 'planted') {
			if (checkPrev(previously, 'live')) {
				$('#players_left #box_utility').slideDown(500)
				$('#players_right #box_utility').slideDown(500)
			}
			if (checkPrev(previously, 'defuse')) {
				// Fake Defuse or killed
				let defuse_side = teams.left.side == 'ct' ? '#left_team' : '#right_team'
				hideAlertSlide(defuse_side)
			}
			if (phase.phase_ends_in <= 35) {
				$('#players_left #box_utility').slideUp(500)
				$('#players_right #box_utility').slideUp(500)
			}
			if (checkPrev(previously, 'live')) {
				let side = teams.left.side == 't' ? '#left_team' : '#right_team'
				hideAlertSlide(side)
				if ($('#round_timer_text').hasClass('animated'))
					$('#round_timer_text').removeClass('animated')
				if ($('#round_timer_text').hasClass('flash'))
					$('#round_timer_text').removeClass('flash')
				animateRoundTimer('bomb_active', false)
				/*showMiddleAlert(COLOR_NEW_T, COLOR_NEW_T, 'BOMB PLANTED', COLOR_NEW_T)
				var wait = setTimeout(function () {
					$('#alert_middle')
						.css('opacity', 0)
						.removeClass('animated fadeOutDown')
				}, 5000)*/
			}
			if (phase.phase_ends_in <= 2) {
				$('#round_timer_text')
					.css('animation-duration', '0.5s')
					.css('animation-iteration-count', 'infinite')
			} else if (phase.phase_ends_in <= 5) {
				$('#round_timer_text')
					.css('animation-duration', '1s')
					.css('animation-iteration-count', 'infinite')
			} else if (phase.phase_ends_in <= 10) {
				$('#round_timer_text')
					.addClass('animated flash')
					.css('animation-duration', '2s')
					.css('animation-iteration-count', 'infinite')
			}
			bomb(parseFloat(phase.phase_ends_in))
			$('#timers #defuse_bar').css('opacity', 0)
			$('#timers2 #defuse_bar2').css('opacity', 0)
			$('#left_team #bomb_defuse #icon').css('opacity', 0)
			$('#left_team #bomb_defuse #kit_bar').css('opacity', 0)
			$('#right_team #bomb_defuse #icon').css('opacity', 0)
			$('#right_team #bomb_defuse #kit_bar').css('opacity', 0)
		}
	}
}

//разминирование
function updateStateDefuse(phase, bomb, players) {
	if (phase) {

		$("#timers #timers2").css("color", (phase.phase == "live" || phase.phase == "over" || phase.phase == "warmup" || (phase.phase == "freezetime" && phase.phase_ends_in > 10))
            ? "white"
            : "red");
        if(teams.right.side == "ct"){
            $("#right_container").css("display", phase.phase == "defuse"
            ? "block"
            : "none");
        }
        else {
            $("#left_container").css("display", phase.phase == "defuse"
            ? "block"
            : "none");
        }
				if (phase.phase == 'defuse') {
			let side = teams.left.side == 't' ? '#left_team' : '#right_team'
			if (!isDefusing) {
				// * Checks for Kit ONCE
				if (parseFloat(phase.phase_ends_in) > 5) {
					defuse_seconds = 10
					divider = 1
					hasKit = false
				} else {
					defuse_seconds = 5
					divider = 2
					hasKit = true
				}
				isDefusing = true
			}
			var defuse_timer_css = {
				opacity: 1,
				width:
					(181 / divider) * (parseFloat(phase.phase_ends_in) / defuse_seconds) +  //25
					'%',
			}
			var defuse_timer_css2 = {
				opacity: 1,
				width:
					(110 / divider) * (parseFloat(phase.phase_ends_in) / defuse_seconds) +  //25
					'%',
			}
			let defusing_side = teams.right.side == 't' ? '#left_team' : '#right_team'
			$(defusing_side + ' #bomb_defuse #icon').css('opacity', hasKit ? 1 : 0)
			$(defusing_side + ' #bomb_defuse #kit_bar')
				.css('background-color', COLOR_NEW_CT)
				.css('opacity', hasKit ? 1 : 0)
			$('#timers #defuse_bar').css(defuse_timer_css)
			$('#timers2 #defuse_bar2').css(defuse_timer_css2)
			$('#defuse_bar2').css("float", "right")
			
			if (bomb != null) {
				if (bomb.state == 'defusing') {
					player = bomb.player
					players.forEach(function (_player) {
						if (_player.steamid == player) {
							defuser = _player
						}
					})
					// 13 characters for name
					showAlertSlide(
						defusing_side,
						COLOR_NEW_CT,
						defuser.name + ' defuse bomb'
					)
				}
			}
		}
	}
}

function updateStateLive(phase, bomb, players, previously) {
	if (phase) {
		if (_displayScoreboard) {
			toggleScoreboard(false)
		}
		removeRoundTimeGraphics()
		forceRemoveAlerts()
		resetBomb()
		hidePlayerStats(phase, previously)
		if (checkPrev(previously, 'freezetime')) {
			$('#players_left #box_monetary').slideUp(500)
			$('#players_right #box_monetary').slideUp(500)
			$('.loss_bonus_left').slideUp(500)
			$('.loss_bonus_right').slideUp(500)
			$('.pick_map_match').slideUp(500)
			$('.left_value').slideUp(500)
			$('.right_value').slideUp(20)
			$('.player_stats2').css('opacity', 0)
			$('.player_stats3').css('opacity', 0)
			//$('#player_counter').slideDown(2000)
			//$('#pick_map_team0').slideUp(500)
			//$('#pick_map_team1').slideUp(500)
			//$('#pick_map_team2').slideUp(500)
			//$('#decider').slideUp(500)
			$('#freezetime_hud').slideUp(500)
			//$('#round_history').slideUp(80)
			//$('#round_history_panel').slideUp(500)
			//$('#left_team #main').slideUp(500)
		}
		if (phase.phase_ends_in <= 109.9) {
			$('#players_left #box_utility').slideUp(500)
			$('#players_right #box_utility').slideUp(500)
		}
		if (phase.phase_ends_in <= 5) {
			$('#round_timer_text')
				.addClass('animated flash')
				.css('animation-duration', '2s')
				.css('animation-iteration-count', 'infinite')
		}
		$('#round_timer_text').css(
			'color',
			phase.phase_ends_in <= 10 ? COLOR_RED : COLOR_WHITE
		)
		if (phase.phase_ends_in) {
			var clock_time = Math.abs(Math.ceil(phase.phase_ends_in))
			var count_minute = Math.floor(clock_time / 60)
			var count_seconds = clock_time - count_minute * 60
			if (count_seconds < 10) {
				count_seconds = '0' + count_seconds
			}
			$('#round_timer_text').text(count_minute + ':' + count_seconds)
		}
		if (bomb != null) {
			if (bomb.state == 'planting') {
				let side = teams.left.side == 't' ? '#left_team' : '#right_team'
				player = bomb.player
				players.forEach(function (_player) {
					if (_player.steamid == player) {
						planter = _player
					}
				})
				// 13 characters for name
				var bufor = planter.name
				if (bufor.length >= 20) {
					bufor = bufor.substring(0, 20) + '...'
				}
				showAlertSlide(side, COLOR_NEW_T, bufor + ' ' + 'planting bomb')
			}
		}
	}
}

function updateStatePaused(phase, type, previously) {
	removeRoundTimeGraphics()
	resetBomb()
	$('#players_left #box_utility').slideDown(500)
	$('#players_right #box_utility').slideDown(500)
	$('#alert_middle #alert_text_middle #pole_1_middle_img').css(
		'background-image',
		'url(/files/img/elements/timer2.png)'
	)
	$('#alert_middle').removeClass()
	$('#pause').removeClass()
	if (type == 'paused') {
		if (
			checkPrev(previously, 'freezetime') ||
			checkPrev(previously, 'live') ||
			checkPrev(previously, 'defuse') ||
			checkPrev(previously, 'bomb')
		)
			animateRoundTimer('pause_active', false)
		$('#alert_middle #pole_1_middle').css(
			'background-color',
			teams.left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
		)
		$('#alert_middle #pole_2_middle').css(
			'background-color',
			teams.right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
		)
		$('#alert_middle #alert_text_middle #alert_text_middle_2')
			.text('MATCH PAUSED')
			.css('color', COLOR_WHITE)
		$('#pause')
			.text('MATCH PAUSED')
			.css('color', COLOR_WHITE)
	} else if (type == 'timeout_t') {
		if (phase.phase_ends_in) {
			var clock_time = Math.abs(Math.ceil(phase.phase_ends_in))
			var count_minute = Math.floor(clock_time / 60)
			var count_seconds = clock_time - count_minute * 60
			if (count_seconds < 10) {
				count_seconds = '0' + count_seconds
			}
			$('#round_timer_text')
				.text(count_minute + ':' + count_seconds)
				.css('color', COLOR_NEW_T)
		}
		$('#alert_middle #pole_1_middle').css('background-color', COLOR_NEW_T)
		$('#alert_middle #pole_2_middle').css('background-color', COLOR_NEW_T)
		$('#alert_middle #alert_text_middle_2_middle').css(
			'background-color',
			COLOR_NEW_T
		)
		$('#alert_middle #alert_text_middle #pole_1_middle_img').css(
			'background-image',
			'url(/files/img/elements/icon_timer_default.png)'
		)
		/*$('#alert_middle #alert_text_middle #alert_text_middle_2') //оригинал тайм аутов
			.text(
				teams.left.side == 't'
					? ' TIMEOUT: ' +
							'' +
							teams.left.short_name.toUpperCase() +
							' use:' +
							' ' +
							teams.left.timeouts_remaining +
							''
					: ' TIMEOUT: ' +
							'' +
							teams.right.short_name.toUpperCase() +
							' use:' +
							' ' +
							teams.right.timeouts_remaining +
							''
			)
			.css('color', COLOR_NEW_T)*/

			$('#alert_middle #alert_text_middle #alert_text_middle_2')
			.text(
				teams.left.side == 't'
					? ' TIMEOUT: '
					: ' TIMEOUT: '
			)
			.css('color', COLOR_NEW_T)

			$('#alert_text_middle_2_2')
			.text(
				teams.left.side == 't'
					? teams.left.short_name.toUpperCase()
					: teams.right.short_name.toUpperCase()
			)
			.css('color', COLOR_NEW_T)

			$('#alert_text_middle_2_3')
			.text(
				teams.left.side == 't'
					? ' use:' +
							'' +
							teams.left.timeouts_remaining +
							'/4'
					: ' use:' +
							'' +
							teams.right.timeouts_remaining +
							'/4'
			)
			.css('color', COLOR_NEW_T)

		/* отображение количества timeout*/
		/*showAlertSlide(
			'#left_team',
			teams.left.side == 't' ? COLOR_NEW_T : COLOR_NEW_CT,
			'Timeouts Remaining: ' + teams.left.timeouts_remaining
		)
		showAlertSlide(
			'#right_team',
			teams.right.side == 't' ? COLOR_NEW_T : COLOR_NEW_CT,
			'Timeouts Remaining: ' + teams.right.timeouts_remaining
		)*/
	} else if (type == 'timeout_ct') {
		if (phase.phase_ends_in) {
			var clock_time = Math.abs(Math.ceil(phase.phase_ends_in))
			var count_minute = Math.floor(clock_time / 60)
			var count_seconds = clock_time - count_minute * 60
			if (count_seconds < 10) {
				count_seconds = '0' + count_seconds
			}
			$('#round_timer_text')
				.text(count_minute + ':' + count_seconds)
				.css('color', COLOR_NEW_CT)
		}
		$('#alert_middle #pole_1_middle').css('background-color', COLOR_NEW_CT)
		$('#alert_middle #pole_2_middle').css('background-color', COLOR_NEW_CT)
		$('#alert_middle #alert_text_middle #pole_1_middle_img').css(
			'background-image',
			'url(/files/img/elements/icon_timer_default.png)'
		)
		$('#alert_middle #pole_2_middle').css('background-color', COLOR_NEW_CT)
		/*$('#alert_middle #alert_text_middle #alert_text_middle_2') // оригинал информации об таймаутах
			.text(
				teams.left.side == 'ct'
					? ' TIMEOUT: ' +
							'' +
							teams.left.short_name.toUpperCase() +
							' | use:' +
							' ' +
							teams.left.timeouts_remaining +
							'/4'
					: ' TIMEOUT2: ' +
							'' +
							teams.right.short_name.toUpperCase() +
							' | use:' +
							' ' +
							teams.right.timeouts_remaining +
							'/4'
			)*/
			$('#alert_middle #alert_text_middle #alert_text_middle_2')
			.text(
				teams.left.side == 'ct'
					? ' TIMEOUT: '
					: ' TIMEOUT: '
			)
			.css('color', COLOR_NEW_CT)
//название команды
			$('#alert_text_middle_2_2')
			.text(
				teams.left.side == 'ct'
					? teams.left.short_name.toUpperCase()
					: teams.right.short_name.toUpperCase()
			)
			.css('color', COLOR_NEW_CT)
//заюзанных перерывов
			$('#alert_text_middle_2_3')
			.text(
				teams.left.side == 'ct'
					? ' use:' + 
					teams.left.timeouts_remaining +
					'/4'
					: ' use:' + 
					teams.right.timeouts_remaining +
					'/4'
			)
			.css('color', COLOR_NEW_CT)

		/* отображение количества timeout*/
		/*showAlertSlide(
			'#left_team',
			teams.left.side == 't' ? COLOR_NEW_T : COLOR_NEW_CT,
			'Timeouts Remaining: ' + teams.left.timeouts_remaining
		)
		showAlertSlide(
			'#right_team',
			teams.right.side == 't' ? COLOR_NEW_T : COLOR_NEW_CT,
			'Timeouts Remaining: ' + teams.right.timeouts_remaining
		)*/
	}

	$('#alert_middle').css('opacity', 1).addClass('animated fadeInUp')
	$('#pause').css('opacity', 1).addClass('animated fadeInUp')
}

function updateObserved(observed) {
	if (observed && observed.steamid != 1 && observed.getStats()) {
		$('#observed').css('opacity', 1)
		fillObserved(observed)
	} else {
		$('#observed').css('opacity', 0)
	}
}

function fillObserved(obs) {
	let stats = obs.getStats()
	let weapons = obs.weapons
	team_color = obs.team == 'CT' ? COLOR_NEW_CT : COLOR_NEW_T

	/* // загрузка авки из стим
	loadAvatar(obs.steamid, function () {
		$('#obs_img').attr('src', '/files/avatars/' + obs.steamid + '.png')
	})
*/
	//#region Poles
	$('#obs_lane3_left_pole').css('background-color', team_color)
	$('#obs_lane3_right_pole').css('background-color', team_color)
	//#endregion
	var bufor = obs.name
	if (bufor.length >= 13) {
		bufor = bufor.substring(0, 13) + '...'
	}
	$('#obs_alias_text').text(bufor/*.toUpperCase()*/)
	$('#obs_alias_text').css('color', COLOR_WHITE/*team_color*/)
	if (obs.real_name && obs.real_name != obs.name) {
		$('#obs_realname_text').text(obs.real_name)
	} else {
		$('#obs_realname_text').text('')
	}

	// Logic for Team Image
	if (obs.team == 'CT') {
		if (teams.left.side == 'ct') {
			_img = teams.left.logo
		} else {
			_img = teams.right.logo
		}
	} else if (obs.team == 'T') {
		if (teams.left.side == 't') {
			_img = teams.left.logo
		} else {
			_img = teams.right.logo
		}
	}

	if (disp_avatars) {
		if (disp_player_avatars) {
			if (obs.hasOwnProperty('avatar')) {
				// Custom Set Avatar
				if (obs.avatar) $('#obs_img').attr('src', '/storage/' + obs.avatar)
			} else {
				// Just Use Team Logo
				$('#obs_img').attr('src', '/storage/' + _img)
				//$('#obs_img').attr('src', '/files/avatars/' + obs.steamid + '.png')
			}
		} else {
			loadAvatar(obs.steamid, function () {
				$('#obs_img').attr('src', '/av/' + obs.steamid)
			})
		}
	} else {
		$('#obs_avatar').css('opacity', 0)
	}

	// Team Logo and Flags
	$('#obs_team_img').attr('src', '/storage/' + _img)
	/*$('#team_3').attr('src', '/storage/' + _img)*/

	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	if (disp_player_flags) {
		if (obs.hasOwnProperty('teamData')) {
			if (obs.teamData.hasOwnProperty('country_code')) {
				$('#obs_country_img').attr(
					'src',
					'/files/img/flags-50/' + obs.country_code + '.png'
				)
				$('#obs_country_img').css('opacity', 1)
			} else {
				$('#obs_country_img').css('opacity', 0)
			}
		} else {
			$('#obs_country_img').css('opacity', 0)
		}
	} else {
		$('#obs_country_img').css('opacity', 0)
	}

	$('#obs_health_text').text(stats.health)
	$('#obs_health_img').removeClass()
	if (stats.health <= 20) {
		$('#obs_health_img').addClass('health_' + obs.team)
		$('#obs_health_text').css('color', COLOR_RED)
	} else if (stats.health > 20) {
		$('#obs_health_img').addClass('health_full_' + obs.team)
		$('#obs_health_text').css('color', COLOR_WHITE)
	}

	$('#obs_armor_text').text(stats.armor)
	$('#obs_armor_img').removeClass()
	if (stats.helmet) {
		if (stats.armor == 0) {
			$('#obs_armor_img').addClass('armor_none_' + obs.team)
		} else if (stats.armor <= 30) {
			$('#obs_armor_img').addClass('armor_half_helm_' + obs.team)
		} else if (stats.armor <= 100) {
			$('#obs_armor_img').addClass('armor_helm_' + obs.team)
		}
	} else {
		if (stats.armor == 0) {
			$('#obs_armor_img').addClass('armor_none_' + obs.team)
		} else if (stats.armor <= 30) {
			$('#obs_armor_img').addClass('armor_half_' + obs.team)
		} else if (stats.armor <= 100) {
			$('#obs_armor_img').addClass('armor_kev_' + obs.team)
		}
	}

	$('#obs_kills_k').css('color', team_color)
	$('#obs_kills_text').text(stats.kills)
	$('#obs_assists_a').css('color', team_color)
	$('#obs_assists_text').text(stats.assists)
	$('#obs_deaths_d').css('color', team_color)
	$('#obs_deaths_text').text(stats.deaths)
	$('#obs_kd_kd').css('color', team_color)
		if (stats.deaths == 0) {
			$('#obs_kd_text').text(stats.kills.toFixed(1))
		} else {
			$('#obs_kd_text').text(Math.floor((stats.kills / stats.deaths).toFixed(2) * 100) / 100)
		}

	//$('#obs_adr_text').text(Math.round((stats.adr[player.steamid] || 0)))
		//Math.round((adr[player.steamid] || 0)
	//$('#obs_rt_rt').css('color', team_color)
	//$('#obs_rt_text').text(Math.floor(stats.round_totaldmg / 1,2 * round_now))
	//$('#obs_rt_text').text(Math.round((adr[player.steamid])))
	//$('#obs_rt_text').text(stats.round_totaldmg)
	//$('#DMG_round_text').text(stats.round_totaldmg)
	//$('#obs_adr_text').text(stats.demage)

	$('#obs_reserve').css('color', team_color)

	$('#obs_nade1').removeClass()
	$('#obs_nade2').removeClass()
	$('#obs_nade3').removeClass()
	$('#obs_nade4').removeClass()
	$('#obs_bomb_kit').removeClass()
	$('#obs_bullets_section').removeClass()
	$('#obs_bullets_section').addClass('bullets_' + obs.team)

	let grenades_list = []
	for (let key in weapons) {
		let weapon = weapons[key]
		if (weapon.type == 'Grenade') {
			for (let x = 0; x < weapon.ammo_reserve; x++) {
				grenades_list.push(weapon.name)
			}
		}
		if (weapon.type == 'C4') {
			$('#obs_bomb_kit').addClass('obs_bomb')
		}
		if (weapon.state == 'active' || weapon.state == 'reloading') {
			if (
				weapon.type == 'Grenade' ||
				weapon.type == 'C4' ||
				weapon.type == 'Knife' ||
				stats.health == 0
			) {
				$('#obs_clip').css('color', COLOR_WHITE)
				$('#obs_clip').text('-')
				$('#obs_reserve').text('/-')
			} else {
				$('#obs_clip').text(weapon.ammo_clip)
				if (weapon.ammo_clip <= 3) {
					$('#obs_clip').css('color', COLOR_RED)
				} else {
					$('#obs_clip').css('color', COLOR_WHITE)
				}
				$('#obs_reserve').text('/' + weapon.ammo_reserve)
			}
		}
	}
	for (let x = 0; x < grenades_list.length; x++) {
		$('#obs_nade' + (x + 1)).addClass('nade_' + grenades_list[x].substr(7))
	}

	if (stats.defusekit) {
		$('#obs_bomb_kit').addClass('obs_kit')
	}

	skull_color = obs.team == 'CT' ? 'CT' : 'T'
	$('#obs_round_kills #obs_skull').removeClass()
	if (stats.round_kills > 0) {
		$('#obs_round_kills #obs_skull').addClass('obs_skull_' + skull_color)
		$('#obs_round_kills #obs_round_kills_text').text(stats.round_kills)
	} else {
		$('#obs_round_kills #obs_round_kills_text').text('')
	}
}

function updatePlayers(players, observed, phase, previously) {
	if (players) {
		fillPlayers(teams, observed, phase, previously)
	}
}

function fillPlayers(teams, observed, phase, previously) {
	if (teams.left.players) {
		for (var i = 0; i < 5; i++) {
			if (i >= teams.left.players.length) {
				$('#players_left #player_section')
					.find('#player' + (i + 1))
					.css('opacity', '0')
			} else {
				fillPlayer(
					teams.left.players[i],
					i,
					'players_left',
					observed,
					phase,
					previously
				)
				$('#players_left #player_section')
					.find('#player' + (i + 1))
					.css('opacity', '1')
			}
		}
	}
	if (teams.right.players) {
		for (var i = 0; i < 5; i++) {
			if (i >= teams.right.players.length) {
				$('#players_right #player_section')
					.find('#player' + (i + 1))
					.css('opacity', '0')
			} else {
				fillPlayer(
					teams.right.players[i],
					i,
					'players_right',
					observed,
					phase,
					previously
				)
				$('#players_right #player_section')
					.find('#player' + (i + 1))
					.css('opacity', '1')
			}
		}
	}
}

function fillPlayer(player, nr, side, observed, phase, previously) {
	let slot = player.observer_slot
	let stats = player.getStats()
	let weapons = player.getWeapons()
	let steamid = player.steamid
	let team = player.team.toLowerCase()
	let obs_slot = observed.observer_slot
	let dead = stats.health == 0
	let health_color =
		stats.health <= 20 ? COLOR_RED : team == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	let alt_health_color =
		stats.health <= 20 ? COLOR_RED : team == 'ct' ? COLOR_CT : COLOR_T
	let side_color = team == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T

	let $player = $('#live_page ' + '#' + side).find('#player' + (nr + 1))

	$player
		.find('.player_side_bar')
		.css('background-color', dead ? COLOR_MAIN_PANEL : side_color)

	//let $top = $player.find('.player_section_top')
	let $top = $player.find('.player_section_top').css('width', '325px')
	let $top2 = $player.find('.player_section_top2').css('width', '70px')
	let $top3 = $player.find('.player_section_top3').css('width', '70px')
	let $bottom = $player.find('.player_section_bottom').css('width', '325px', 'left', '129.6px')
	let $bottom2 = $player.find('.player_section_bottom2').css('width', '30px', 'left', '129.6px')
	let $bottom3 = $player.find('.player_section_bottom3').css('width', '30px', 'right', '129.6px')
	//let $bottom = $player.find('.player_section_bottom').css('left', '129.6px')
	let $kda_money = $player.find('.player_stats_holder')
	let $kda_money2 = $player.find('.player_kda_stile_esl')
	let $kda_money3 = $player.find('.player_kda_stile_esl2')
	let $kda_money4 = $player.find('.player_stats2')
	let $kda_money5 = $player.find('.player_stats3')


	// avatars 

//оригинал
/*
$player.find("#player_image").removeClass("dead");
if (disp_player_avatars) {
  if (player.hasOwnProperty("avatar")) {
	// Custom Set Avatar
	if (player.avatar)
	  $player
		.find("#player_image")
		.attr("src", "/storage/" + player.avatar)
		.addClass(dead ? "dead" : "");
  } else {
	// Just Use Team Logo
	if (team == "ct") {
	  if (teams.left.side == "ct") {
		_img = teams.left.logo;
	  } else {
		_img = teams.right.logo;
	  }
	} else if (team == "t") {
	  if (teams.left.side == "t") {
		_img = teams.left.logo;
	  } else {
		_img = teams.right.logo;
	  }
	}
	$player
	  .find("#player_image")
	  .attr("src", "/storage/" + _img)
	  .addClass(dead ? "dead" : "");
  }
} else {
  loadAvatar(steamid, function () {
	$player
	  .find("#player_image")
	  .attr("src", "/av/" + steamid)
	  .addClass(dead ? "dead" : "");
  });
}*/
	
//не оригинал

	$player.find('#player_image').removeClass('dead')
	if (disp_player_avatars) {
		if (player.hasOwnProperty('avatar')) {
			// Custom Set Avatar
			if (player.avatar)
				$player
					.find('#player_image')
					.attr('src', '/storage/' + player.avatar) //Фотографии игроков
					//.attr('src', '/av/' + steamid) //аватарки из стим
					.addClass(dead ? 'dead' : '')
		
		} else {
			// Аватарки из лого команды // Just Use Team Logo
			if (team == "ct") {
			  if (teams.left.side == "ct") {
				_img = teams.left.logo;
			  } else {
				_img = teams.right.logo;
			  }
			} else if (team == "t") {
			  if (teams.left.side == "t") {
				_img = teams.left.logo;
			  } else {
				_img = teams.right.logo;
			  }
			}

			// авки из стим за место лого команды для ESEA
			$player
				.find('#player_image')
				//.attr('src', '/storage/' + player.avatar) //Фотографии игроков
				.attr('src', '/av/' + steamid) //аватарки из стим
				.addClass(dead ? 'dead' : '')
		}
  } /*else {
		// авки из стим за место лого команды для ESEA
		loadAvatar(steamid, function () {
			$player
				.find('#player_image')
				//.attr('src', '/storage/' + player.avatar) //Фотографии игроков
				.attr('src', '/av/' + steamid) //аватарки из стим
				.addClass(dead ? 'dead' : '')
		})
	}*/

	//  scoreboard

	if (side == 'players_left') {
		scoreboard_players_left[nr][0] = player.name.toUpperCase()
		scoreboard_players_left[nr][1] = stats.kills
		scoreboard_players_left[nr][2] = stats.assists
		scoreboard_players_left[nr][3] = stats.deaths
		if (stats.deaths == 0) {
			scoreboard_players_left[nr][4] = stats.kills.toFixed(1)
		} else {
			scoreboard_players_left[nr][4] = (stats.kills / stats.deaths).toFixed(1)
		}
		scoreboard_players_left[nr][5] = stats.mvps
		scoreboard_players_left[nr][6] = stats.score
		//scoreboard_players_left[nr][7] = stats.damage
	} else {
		scoreboard_players_right[nr][0] = player.name.toUpperCase()
		scoreboard_players_right[nr][1] = stats.kills
		scoreboard_players_right[nr][2] = stats.assists
		scoreboard_players_right[nr][3] = stats.deaths
		if (stats.deaths == 0) {
			scoreboard_players_right[nr][4] = stats.kills.toFixed(1)
		} else {
			scoreboard_players_right[nr][4] = (stats.kills / stats.deaths).toFixed(1)
		}
		scoreboard_players_right[nr][5] = stats.mvps
		scoreboard_players_right[nr][6] = stats.score
	}

	$top
		.find('#player_alias_text')
		.css('color', dead ? COLOR_WHITE_HALF : COLOR_WHITE)

		$top
		.find('#DMG_round')
		.css('color', dead ? COLOR_WHITE_HALF : COLOR_WHITE)

	if (slot >= 1 && slot <= 5) {
		$top.find('#player_alias_text').text(player.name/*.toUpperCase()*/)
	} else {
		if (slot == 10) {
			$top.find('#player_alias_text').text(player.name/*.toUpperCase()*/)
		} else {
			$top.find('#player_alias_text').text(player.name/*.toUpperCase()*/)
		}
	}

	$top
		.find('.DMG_round')
		.css('color', dead ? COLOR_WHITE_HALF : COLOR_WHITE)

	$kda_money.find('#player_kills_k').css('color', side_color)
	$kda_money.find('#player_kills_text').text(stats.kills)
	$kda_money2.find('#player_kills_text2').text(stats.kills)
	$kda_money3.find('#player_kills_text3').text(stats.kills) 
	$player.find('#player_dead_kills_text').text(stats.kills)
	$player.find('#player_dead_kills_text').text(stats.kills)
	$player.find('#DMG_round_text').text(stats.round_totaldmg)
	$player.find('#DMG_round_text2').text(stats.round_totaldmg)
	//$player.find('#ADR_m_text2').text(Math.floor((round_totaldmg / round).toFixed(2) * 100) / 100)
	//$player.find('#KD_team_text2').text(Math.floor((stats.kills / stats.deaths).toFixed(2) * 100) / 100)
	//$player.find('#ADR_m_text2').text(stats.damagePrRound)
	/*$kda_money2.find('#player_kills_text_live2').text(stats.kills)*/
	$player.find('#player_dead_kills_text_live').text(stats.kills)

	$kda_money.find('#player_assists_a').css('color', side_color)
	$kda_money.find('#player_assists_text').text(stats.assists)
	$player.find('#player_dead_assists_text').text(stats.assists)

	$kda_money.find('#player_deaths_d').css('color', side_color)
	$kda_money.find('#player_deaths_text').text(stats.deaths)
	$kda_money2.find('#player_deaths_text2').text(stats.deaths)
	$kda_money3.find('#player_deaths_text3').text(stats.deaths)
	$player.find('#player_dead_deaths_text').text(stats.deaths)
	$player.find('#player_deaths_text_live').text(stats.deaths)
	$player.find('#player_dead_deaths_text_live').text(stats.deaths)

	// отображение игрока после смерти // //width: 1100px;
	if (dead) {
		$bottom.find('#player_bomb_kit_image').css('opacity', 0)
		$bottom2.find('#player_bomb_kit_image2').css('opacity', 0)
		$bottom2.find('#player_bomb_kit_bg').css('opacity', 0)
		$bottom2.find('#player_bomb_kit_bg2').css('opacity', 0)
		$bottom2.find('#player_bomb_kit2').css('opacity', 0)
		$bottom2.find('#player_bomb_kit_image3').css('opacity', 0)
		$bottom3.find('#player_bomb_kit4').css('opacity', 0)
		$bottom3.find('#player_bomb_kit_image3').css('opacity', 0)
		$bottom3.find('.player_bomb_kit_image3_fon').css('opacity', 0)
		$bottom3.find('#player_bomb_kit_bg2').css('opacity', 0)
		$bottom3.find('#player_kit2').css('opacity', 0)
		$bottom.find('#player_armor_image').css('opacity', 0)
		$bottom2.find('#player_armor_image2').css('opacity', 0)
		$bottom3.find('#player_armor_image3').css('opacity', 0)
		$top.find('#player_health_text').css('opacity', 0, )
		$top2.find('#player_health_text2').css('opacity', 0, )
		$top3.find('#player_health_text3').css('opacity', 0, )
		$top.find('#player_health_img').css('opacity', 0)
		$player.find('.player_dead').css('opacity', 1)
		//$player.find('.player_section_top').css('width', '200px')
		//$player.find('.player_section_bottom').css('width', '200px')
		if (side.substr(8) == 'left') {
			$player.find('#player_alias_text').css('left', '0px') //-35
			$player.find('#DMG_round_text2').css('left', '0px') //-35
			$player.find('#player_current_money_text').css('left', '-55px') //-55px
			$player.find('#player_current_money_text').css('top', '0px') //-55px
			$player.find('#player_current_money_text').css('font-size', '12px') //-55px
			$player.find('#player_current_money_text2').css('left', '-55px')
			$player.find('#player_skull').css('left', '0px') //'-55px'
			$player.find('#player_round_kills_text').css('left', '16px') //'-35px'
			$player.find('.player_section_top').css('width', '200px')
			$player.find('.player_section_top2').css('width', '70px')
			$player.find('.player_section_top3').css('width', '70px')
			$player.find('.player_section_bottom').css('width', '200px')
			$player.find('.player_section_bottom2').css('width', '30px')
			$player.find('.player_section_bottom3').css('width', '30px')
					} else if (side.substr(8) == 'right') {
			$player.find('#player_alias_text').css('right', '0px') //-35
			$player.find('#DMG_round_text2').css('right', '0px') //-35
			$player.find('#player_current_money_text').css('left', '-48px') //-55px
			$player.find('#player_current_money_text').css('top', '0px') //-55px
			$player.find('#player_current_money_text').css('font-size', '12px') //-55px
			$player.find('#player_current_money_text2').css('left', '-66px') //65 //'70px'
			$player.find('#player_skull').css('right', '82px') //'-55px'
			$player.find('#player_round_kills_text').css('right', '73px') //'-35px'
			$player.find('.player_section_top').css('width', '200px')
			$player.find('.player_section_top2').css('width', '70px')
			$player.find('.player_section_top3').css('width', '70px')
			$player.find('.player_section_bottom').css('width', '200px')
			$player.find('.player_section_bottom').css('left', '129.6px')
			$player.find('.player_section_bottom2').css('width', '30px')
			$player.find('.player_section_bottom2').css('left', '129.6px')
			$player.find('.player_section_bottom3').css('width', '30px')
			$player.find('.player_section_bottom3').css('left', '0px')
		}
	} else {
		$bottom.find('#player_bomb_kit_image').css('opacity', 1)
		$bottom2.find('#player_bomb_kit_image2').css('opacity', 1)
		$bottom2.find('#player_bomb_kit_bg').css('opacity', 1)
		$bottom2.find('#player_bomb_kit_bg2').css('opacity', 1)
		$bottom2.find('#player_bomb_kit2').css('opacity', 1)
		$bottom2.find('#player_bomb_kit_image3').css('opacity', 1)
		$bottom3.find('#player_bomb_kit4').css('opacity', 1)
		$bottom3.find('#player_bomb_kit_image3').css('opacity', 1)
		/*$bottom3.find('.player_bomb_kit_image3_fon').css('opacity', 1)*/
		$bottom3.find('#player_kit2').css('opacity', 1)
		$bottom3.find('#player_bomb_kit_bg2').css('opacity', 1)
		$bottom.find('#player_armor_image').css('opacity', 1)
		$bottom2.find('#player_armor_image2').css('opacity', 1)
		$bottom3.find('#player_armor_image3').css('opacity', 1)
		$top.find('#player_health_text').css('opacity', 1)
		$top2.find('#player_health_text2').css('opacity', 1)
		$top3.find('#player_health_text3').css('opacity', 1)
		$top.find('#player_health_img').css('opacity', 1)
		$player.find('.player_dead').css('opacity', 0)
				if (side.substr(8) == 'left') {
			$player.find('#player_alias_text').css('left', '0px')
			$player.find('#player_current_money_text').css('left', '1px')
			$player.find('#player_current_money_text').css('top', '0px') //-55px
			$player.find('#player_current_money_text').css('font-size', '15px') //-55px
			$player.find('#player_current_money_text2').css('left', '1px')
			$player.find('#player_skull').css('left', '0px')
			$player.find('#player_round_kills_text').css('left', '16px')
		} else if (side.substr(8) == 'right') {
			$player.find('#player_alias_text').css('right', '0px')
			$player.find('#player_current_money_text').css('left', '7px')
			$player.find('#player_current_money_text').css('top', '0px') //-55px
			$player.find('#player_current_money_text').css('font-size', '15px') //-55px
			$player.find('#player_current_money_text2').css('left', '7px')
			$player.find('#player_skull').css('right', '82px')
			$player.find('#player_round_kills_text').css('right', '73px')
			//$player.find('.player_section_bottom').css('width', '200px')
			$player.find('.player_section_bottom').css('left', '5px')
			$player.find('.player_section_bottom2').css('left', '5px')
			$player.find('.player_section_bottom3').css('left', '0px')
		}
	}

	if (stats.burning > 0 && !dead) {
		$player.find('.burning').css('display', 'block')
		$player.find('#burning_level').addClass('burnt')
		$player.find('#burning_level').css('opacity', stats.burning / 255)
	} else {
		$player.find('#burning_level').removeClass('burnt')
		$player.find('.burning').css('display', 'none')
	}

	if (stats.flashed > 0 && !dead) {
		$player.find('.flashed').css('display', 'block')
		$player.find('#flashed_level').addClass('blind')
		$player.find('#flashed_level').css('opacity', stats.flashed / 255)
	} else {
		$player.find('#flashed_level').removeClass('blind')
		$player.find('.flashed').css('display', 'none')
	}

	if (slot == obs_slot) {
		$player
			.find('#player_spec_bar')
			//.css('background-color', side_color)
			.css('opacity', 1)
	} else {
		$player.find('#player_spec_bar').css('opacity', 0)
	}

	if (slot == obs_slot) {
		$player
			.find('#player_spec_bar2')
			//.css('background-color', side_color)
			.css('opacity', 1)
	} else {
		$player.find('#player_spec_bar2').css('opacity', 0)
	}

	if (slot == obs_slot) {
		$player
			.find('#player_spec_bar_bg')
			//.css('background-color', side_color)
			.css('opacity', 1)
	} else {
		$player.find('#player_spec_bar_bg').css('opacity', 0)
	}

	if (slot == obs_slot) {
		$player
			.find('#player_spec_bar_bg2')
			//.css('background-color', side_color)
			.css('opacity', 1)
	} else {
		$player.find('#player_spec_bar_bg2').css('opacity', 0)
	}

	//let desired = "linear-gradient(to " + side.substr(8) + ", " + health_color + ", " + alt_health_color + ")";
	// ! gradient_double works in browser but not on the overlay
	let gradient_double =
		'linear-gradient(to ' +
		side.substr(8) +
		', rgba(0,0,0,0) ' +
		(100 - stats.health) +
		'%, ' +
		alt_health_color +
		' ' +
		(100 - stats.health) +
		'%)'
	// ! gradient_single works in browser and on the overlay
	//let gradient_single = "linear-gradient(to " + side.substr(8) + ", rgba(0,0,0,0) " + (100 - stats.health) + "%, " + alt_health_color + " " + (100 - stats.health) + "%)";

	$top.find('.player_health_bar').css('background', gradient_double)
	$top.find('#player_health_text').text(stats.health)
	$top2.find('#player_health_text2').text(stats.health)
	$top3.find('#player_health_text3').text(stats.health)
	$top.find('#player_health_img').removeClass()
	if (stats.health < 40) {
		$top.find('#player_health_img').addClass('health_' + team)
	} else if (stats.health > 40) {
		$top.find('#player_health_img').addClass('health_full_' + team)
	}

	let armor_icon = $bottom.find('#player_armor_image')
	armor_icon.removeClass()
	if (stats.helmet) {
		if (stats.armor == 0) {
			armor_icon.addClass('armor_none_default')
		} else if (stats.armor <= 50) {
			armor_icon.addClass('armor_half_helm_default')
		} else if (stats.armor <= 100) {
			armor_icon.addClass('armor_helm_default')
		}
	} else {
		if (stats.armor == 0) {
			armor_icon.addClass('armor_none_default')
		} else if (stats.armor <= 50) {
			armor_icon.addClass('armor_half_default')
		} else if (stats.armor <= 100) {
			armor_icon.addClass('armor_kev_default')
		}
	}

	let armor_icon2 = $bottom2.find('#player_armor_image2')
	armor_icon2.removeClass()
	if (stats.helmet) {
		if (stats.armor == 0) {
			armor_icon2.addClass('armor_none_default')
		} else if (stats.armor <= 50) {
			armor_icon2.addClass('armor_half_helm_default')
		} else if (stats.armor <= 100) {
			armor_icon2.addClass('armor_helm_default')
		}
	} else {
		if (stats.armor == 0) {
			armor_icon2.addClass('armor_none_default')
		} else if (stats.armor <= 50) {
			armor_icon2.addClass('armor_half_helm_default')
		} else if (stats.armor <= 100) {
			armor_icon2.addClass('armor_kev_default')
		}
	}

	let armor_icon3 = $bottom3.find('#player_armor_image3')
	armor_icon3.removeClass()
	if (stats.helmet) {
		if (stats.armor == 0) {
			armor_icon3.addClass('armor_none_default')
		} else if (stats.armor <= 50) {
			armor_icon3.addClass('armor_half_helm_default')
		} else if (stats.armor <= 100) {
			armor_icon3.addClass('armor_helm_default')
		}
	} else {
		if (stats.armor == 0) {
			armor_icon3.addClass('armor_none_default')
		} else if (stats.armor <= 50) {
			armor_icon3.addClass('armor_half_helm_default')
		} else if (stats.armor <= 100) {
			armor_icon3.addClass('armor_kev_default')
		}
	}

	$bottom.find('#player_bomb_kit_image').removeClass()
	if (stats.defusekit) {
		$bottom.find('#player_bomb_kit_image').addClass('player_kit')
	}
	$bottom
		.find('#player_current_money_text')
		.css('color', dead ? COLOR_WHITE_HALF : '#a7d32e')
	$bottom.find('#player_current_money_text').text('$' + stats.money)
	if (!start_money[steamid]) {
		start_money[steamid] = stats.money;
	  }
	
	  $kda_money.find("#player_spent_text").text("-$" + (start_money[steamid] - stats.money));

	$bottom2.find('#player_bomb_kit_image2').removeClass()
	if (stats.defusekit) {
		$bottom2.find('#player_bomb_kit_image2').addClass('player_kit2')
	}
	
	$bottom2.find('#player_bomb_kit_bg').removeClass()
	if (stats.defusekit) {
		$bottom2.find('#player_bomb_kit_bg')
		.addClass('player_kit')
	}

	$bottom3.find('#player_bomb_kit_image2').removeClass()
	if (stats.defusekit) {
		$bottom3.find('#player_bomb_kit_image2').addClass('player_kit2')
	}
	
	$bottom3.find('#player_bomb_kit_bg').removeClass()
	if (stats.defusekit) {
		$bottom3.find('#player_bomb_kit_bg')
		.addClass('player_kit')
	}
// отображение бомбы справа и слева у терров очиска фона //

	$bottom2.find('#player_bomb_kit_image3').removeClass()
	$bottom3.find('#player_bomb_kit_image3').removeClass()
	$bottom2.find('#player_bomb_kit_bg2').removeClass()
	$bottom3.find('#player_bomb_kit_bg2').removeClass()
// отображение бомбы справа и слева у терров очиска фона //


	

	$bottom3.find('#player_bomb_kit3').removeClass()
	if (stats.defusekit) {
		$bottom3.find('#player_bomb_kit3').addClass('player_bomb_kit4')
	}

	

		$kda_money4.find("#player_spent_text2").text("$" + (start_money[steamid] - stats.money));
		$kda_money5.find("#player_spent_text3").text("$" + (start_money[steamid] - stats.money));

	/*$bottom
		.find('#player_current_money_text2')
		.css('color', dead ? COLOR_WHITE_HALF : '#a7d32e')
	$bottom.find('#player_current_money_text2').text('$' + stats.money)*/

	$bottom.find('#player_skull').removeClass()
	$bottom.find('#player_round_kills_text').text('')
	$bottom.find('#player_round_kills_text2').text('')
	if (stats.round_kills > 0) {
		$bottom.find('#player_skull').addClass('player_skull_default')
		$bottom.find('#player_round_kills_text').text(stats.round_kills)
		$bottom.find('#player_round_kills_text2').text(stats.round_kills)
	}

	$top.find('#player_weapon_primary_img').attr('src', '').removeClass()
	$bottom.find('#player_weapon_secondary_img').attr('src', '').removeClass()

	$bottom.find('#player_nade1').removeClass()
	$bottom.find('#player_nade2').removeClass()
	$bottom.find('#player_nade3').removeClass()
	$bottom.find('#player_nade4').removeClass()
	let grenades = []
	for (let key in weapons) {
		let weapon = weapons[key]
		let name = weapon.name.replace('weapon_', '')
		let state = weapon.state
		let view = ''
		let type = weapon.type
		if (type != 'C4' && type != 'Knife') {
			view += state == 'active' ? 'checked' : 'holstered'
			if (type == 'Grenade') {
				for (let x = 0; x < weapon.ammo_reserve; x++) {
					let nade = {
						weapon: weapon.name.substr(7),
						state: view,
					}
					grenades.push(nade)
				}
			} else if (type) {
				view += side.substr(8) == 'right' ? ' img-hor' : ''
				if (type == 'Pistol') {
					$bottom
						.find('#player_weapon_secondary_img')
						.attr('src', '/files/img/weapons/' + name + '.png')
						.addClass('invert')
						.addClass(view)
				} else {
					$top
						.find('#player_weapon_primary_img')
						.attr('src', '/files/img/weapons/' + name + '.png')
						.addClass('invert')
						.addClass(view)
				}
			}
		}
		if (type == 'C4') {
			view = weapon.state == 'active' ? 'player_bomb_selected' : 'player_bomb'
			$bottom.find('#player_bomb_kit_image').addClass(view)
		}
		//отображение бомбы слева //
		if (type == 'C4') {
			view = weapon.state == 'active' ? 'player_bomb_selected2' : 'player_bomb2'
			$bottom2.find('#player_bomb_kit_image3').addClass(view)
		}
		if (type == 'C4') {
			view = weapon.state == 'active' ? 'player_bomb_selected2' : 'player_bomb_kit_image3_fon'  //.player_bomb_kit_image3_fon
			$bottom2.find('#player_bomb_kit_bg2').addClass(view)
		}
		//отображение бомбы слева //

		//отображение бомбы справа //

		if (type == 'C4') {
			view = weapon.state == 'active' ? 'player_bomb_selected2' : 'player_bomb2'
			$bottom3.find('#player_bomb_kit_image3').addClass(view)
		}
		if (type == 'C4') {
			view = weapon.state == 'active' ? 'player_bomb_selected2' : 'player_bomb_kit_image3_fon'  //.player_bomb_kit_image3_fon
			$bottom3.find('#player_bomb_kit_bg2').addClass(view)
		}
        //отображение бомбы справа //


		if (!checkGuns(weapons)) {
			view += side.substr(8) == 'right' ? ' img-hor' : ''
			$top
				.find('#player_weapon_primary_img')
				.attr('src', '/files/img/weapons/' + name + '.png')
				.addClass('invert')
				.addClass(view)
		}
	}

	if (team == 'ct') {
		if (teams.left.side == 'ct') {
			grenades = grenades.reverse()
		}
	} else if (team == 't') {
		if (teams.left.side == 't') {
			grenades = grenades.reverse()
		}
	}

	for (let x = 0; x < grenades.length; x++) {
		$bottom
			.find('#player_nade' + (x + 1))
			.addClass('player_nade_' + grenades[x].weapon)
		$bottom.find('#player_nade' + (x + 1)).addClass(grenades[x].state)
	}
}

function removeRoundTimeGraphics() {
	$('#round_timer_text').removeClass('bomb_active')
	$('#round_timer_text').removeClass('bomb_exploded')
	$('#round_timer_text').removeClass('bomb_defused')
	$('#round_timer_text').removeClass('pause_active')
	$('#round_timer_text').removeClass('pause_active_T')
	$('#round_timer_text').removeClass('pause_active_CT')
	$('#round_timer_text').removeClass('players_eliminated_T')
	$('#round_timer_text').removeClass('players_eliminated_CT')
	$('#round_timer_text').removeClass('round_time_reached')
	$('#round_timer_text').removeClass('round_warmup')
}

//оригинальный таймер бомбы и разминирование

var isDefusing = false
var bomb_time, bomb_timer, bomb_timer_css, bomb_container_css
bomb_time = 0

function bomb(time) {
	if (Math.pow(time - bomb_time, 2) > 1) {
		clearInterval(bomb_timer)
		bomb_time = parseFloat(time)
		if (bomb_time > 0) {
			bomb_timer = setInterval(function () {

				bomb_container_css = {
                    display: "block"
                }

				bomb_timer_css = {
					opacity: 1,
					width: (bomb_time * 100) / 40 + '%',
				}

				if (teams.right.side == 't') {
					$('#timers #bomb_bar').css(bomb_timer_css)
					$("#right_container").css(bomb_container_css);
                    $("#right_bar").css(bomb_timer_css);
                    $("#right_bar").css("float", "right")
					


			} else {
				$('#timers2 #bomb_bar2').css(bomb_timer_css)
				$("#left_container").css(bomb_container_css);
				$("#left_bar").css(bomb_timer_css);
				$("#left_bar").css("float", "left")
				$('#bomb_bar2').css("float", "right")
				
			}

				
				bomb_time = bomb_time - 0.01
			}, 10)
		} else {
			clearInterval(bomb_timer)
		}
	}
}
// не оригинальный таймер и разминирование
function resetBomb() {
	clearInterval(bomb_timer)


	if(teams.right.side == "t"){
        $("#right_container").css("display", "none");
		$("#left_container").css("display", "none");
		$("#left_background").removeClass();
		$("#left_bar").removeClass();
		$('#left_img').removeClass();
        $("#right_bar").css("display", "none");
		$("#defuse_bar").css("display", "none");
    }
    else{
        $("#right_container").css("display", "none");
		$("#left_container").css("display", "none");
		$("#left_background").removeClass();
		$("#right_background").removeClass();
		$("#right_bar").removeClass();
		$('#right_img').removeClass();
        $("#right_bar").css("display", "none");
		$("#defuse_bar2").css("display", "none");
    }



}

/*
// не оригинальный таймер и разминирование
var isDefusing = false

var bomb_time, bomb_timer, bomb_timer_css, bomb_container_css
bomb_time = 0
function bomb(time) {
	if (Math.pow(time - bomb_time, 2) > 1) {
		clearInterval(bomb_timer)
		bomb_time = parseFloat(time)
		if (bomb_time > 0) {
			bomb_timer = setInterval(function () {
				bomb_container_css = {
					display: 'block',
				}
				bomb_timer_css = {
					display: 'block',
					width: (bomb_time * 90) / 40 + '%',
				}
				if (teams.right.side == 't') {
					$('#right_container').css(bomb_container_css)
					$('#right_bar').css(bomb_timer_css)
					$('#right_bar').css('float', 'right')
				} else {
					$('#left_container').css(bomb_container_css)
					$('#left_bar').css(bomb_timer_css)
					$('#left_bar').css('float', 'left')
				}
				bomb_time = bomb_time - 0.01
			}, 10)
		} else {
			clearInterval(bomb_timer)
		}
	}
}
function resetBomb() {
	clearInterval(bomb_timer)
	if (teams.right.side == 't') {
		$('#right_container').css('display', 'none')
		$('#right_bar').css('display', 'none')
	} else {
		$('#left_container').css('display', 'none')
		$('#left_bar').css('display', 'none')
	}
}
*/
function executeAnim(element, animationNameIn, length, animationNameOut) {
	$(element).css('opacity', 1)
	$(element).addClass('animated')
	$(element).addClass(animationNameIn)
	var wait = setTimeout(function () {
		$(element).removeClass(animationNameIn)
		$(element).addClass(animationNameOut)
	}, length)
	$(element).removeClass(animationNameOut)
}

function animateElement(element, animationName, callback) {
	const node = document.querySelector(element)
	node.classList.add('animated', animationName)

	function handleAnimationEnd() {
		node.removeEventListener('animationend', handleAnimationEnd)

		if (typeof callback === 'function') callback()
	}
	node.addEventListener('animationend', handleAnimationEnd)
}

function showAlert(side, color, text) {
	$(side + ' #alert #pole_1').css('background-color', color)
	$(side + ' #alert #pole_2').css('background-color', color)
	$(side + ' #alert #alert_text')
		.text(text)
		.css('color', color)
	$(side + ' #alert')
		.css('opacity', 1)
		.addClass('animated fadeInUp')
}

//регулировка слайдера об победители
function showAlertSlide(side, color, text) {
	$(side + ' #alert #pole_1').css('background-color', color)
	$(side + ' #alert #pole_2').css('background-color', color)
	$(side + ' #alert #alert_text')
		.text(text)
		.css('color', color)
	if (side == '#left_team') {
		$(side + ' #alert')
			.css('opacity', 1)
			.addClass('animated fadeInRight')
	} else if (side == '#right_team') {
		$(side + ' #alert')
			.css('opacity', 1)
			.addClass('animated fadeInLeft')
	}
}

/* опускание слайдера по timeout */
/*
function hideAlert(side) {
	let element = side + ' #alert'
	$(element).removeClass('animated fadeInUp')
	animateElement(element, 'fadeOutDown', function () {
		$(element).css('opacity', 0).removeClass('animated fadeOutDown')
	})
}*/

function hideAlertSlide(side) {
	let element = side + ' #alert'
	if (side == '#left_team') {
		$(element).removeClass('animated fadeInRight')
	} else if (side == '#right_team') {
		$(element).removeClass('animated fadeInLeft')
	}
	if (side == '#left_team') {
		anim = 'fadeOutRight'
	} else if (side == '#right_team') {
		anim = 'fadeOutLeft'
	}
	animateElement(element, anim, function () {
		$(element)
			.css('opacity', 0)
			.removeClass('animated')
			.removeClass(side == '#left_team' ? 'fadeOutRight' : 'fadeOutLeft')
	})
}

function showMiddleAlert(pole_left_color, pole_right_color, text, text_color) {
	$('#alert_middle #alert_text_middle #pole_1_middle_img').css(
		'background-image',
		'url(/files/img/elements/bomb2.png)'
	)
	$('#alert_middle #pole_1_middle').css('background-color', pole_left_color)
	$('#alert_middle #pole_2_middle').css('background-color', pole_right_color)
	$('#alert_middle #alert_text_middle #alert_text_middle_2')
		.text(text)
		.css('color', text_color)
	executeAnim('#alert_middle', 'fadeInUp', 3000, 'fadeOut')
	/*executeAnim('#pause', 'fadeInUp', 3000, 'fadeOut')*/
}

function forceRemoveAlerts() {
	if ($('#left_team #alert').css('opacity') == 1) {
		$('#left_team #alert').css('opacity', 0).removeClass()
	}
	if ($('#right_team #alert').css('opacity') == 1) {
		$('#right_team #alert').css('opacity', 0).removeClass()
	}
	if ($('#alert_middle').css('opacity') == 1) {
		$('#alert_middle').css('opacity', 0).removeClass()
	}
	if ($('#pause').css('opacity') == 1) {
		$('#pause').css('opacity', 0).removeClass()
	}
}

function animateRoundTimer(_class, remove_graphics) {
	$('#round_timer_text')
		.css('animation-duration', '0.25s')
		.css('animation-iteration-count', '1')
	animateElement('#round_timer_text', 'fadeOut', function () {
		$('#round_timer_text').removeClass('animated fadeOut')
		if (remove_graphics) removeRoundTimeGraphics()
		$('#round_timer_text').text('').addClass(_class)
		animateElement('#round_timer_text', 'fadeIn', function () {
			$('#round_timer_text').removeClass('animated fadeIn')
		})
	})
}

function checkAliveTerrorists(players) {
	for (i = 0; i < players.length; i++) {
		if (players[i].state.health > 0) {
			return true
		}
	}
	return false
}

function checkAlivePlayers(players) {
	var j = 0
	for (i = 0; i < players.length; i++) {
		if (players[i].state.health > 0) {
			j = j + 1
		}
	}
	return j
}

function checkPrev(previously, state) {
	if (previously.hasOwnProperty('phase_countdowns')) {
		if (
			previously.phase_countdowns.hasOwnProperty('phase') &&
			previously.phase_countdowns.phase == state
		) {
			return true
		}
	}
	return false
}

function hidePlayerStats(phase, previously) {
	if (phase.phase == 'live') {
		if (previously.hasOwnProperty('phase_countdowns')) {
			if (previously.phase_countdowns.hasOwnProperty('phase_ends_in')) {
				if (
					previously.phase_countdowns.phase_ends_in >= 110 &&
					phase.phase_ends_in <= 109.9
				) {
					for (let x = 1; x <= 5; x++) {
						animateElement(
							'#players_left #player_section #player' +
								x +
								' .player_stats_holder',
							'fadeOutLeft',
							function () {
								$(
									'#players_left #player_section #player' +
										x +
										' .player_stats_holder'
								)
									.css('opacity', 0)
									.removeClass('animated fadeOutLeft')
							}
						)
						animateElement(
							'#players_right #player_section #player' +
								x +
								' .player_stats_holder',
							'fadeOutRight',
							function () {
								$(
									'#players_right #player_section #player' +
										x +
										' .player_stats_holder'
								)
									.css('opacity', 0)
									.removeClass('animated fadeOutRight')
							}
						)
					}
				} else if (phase.phase_ends_in <= 109) {
					for (let x = 1; x <= 5; x++) {
						if (
							$(
								'#players_left #player_section #player' +
									x +
									' .player_stats_holder'
							).css('opacity') !== 0
						)
							$(
								'#players_left #player_section #player' +
									x +
									' .player_stats_holder'
							).css('opacity', 0)
						if (
							$(
								'#players_right #player_section #player' +
									x +
									' .player_stats_holder'
							).css('opacity') !== 0
						)
							$(
								'#players_right #player_section #player' +
									x +
									' .player_stats_holder'
							).css('opacity', 0)
					}
				}
			}
		}
	}
}

function showPlayerStats(phase) {
	if (phase.phase == 'freezetime') {
		for (let x = 1; x <= 5; x++) {
			if (
				$(
					'#players_left #player_section #player' + x + ' .player_stats_holder'
				).css('opacity') == 0
			) {
				$(
					'#players_left #player_section #player' + x + ' .player_stats_holder'
				).css('opacity', 1)
				animateElement(
					'#players_left #player_section #player' + x + ' .player_stats_holder',
					'fadeInLeft',
					function () {
						$(
							'#players_left #player_section #player' +
								x +
								' .player_stats_holder'
						).removeClass('animated fadeInLeft')
					}
				)
			}
			if (
				$(
					'#players_right #player_section #player' + x + ' .player_stats_holder'
				).css('opacity') == 0
			) {
				$(
					'#players_right #player_section #player' + x + ' .player_stats_holder'
				).css('opacity', 1)
				animateElement(
					'#players_right #player_section #player' +
						x +
						' .player_stats_holder',
					'fadeInRight',
					function () {
						$(
							'#players_right #player_section #player' +
								x +
								' .player_stats_holder'
						).removeClass('animated fadeInRight')
					}
				)
			}
		}
	}
}

function checkGuns(weapons) {
	for (let key in weapons) {
		if (
			weapons[key].type == 'Pistol' ||
			weapons[key].type == 'Rifle' ||
			weapons[key].type == 'SniperRifle' ||
			weapons[key].type == 'Submachine Gun'
		) {
			return true
		}
	}
	return false
}

function updateTeamValues(left, right) {
	let left_color = left.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	let right_color = right.side == 'ct' ? COLOR_NEW_CT : COLOR_NEW_T
	$('#players_left #money_text').css('color', left_color)
	$('#players_left #money_value').text('$' + left.team_money)
	$('#players_right #money_text').css('color', right_color)
	$('#players_right #money_value').text('$' + right.team_money)

	$('#players_left #equip_text').css('color', left_color)
	$('#players_left #equip_value').text('$' + left.equip_value)
	$('#players_right #equip_text').css('color', right_color)
	$('#players_right #equip_value').text('$' + right.equip_value)

	$('#players_left .loss_1').css('background-color', COLOR_WHITE_DULL)
	$('#players_left .loss_2').css('background-color', COLOR_WHITE_DULL)
	$('#players_left .loss_3').css('background-color', COLOR_WHITE_DULL)
	$('#players_left .loss_4').css('background-color', COLOR_WHITE_DULL)
	$('.loss_1_left').css('background-color', COLOR_WHITE_DULL)
	$('.loss_2_left').css('background-color', COLOR_WHITE_DULL)
	$('.loss_3_left').css('background-color', COLOR_WHITE_DULL)
	$('.loss_4_left').css('background-color', COLOR_WHITE_DULL)
	$('#players_right .loss_1').css('background-color', COLOR_WHITE_DULL)
	$('#players_right .loss_2').css('background-color', COLOR_WHITE_DULL)
	$('#players_right .loss_3').css('background-color', COLOR_WHITE_DULL)
	$('#players_right .loss_4').css('background-color', COLOR_WHITE_DULL)
	$('.loss_1_right').css('background-color', COLOR_WHITE_DULL)
	$('.loss_2_right').css('background-color', COLOR_WHITE_DULL)
	$('.loss_3_right').css('background-color', COLOR_WHITE_DULL)
	$('.loss_4_right').css('background-color', COLOR_WHITE_DULL)
	if (left.consecutive_round_losses == 0) {
		left_loss = 1400
	} else if (left.consecutive_round_losses == 1) {
		left_loss = 1900
		$('#players_left .loss_1').css('background-color', left_color)
		$('.loss_1_left').css('background-color', left_color)
	} else if (left.consecutive_round_losses == 2) {
		left_loss = 2400
		$('#players_left .loss_1').css('background-color', left_color)
		$('#players_left .loss_2').css('background-color', left_color)
		$('.loss_1_left').css('background-color', left_color)
		$('.loss_2_left').css('background-color', left_color)
	} else if (left.consecutive_round_losses == 3) {
		left_loss = 2900
		$('#players_left .loss_1').css('background-color', left_color)
		$('#players_left .loss_2').css('background-color', left_color)
		$('#players_left .loss_3').css('background-color', left_color)
		$('.loss_1_left').css('background-color', left_color)
		$('.loss_2_left').css('background-color', left_color)
		$('.loss_3_left').css('background-color', left_color)
	} else if (left.consecutive_round_losses >= 4) {
		left_loss = 3400
		$('#players_left .loss_1').css('background-color', left_color)
		$('#players_left .loss_2').css('background-color', left_color)
		$('#players_left .loss_3').css('background-color', left_color)
		$('#players_left .loss_4').css('background-color', left_color)
		$('.loss_1_left').css('background-color', left_color)
		$('.loss_2_left').css('background-color', left_color)
		$('.loss_3_left').css('background-color', left_color)
		$('.loss_4_left').css('background-color', left_color)
	}

	if (right.consecutive_round_losses == 0) {
		right_loss = 1400
	} else if (right.consecutive_round_losses == 1) {
		right_loss = 1900
		$('#players_right .loss_1').css('background-color', right_color)
		$('.loss_1_right').css('background-color', right_color)
	} else if (right.consecutive_round_losses == 2) {
		right_loss = 2400
		$('#players_right .loss_1').css('background-color', right_color)
		$('#players_right .loss_2').css('background-color', right_color)
		$('.loss_1_right').css('background-color', right_color)
		$('.loss_2_right').css('background-color', right_color)
	} else if (right.consecutive_round_losses == 3) {
		right_loss = 2900
		$('#players_right .loss_1').css('background-color', right_color)
		$('#players_right .loss_2').css('background-color', right_color)
		$('#players_right .loss_3').css('background-color', right_color)
		$('.loss_1_right').css('background-color', right_color)
		$('.loss_2_right').css('background-color', right_color)
		$('.loss_3_right').css('background-color', right_color)
	} else if (right.consecutive_round_losses >= 4) {
		right_loss = 3400
		$('#players_right .loss_1').css('background-color', right_color)
		$('#players_right .loss_2').css('background-color', right_color)
		$('#players_right .loss_3').css('background-color', right_color)
		$('#players_right .loss_4').css('background-color', right_color)
		$('.loss_1_right').css('background-color', right_color)
		$('.loss_2_right').css('background-color', right_color)
		$('.loss_3_right').css('background-color', right_color)
		$('.loss_4_right').css('background-color', right_color)
	}

	$('#players_left #loss_text').css('color', left_color)
	$('#players_left #loss_value').text('$' + left_loss)
	$('#loss_value_left').css('color', left_color)
	$('#loss_value_left').text('$' + left_loss)
	$('#players_right #loss_text').css('color', right_color)
	$('#players_right #loss_value').text('$' + right_loss)
	$('#loss_value_right').css('color', right_color)
	$('#loss_value_right').text('$' + right_loss)
}

function countNades(left, right) {
	var count_left_smokegrenade = 0,
		count_left_incgrenade = 0,
		count_left_molotov = 0,
		count_left_flashbang = 0,
		count_left_hegrenade = 0
	var count_right_smokegrenade = 0,
		count_right_incgrenade = 0,
		count_right_molotov = 0,
		count_right_flashbang = 0,
		count_right_hegrenade = 0

	let side_left = left.side.toUpperCase()
	let side_right = right.side.toUpperCase()

	for (let key in left.players) {
		let player = left.players[key]
		let weapons = player.getWeapons()
		for (let key2 in weapons) {
			let weapon = weapons[key2]
			let name = weapon.name.replace('weapon_', '')
			let type = weapon.type
			if (type == 'Grenade') {
				switch (name) {
					case 'smokegrenade':
						count_left_smokegrenade += 1
						break
					case 'incgrenade':
						count_left_incgrenade += 1
						break
					case 'molotov':
						count_left_molotov += 1
						break
					case 'flashbang':
						count_left_flashbang += 1
						break
					case 'hegrenade':
						count_left_hegrenade += 1
						break
				}
			}
		}
	}

	for (let key in right.players) {
		let player = right.players[key]
		let weapons = player.getWeapons()
		for (let key2 in weapons) {
			let weapon = weapons[key2]
			let name = weapon.name.replace('weapon_', '')
			let type = weapon.type
			if (type == 'Grenade') {
				switch (name) {
					case 'smokegrenade':
						count_right_smokegrenade += weapon.ammo_reserve
						break
					case 'incgrenade':
						count_right_incgrenade += weapon.ammo_reserve
						break
					case 'molotov':
						count_right_molotov += weapon.ammo_reserve
						break
					case 'flashbang':
						count_right_flashbang += weapon.ammo_reserve
						break
					case 'hegrenade':
						count_right_hegrenade += weapon.ammo_reserve
						break
				}
			}
		}
	}

	$('#players_left #util_nade_1').removeClass()
	$('#players_left #util_nade_2').removeClass()
	$('#players_left #util_nade_3').removeClass()
	$('#players_left #util_nade_4').removeClass()
	$('#players_right #util_nade_1').removeClass()
	$('#players_right #util_nade_2').removeClass()
	$('#players_right #util_nade_3').removeClass()
	$('#players_right #util_nade_4').removeClass()

	let total_left =
		count_left_smokegrenade +
		count_left_incgrenade +
		count_left_molotov +
		count_left_flashbang +
		count_left_hegrenade
	let total_right =
		count_right_smokegrenade +
		count_right_incgrenade +
		count_right_molotov +
		count_right_flashbang +
		count_right_hegrenade

	if (total_left == 0) {
		$('#players_left #box_heading_subtext')
			.text(' - None')
			.css('color', '#f21822')
	} else if (total_left <= 5) {
		$('#players_left #box_heading_subtext')
			.text(' - Poor')
			.css('color', '#f25618')
	} else if (total_left <= 9) {
		$('#players_left #box_heading_subtext')
			.text(' - Low')
			.css('color', '#f29318')
	} else if (total_left <= 14) {
		$('#players_left #box_heading_subtext')
			.text(' - Good')
			.css('color', '#8ef218')
	} else if (total_left >= 15) {
		$('#players_left #box_heading_subtext')
			.text(' - Great')
			.css('color', '#32f218')
	} else if (total_left == 20) {
		$('#players_left #box_heading_subtext')
			.text(' - Full')
			.css('color', '#22f222')
	}

	if (total_right == 0) {
		$('#players_right #box_heading_subtext')
			.text('- None')
			.css('color', '#f21822')
	} else if (total_right <= 5) {
		$('#players_right #box_heading_subtext')
			.text('- Poor')
			.css('color', '#f25618')
	} else if (total_right <= 9) {
		$('#players_right #box_heading_subtext')
			.text('- Low')
			.css('color', '#f29318')
	} else if (total_right <= 14) {
		$('#players_right #box_heading_subtext')
			.text('- Good')
			.css('color', '#8ef218')
	} else if (total_right >= 15) {
		$('#players_right #box_heading_subtext')
			.text('- Great')
			.css('color', '#32f218')
	} else if (total_right == 20) {
		$('#players_right #box_heading_subtext')
			.text('- Full')
			.css('color', '#22f222')
	}

	$('#players_left #box_heading_text').css(
		'color',
		side_left == 'CT' ? COLOR_NEW_CT : COLOR_NEW_T
	)
	$('#players_right #box_heading_text').css(
		'color',
		side_right == 'CT' ? COLOR_NEW_CT : COLOR_NEW_T
	)

	$('#players_left #util_nade_1_count').text('x' + count_left_smokegrenade)
	$('#players_left #util_nade_1').addClass('util_smokegrenade_' + side_left)
	$('#players_left #util_nade_2_count').text(
		'x' + (count_left_incgrenade + count_left_molotov)
	)
	$('#players_left #util_nade_2').addClass(
		side_left == 'CT' ? 'util_incgrenade_CT' : 'util_molotov_T'
	)
	$('#players_left #util_nade_3_count').text('x' + count_left_flashbang)
	$('#players_left #util_nade_3').addClass('util_flashbang_' + side_left)
	$('#players_left #util_nade_4_count').text('x' + count_left_hegrenade)
	$('#players_left #util_nade_4').addClass('util_hegrenade_' + side_left)

	$('#players_right #util_nade_4_count').text('x' + count_right_smokegrenade)
	$('#players_right #util_nade_4').addClass('util_smokegrenade_' + side_right)
	$('#players_right #util_nade_3_count').text(
		'x' + (count_right_incgrenade + count_right_molotov)
	)
	$('#players_right #util_nade_3').addClass(
		side_right == 'CT' ? 'util_incgrenade_CT' : 'util_molotov_T'
	)
	$('#players_right #util_nade_2_count').text('x' + count_right_flashbang)
	$('#players_right #util_nade_2').addClass('util_flashbang_' + side_right)
	$('#players_right #util_nade_1_count').text('x' + count_right_hegrenade)
	$('#players_right #util_nade_1').addClass('util_hegrenade_' + side_right)
}

printed_player_data = true
// Включите, чтобы получить SteamID игроков в игре, полезно для создания игроков в БД
function printPlayerData(players) {
	if (!printed_player_data) {
		players_data = []
		players.forEach(function (player) {
			data = {
				name: player.name,
				steamid: player.steamid,
			}
			players_data.push(data)
		})
		console.log(players_data)
		printed_player_data = true
	}
}