<?php
if(!defined('GAME'))
{
	die();
}

session_start();

if($u->room['file']=='loto')
{
if($_GET['get']=='20')
{
	mysql_query('DELETE FROM `actions` WHERE `uid` = "'.$u->info['id'].'" AND `vals` = "loto"');
}
$titm = mysql_fetch_array(mysql_query('SELECT * FROM `actions` WHERE `uid` = "'.$u->info['id'].'" AND `vals` = "loto" ORDER BY `time` DESC LIMIT 1'));
if($_GET['get']=='10' && $titm==false)
{

	$droplist = array(
	        0=>4514,
            1=>4515,
            2=>4688,
            3=>4689,
            4=>4690,
            5=>5009,
            6=>5008,
            7=>5010,
            8=>5239,
            9=>5069,
            10=>10035,
            11=>10036,
            12=>10037,
            13=>10008,
            14=>10020,
            15=>6112,
            16=>6113,
            17=>6114,
            18=>6115,
            19=>6116,
            20=>6360,
            21=>6462,
            22=>5022,
            23=>5023,
            24=>6445,
            25=>6455,
            26=>10009,
            27=>1032,
            28=>1031,
            29=>1034
	);
    $idve=$droplist[rand(0,count($droplist)-1)];
    $u->addItem($idve,$u->info['id'],'|frompisher=1|nosale=1'.$u->info['login']);
    $inf = mysql_fetch_array(mysql_query('SELECT * FROM `items_main` WHERE `id` = "'.$idve.'" LIMIT 1'));
	$titm = mysql_query('INSERT INTO `actions` (`uid`,`time`,`city`,`room`,`vars`,`ip`,`vals`) VALUES ("'.$u->info['id'].'","'.time().'","'.loto.'","'.$u->info['room'].'","'.$idve.'","'.mysql_real_escape_string($_SERVER['HTTP_X_REAL_IP']).'","loto")');
	echo json_encode($idve); // тут передача и попытка запуска
}


?>
	<TABLE width="100%" cellspacing="0" cellpadding="0">
	<tr><td valign="top"><div align="center" class="pH3"><h3>Лото Бойцовского Клуба</h3></div>
	<br />

            <div id="winDiv">
                <p class="testDiv">Ваш приз: <span id="win"></span></p>
                <div id="imgWin"></div>
            </div>

            <div class="wraper">
                <div class="arrowup"></div>
                <div class="arrowdown"></div>
                <div class="window">
                    <ul class="list"></ul>
                </div>
            </div>
            <p style="text-align: center">
		    Рулетка <?if ($titm==false){?><a href="?get=10">Крутить</a> <?} else {?> <a href="?get=20">Обновить</a> <?}?>
		   <!--
			<button class="buttonRuletka" onclick="(<?php //echo json_encode($idve) ?>)" formmethod="get">Запустить игру!</button>
			-->

            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
            <script>


                var $ulImg = document.getElementsByClassName("list")[0]

                var $arrLiImg = [
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/ambosia_gora.gif" type="id1" title="Амброзия подмастерья Владык"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/bag1291.gif" type="id2" title="Туманная Сумка"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/otvar112.gif" type="id3" title="Отвар Когтей ПГ"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/best.gif" type="id4" title="Хорошее Железо"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/100ekkr.gif" type="id5" title="Чек на 100 Еврокредитов"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/50ekkr.gif" type="id6" title="Чек на 50 Еврокредитов"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/fine.gif" type="id7" title="Нормальное Железо"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/food_l10_e.gif" type="id8" title="Яблоко Раздора"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/food_l11_e.gif" type="id9" title="Жесткая Рыба"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/food_l5_eng.gif" type="id10" title="Бутерброд -The Best Friend-"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/invoke_plain_honor_attack_invul_any1.gif" type="id11" title="Защита от Нападения [30]"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/jora10.gif" type="id12" title="Сумка Копателя Катакомб"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/jora101.gif" type="id13" title="Улучшенная Сумка Короля"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/jora7.gif" type="id14" title="Сумка Копателя Бездны"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/jora8.gif" type="id15" title="Сумка Защиты"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/jora9.gif" type="id16" title="Сумка Копателя Горы Легиона"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/joust_rew_s.gif" type="id17" title="Жетон Успеха"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/grib112.gif" type="id18" title="Сушеный Мухомор"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/voda112.gif" type="id19" title="Живая Вода"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/lootbag_.gif" type="id20" title="Сумка Валлуара Великого"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/poor.gif" type="id21" title="Плохое Железо"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/pot_base_1000_dex.gif" type="id22" title="Смазка для Големов"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/pot_base_1000_inst.gif" type="id23" title="Ускоритель для Големов"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/pot_base_1000_str.gif" type="id24" title="Топливо для Големов"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/pot_base_200_alldmg2_p1k.gif" type="id25" title="Зелье Каменной Стойкости"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/pot_base_200_allmag2_p1k.gif" type="id6" title="Зелье Стража Магии"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/svitok1.png" type="id27" title="Свиток Репутации Потерянного Входа"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/svitok1.png" type="id28" title="Свиток Репутации Горы Легиона"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/zolyaichko.gif" type="id29" title="Яйцо Дракона"></li>',
                    '<li><img src="https://new-combats.com/img.new-combats.com/i/items/ambosia_gora.gif" type="id30" title="Амброзия Скучающих Владык"></li>'
                ]

                function shuffle (array) {
                    var currentIndex = array.length, temporaryValue, randomIndex ;

                    while (0 !== currentIndex) {

                        randomIndex = Math.floor(Math.random() * currentIndex);
                        currentIndex -= 1;

                        temporaryValue = array[currentIndex];
                        array[currentIndex] = array[randomIndex];
                        array[randomIndex] = temporaryValue;
                    }

                    return array;
                }

                var $finallyLiImg = shuffle($arrLiImg)

                for (let key of $finallyLiImg) {
                    var $htmlElementsMessage = new DOMParser().parseFromString(key, "text/html").getElementsByTagName("li")[0]
                    $ulImg.append($htmlElementsMessage)
                }

                var $button = document.getElementsByClassName("buttonRuletka")[0]
                var $winWindow = document.getElementById("winDiv")
                var $win = document.getElementById("win")
                var $wrapper = document.getElementsByClassName("wraper")[0]
                var $imgWin = document.getElementById("imgWin")

                $winWindow.style.top = `${$wrapper.offsetTop}px`
                $winWindow.style.left = `${($wrapper.offsetWidth / 2) - 326}px`

                $winWindow.hidden = true

                var timeOutWin 

                $(document).ready(function () {
                    for (i = 0; i < 3; i++) {
                        $(".list li").clone().appendTo(".list");
                    }
                    $button.onclick = () => {

                        if (timeOutWin) {
                            clearTimeout(timeOutWin)
                            $imgWin.innerHTML = ""
                            $winWindow.hidden = true
                        }
                        // console.log(timeOutWin)
                        $imgWin.innerHTML = ""
                        $button.textContent = "Ожидание..."
                        $button.disabled = true

                        $('.window').css({
                            right: "0"
                        })
                        $('.list li').css({
                            border: '4px solid transparent'
                        })

                        function selfRandom(min, max) {
                            return Math.floor(Math.random() * (max - min + 1)) + min;
                        }

                        var x = selfRandom(50, 100);

                        $('.window').animate({
                            right: ((x * 75) + (x * 8 - 12) - 435)
                        }, 1500, () => {

                            var $winImg = $('.list li:eq(' + x + ')')[0]
                            // console.log($winImg.children[0].getAttribute("src"))

                            setTimeout( () => {
                                
                                var idThing = $winImg.children[0].getAttribute("type")
                                var titleThing = $winImg.children[0].getAttribute("title")
                                $button.disabled = false
                                $winWindow.hidden = false
                                $button.textContent = "Запустить игру!"
                                $win.textContent = titleThing

                                var $img = document.createElement("img")
                                $img.src = $winImg.children[0].getAttribute("src")
                                $imgWin.append($img)
                                
                                timeOutWin = setTimeout( () => {
                                    $imgWin.innerHTML = ""
                                    $winWindow.hidden = true
                                }, 10000)
                            }, 300)
                        })
                    // });
                    }
                });
            </script>
            <style>
                * {
                    padding: 0;
                    margin: 0;
                }

                li {
                    list-style: none;
                    display: inline-block;
                    float: left;
                }

                .window {
                    padding: 5px 0;
                    overflow: hidden;
                    position: relative;
                    width: 25000px;
                    height: 82px;
                    right: 0px;
                }

                .wraper {
                    position: relative;
                    margin: auto;
                    margin-top: 180px;
                    width: 982px;
                    overflow-x: hidden;
                    overflow-y: hidden;
                    border: 4px solid #1a96b7;
                    border-radius: 2px;
                }

                .list {
                    position: relative;
                    margin-left: 0;
                    display: inline-block;
                }

                .list li {
                    border: 4px solid transparent;
                }

                .list li img {
                    width: 75px;
                    height: 75px;
                }
                .arrowup {
                    position: absolute;
                    bottom: 0;
                    left: 485px;
                    z-index: 1;
                    width: 0;
                    height: 0;
                    border-bottom: 20px solid #1a96bf;
                    border-left: 5px solid transparent;
                    border-right: 5px solid transparent;
                }

                .arrowdown {
                    position: absolute;
                    top: 0;
                    left: 485px;
                    z-index: 1;
                    width: 0;
                    height: 0;
                    border-top: 20px solid #1a96bf;
                    border-left: 5px solid transparent;
                    border-right: 5px solid transparent;
                }
                .buttonRuletka {
                    font-size: 17px;
                    padding: 5px;
                    width: 150px;
                    border: 1px solid #1a96bf;
                    margin: 10px 0;
                }
                .buttonRuletka:hover {
                    background: rgba(0, 102, 149, 0.33);
                }
                #winDiv {
                    border: 1px solid #1a96bf;
                    border-radius: 3px;
                    position: fixed;
                    text-align: center;
                    width: 500px;
                    /* margin-left: auto;
                    margin-right: auto; */
                    padding: 7px;
                }
                .testDiv {
                    font-size: 16px;
                }
                #win {
                    font-weight: 600;
                }

            </style>
	<td width="50" valign="top">
    <TABLE cellspacing="0" cellpadding="0"><TD width="100%">&nbsp;</TD><TD>
	<table  border="0" cellpadding="0" cellspacing="0">
	<tr align="right" valign="top">
	<td>
	<!-- -->
	<? echo $goLis; ?>
	<!-- -->
	<table border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td nowrap="nowrap">
	<tr>
	<td bgcolor="#D3D3D3"><img src="https://img.new-combats.com/i/move/links.gif" width="9" height="7" /></td>
	<td bgcolor="#D3D3D3" nowrap><a href="#" id="greyText" class="menutop" onclick="location='main.php?loc=1.180.0.9&rnd=<? echo $code; ?>';" title="<? thisInfRm('1.180.0.9',1); ?>">Центральная площадь</a></td>
	</tr>
	</td>
	</tr>
	</table>
	</td></table>
	</td></table>
	<div><br />
	</div></td>
	</table>
    <br>
	<div id="textgo" style="visibility:hidden;"></div>
<?
}
?>