<?
include_once 'inc/start.php';

$r1 = mt_rand(1, 6);
$r2 = mt_rand(1, 6);
$r3 = mt_rand(1, 6);

if (!isset($_SESSION['rate']))
$_SESSION['rate'] = 10;

// Стоимость игры
$_rate = $_SESSION['rate'];

if (isset($_GET['rate']) && is_numeric($_GET['rate']))
{
	if ($_GET['rate'] > 0 && $_GET['rate'] <= 100)
	{
		$_SESSION['rate'] = (int) $_GET['rate'];
		header('Location: ?' . $_SESSION['rate']);
		exit;		
	}
}

$_win = 0;

if (isset($_GET['start']) && $user[$_table] >= $_rate)
{
	mysql_query("UPDATE `user` SET `$_table` =  `$_table` - '$_rate' WHERE `id` = '$user[id]' LIMIT 1");
	
	$user[$_table] = $user[$_table] - $_rate;
	
	if ($r1 == $r2 && $r1 == $r3)
	{
		$_win = $_rate * ($r1 + 4);
	}
	elseif ($r1 == 6 || $r2 == 6 || $r3 == 6)
	{
		if ($r1 == 6 && $r2 == 6)
		$x = 2;
		elseif ($r2 == 6 && $r3 == 6)
		$x = 2;
		elseif ($r1 == 6 && $r3 == 6)
		$x = 2;
		else
		$x = 1;
		
		$_win = $_rate * $x;
	}
	
	if ($_win > 0)
	{
		mysql_query("UPDATE `user` SET `$_table` =  `$_table` + '$_win' WHERE `id` = '$user[id]' LIMIT 1");
	}
	
	$_script = true;
}

//$user[$_table] = $user[$_table] + $_win;

include_once 'inc/head.php';
?>
<div class="navig">
<?= $_menu?>
</div>
<?
if (isset($_GET['rate']))
{
	for($i = 1; 10 >= $i; $i++){
		?>
		<div class="navig_rate">
		<a href="?rate=<?= $i?>">Ставка <?= des2num($i, array('монета', 'монеты', 'монет'))?></a>
		</div>
		<?
	}
}
elseif (isset($_GET['help']))
{
	?>
	<div class="navig_help">
	При выпадении этих комбинаций, ваш выигрыш умножается на указанное колличество ниже, раз.
	</div>

	<div class="navig_help">
	<img src="style/fruit/6.PNG">
	<div></div>
	<div></div>
	<div>x1</div>
	</div>

	<div class="navig_help">
	<img src="style/fruit/6.PNG">
	<img src="style/fruit/6.PNG">
	<div></div>
	<div>x2</div>
	</div>
	<?
	
	for($i = 1; 6 >= $i; $i++){
		?>
		<div class="navig_help">
		<img src="style/fruit/<?= $i?>.PNG">
		<img src="style/fruit/<?= $i?>.PNG">
		<img src="style/fruit/<?= $i?>.PNG">
		<div>x<?= $i + 4?></div>
		</div>
		<?
	}
	
	?>
	<div class="fruit_foot">
	<table class="fruit_foot">
	<tr>
	<td><a class="start"  href="?">Назад</a></td>
	</tr>
	</table>
	</div>
	<?
}
else
{
	?>
	<div class="fruit_head">
	<table class="fruit_head">
	<tr>
	<td>Ставка<br /><span style="color: #46ff00"><?= $_rate?></span></td>
	<td>Выигрыш<br /><span style="color: #46ff00"><?= $_win?></span></td>
	<td><?= $_name?><br /><span style="color: #46ff00"><?= ($user[$_table] - $_rate)?></span></td>
	</tr>
	</table>
	</div>

	<div class="fruit_back">
	<div class="fruit"></div>
	<div class="fruit_img">
	<div id="matrix">
	<div class="column column1"><img src="style/fruit/<?= $r1?>.PNG" /></div>
	<div class="column column2"><img src="style/fruit/<?= $r2?>.PNG" /></div>
	<div class="column column3"><img src="style/fruit/<?= $r3?>.PNG" /></div>
	</div>
	</div>
	</div>
	
	<?if (isset($_GET['start']) && isset($_script)) { ?>
	<script type="text/javascript">
	checkAnimation(document.body);
	prepareAnimation('fc_modern', '240', 3, 1);

	window.onload = function(){
		startAnimation(0, 3)
	};
	</script> 
	<? } ?> 

	<div class="fruit_foot">
	<table class="fruit_foot">
	<tr>
	<?if ($user[$_table] + $_win < $_rate) {?>
	<td><a class="start"  href="<?= $no_money?>">Биллинг</a></td>
	<? } else { ?>
	<td><?= ($_win == 0 ? '<a class="start"  href="?start=' . mt_rand(00000, 99999) . '">Крутить</a>' : '<a class="start"  href="?take">Забрать</a>')?></td>
	<? } ?>
	<td><a class="gray" href="?rate">Ставка</a></td>
	<td><a class="gray" href="?help">Справка</a></td>
	</tr>
	</table>
	</div>
	<?	
}

?>
<div class="navig">
<?= $_menu?>
</div>
<?

include_once 'inc/foot.php';
?>