<?
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/start.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/sess.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/home.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/settings.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/db_connect.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/ipua.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/fnc.php';

$id = (int) $_GET['id'];

$foto = mysql_fetch_assoc(query("SELECT * FROM `gallery_foto` WHERE `id` = '$id'  LIMIT 1"));
$gallery = mysql_fetch_assoc(query("SELECT * FROM `gallery` WHERE `id` = '$foto[id_gallery]' LIMIT 1")); 
$ank = get_user($gallery['id_user']);

if (isset($_SESSION['id_user']))
$user = get_user($_SESSION['id_user']);

$left_count = mysql_result(query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id` > '$foto[id]' AND `id_gallery` = '$gallery[id]'"),0);
$right_count =  mysql_result(query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id` < '$foto[id]' AND `id_gallery` = '$gallery[id]'"),0);

if (!$foto['id']) 
{
	die('Фотография не найдена');
	exit;
}

$q = query("SELECT * FROM `gallery_foto` WHERE `id_gallery` = '$gallery[id]' ORDER BY `id` DESC");

$num = 0;
?>
<div style="display: none;" id="photo_count" title="<?= $right_count?>"></div>
<a onclick="closeModal();"><div class="modal-buttons" id="modal-right">Закрыть</div></a>

<a id="action" href="/foto/<?=$foto['id_user']?>/<?=$foto['id_gallery']?>/<?=$foto['id']?>/"><div class="modal-buttons" id="modal-left">Действие</div></a>

<a id="comment" href="/foto/<?=$foto['id_user']?>/<?=$foto['id_gallery']?>/<?=$foto['id']?>/"><div class="modal-buttons" id="modal-left-bottom"><span class="ic_main komm"></span> 
 <span id="count_comment"></span></div></a>
 
<a id="play" onclick="play();" title="1"><div class="modal-buttons" id="modal-right-bottom"><span class="ic_all slide_play"></span></div></a>

<a id="navigation-left" onclick="step(0);"><span class="modal-nav" id="nav-left">&laquo;</span></a>
<a id="navigation-right" onclick="step(1);"><span class="modal-nav" id="nav-right">&raquo;</span></a>

<div class="touchslider touchslider-demo">
<div class="touchslider-viewport">
<div>
<?
while ($foto = mysql_fetch_assoc($q)) 
{
	?>
	<div class="touchslider-item">
	<div id="modal-table">
	<div id="modal-row">
	<div id="modal-cell">	
	<div style="display: block;">
	<img class="touchslider-img" id="id-<?= $num?>" src="/sys/javascript/icons/ajax-loader.gif" alt="<?= $foto['id']?>" title="<?= text($foto['name'])?>" />
	<span id="show_<?= $num?>" title="0" ></span>
	<span id="photo_<?= $num?>" title="/foto/<?=$foto['id_user']?>/<?=$foto['id_gallery']?>/<?=$foto['id']?>/" style="display: hidden;"></span>
	
	<div class="modal-foot-menu">
	<?
	if (isset($user) && $user['id'] != $foto['id_user'])
	{
		if (mysql_result(query("SELECT COUNT(*) FROM `gallery_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0) == 0)
		{
			?>
			<center id="rate_<?= $foto['id']?>">
			<a onclick="actionAjax('func=photo&id=<?= $foto['id']?>&rating=6', 'rate_<?= $foto['id']?>');" title="5+"><span class="rtr_icon rtr_6"></span></a>
			<a onclick="actionAjax('func=photo&id=<?= $foto['id']?>&rating=5', 'rate_<?= $foto['id']?>');" title="5"><span class="rtr_icon rtr_5"></span></a>
			<a onclick="actionAjax('func=photo&id=<?= $foto['id']?>&rating=4', 'rate_<?= $foto['id']?>');" title="4"><span class="rtr_icon rtr_4"></span></a>
			<a onclick="actionAjax('func=photo&id=<?= $foto['id']?>&rating=3', 'rate_<?= $foto['id']?>');" title="3"><span class="rtr_icon rtr_3"></span></a>
			<a onclick="actionAjax('func=photo&id=<?= $foto['id']?>&rating=2', 'rate_<?= $foto['id']?>');" title="2"><span class="rtr_icon rtr_2"></span></a>
			<a onclick="actionAjax('func=photo&id=<?= $foto['id']?>&rating=1', 'rate_<?= $foto['id']?>');" title="1"><span class="rtr_icon rtr_1"></span></a>
			</center>
			<?
		}
		else
		{
			$rate = mysql_fetch_assoc(query("SELECT * FROM `gallery_rating` WHERE `id_foto` = $foto[id] AND `id_user` = '$user[id]' LIMIT 1"));
			$link = "actionAjax('func=photo&id=" . $foto['id'] . "&rating=6&update', 'rate_". $foto['id']."');";
			
			?><center id="rate_<?= $foto['id']?>"><?= __('Ваша оценка')?> <span class="rtr_icon rtr_<?= $rate['like']?>"></span> 
			<?= ($rate['like'] < 6 ? __('повысить до') . ' <a onclick="' . $link . '" title="5+"><span class="rtr_icon rtr_6"></span></a>' : '')?></center><?
		}
	}
	?>
	<span id="count_<?= $num?>" title="<?= mysql_result(query("SELECT COUNT(*) FROM `gallery_komm` WHERE `id_foto` = '$foto[id]'"),0)?>"></span>
	</div>
	</div>
	</div>
	</div>
	</div>
	</div>
	<?
	$num++;
}
?>
</div>
</div>
</div>

<script type="text/javascript">


//document.getElementById('photo_<?= $left_count + 1?>').style.display = 'block';

function step(step){
	if (step == 1)
	$(".touchslider").data("touchslider").next();
	else
	$(".touchslider").data("touchslider").prev();
}

function play(play){
	
	if (document.getElementById('play').title == 1)
	{
		document.getElementById('play').title = '0';
		document.getElementById('modal-right-bottom').innerHTML = '<span class="ic_all slide_pause"></span>';	
		$(".touchslider").data("touchslider").start(); 
	}else{
		document.getElementById('play').title = '1';
		document.getElementById('modal-right-bottom').innerHTML = '<span class="ic_all slide_play"></span>';	
		$(".touchslider").data("touchslider").stop();
	}
}

$(".touchslider-demo").touchSlider({mouseTouch: true});
$(".touchslider").data("touchslider").step('<?= $left_count?>', null, '<?= $num?>'); // start the slider

// Вычисляем размер экрана
var widthScreen = screen.width, heightScreen = screen.height;

// Вычисляем размер окна браузера
var widthBrowser = $(window).width(), heightBrowser = $(window).height();

// Cразу меняем размер окна слайдера
$('body').css({'overflow' : 'hidden', 'position' : 'fixed'});

//alert(widthBrowser + 'x' + heightScreen);

$('.touchslider-img').css({'max-width' : widthBrowser, 'max-height' : heightBrowser});
$('.touchslider-viewport').css({'width' : widthBrowser, 'height' : heightBrowser});
$('.touchslider-item').css({'width' : widthBrowser, 'height' : heightBrowser});
$('.modal-foot-menu').css({'width' : widthBrowser, 'height' : heightBrowser / 4});

// Проверяем на изменение размера
function touchsliderScreen() 
{
	// Вычисляем размер окна браузера
	var widthBrowser = $(window).width(), heightBrowser = $(window).height();
	
	if (widthBrowser > 600){
		$('.modal-nav').css({'display' : 'inline-block'});
	}

	// Cразу меняем размер окна слайдера и содержимого
	$('.touchslider-img').css({'max-width' : widthBrowser, 'max-height' : heightBrowser});
	$('.touchslider-viewport').css({'width' : widthBrowser, 'height' : heightBrowser});
	$('.touchslider-item').css({'width' : widthBrowser, 'height' : heightBrowser});
	$('.modal-foot-menu').css({'width' : widthBrowser, 'height' : heightBrowser / 4});

}

$(document).ready(function()
{  
	touchsliderScreen();  
	setInterval('touchsliderScreen()', 500);  
});  

</script>