(function ($) {
	$(function () {
		Pod.require(['nyLotteryVars'], function (nyLotteryVars) {
			if (nyLotteryVars.stage != 2 && nyLotteryVars.stage != -1) {
				console.log('ERROR: unexpected value of stage ' + nyLotteryVars.stage);
				return;
			}

			$('#js_div_newyear_subtitle').text('Наши победители');
			$('#js_ul_newyear_subtitle_switch').hide();
			$('.newyear_lottery_text').hide();

			var myId = nyLotteryVars.myId;
			var winners = nyLotteryVars.winners;
			var table = $('#js_bottom_table');
			var tableHeadRow = table.find('thead').find('tr');
			var tableBody = table.find('tbody');

			tableHeadRow.empty().append(
				$('<th>').text('Место'),
				$('<th>').text('Участник'),
				$('<th>').text('Выигрыш')
			);
			tableBody.empty();
			$.each(winners, function (index, winner) {
				tableBody
					.append($('<tr>').append(
						$('<td>').text(winner.won_place),
						$('<td>').text(winner.name),
						$('<td>').html(winner.won_prize))
					).addClass(myId == winner.uid ? 'active' : '');
			});
			$.pagination({number: 0, perPage: 0, now: 0});
		});
	});
})($);
