<div id="photogallery_popup">
	<div id="header_photo"><h2>{$lang.gallery.photo}&nbsp;</h2></div>

	<div class="photogallery_popup_photo">
		<div id="photogallery_popup_img_cont" class="photogallery_popup_img_cont" style="width: {$info.icon_w}px; max-width: 100%; height: {$info.icon_h}px; position: relative;">
			<img src="{$info.icon_url}" />
			{if $info.user_comment}<div class="photogallery_photo_comment"><div>{$info.user_comment}</div></div>{/if}
		</div>
	</div>

	<div class="photogallery_info_cont">
		<div class="float_left" title="{$lang.gallary.comments}"><a href="javascript:void(0);" onclick="showComments({$info.id});" class="icons photogallery_comments_icon">&nbsp;</a><span class="photogallery_count">{$info.comments_count}</span></div>
		<div class="float_left" id="photogallery_likes" title="{$lang.gallary.likes}"><a id="photogallery_likes_icon" href="javascript:void(0);" class="icons photogallery_likes_icon_{if $info.like_allow}active{else}inactive{/if}">&nbsp;</a><div id="photogallery_likes_count" class="float_right photogallery_count_animate"><ul class="photogallery_count_animate_cont"><li class="photogallery_count">{$info.likes}</li></ul></div></div>
		<div class="float_left" title="{$lang.gallary.views}"><span class="icons photogallery_views_icon">&nbsp;</span><span class="photogallery_count">{$info.views}</span></div>
		<div class="float_right" title="{$lang.gallary.profile}"><a href="{$info.profile_link}" target="_blank" class="icons photogallery_profile_icon">&nbsp;</a><span><a href="{$info.profile_link}" target="_blank">{$info.name}</a></span></div>
	</div>

	<div id="photogallery_popup_comments" class="photogallery_popup_comments" style="display:none;"></div>
</div>

<script>
	var photogallery_photo_id = {if $info.id}{$info.id}{else}0{/if};
	var photogallery_like_allow = {if $info.like_allow}1{else}0{/if};
{literal}
	var photogallery_comments_loaded = 0;
	
	$('#photogallery_popup_img_cont').on('mouseenter', function(){
		$(this).find('.photogallery_photo_comment').fadeIn(100);
	}).on('mouseleave', function(){
		$(this).find('.photogallery_photo_comment').fadeOut(100);
	});
	
	if(photogallery_like_allow){
		$('#photogallery_likes_icon').one('click', function(){likePhoto(photogallery_photo_id)});
	}

	function textchange2(obj, count, count_obj) {
		count_obj = count_obj || null;
		if(count_obj) $(count_obj).text(count);
		var a = $(obj).val().length;
		if (a > count) {
			$(obj).val($(obj).val().substring(0, count));
		}
		a = $(obj).val().length;
		if(count_obj) $(count_obj).html(count - a);
		if (a > count){
			$(obj).css("disabled", "disabled");
		}
	}
	
	function showComments(id){
		$('#photogallery_popup_comments').slideToggle(100);
		if(!photogallery_comments_loaded){
			$.post(
				'{/literal}{$server}{literal}/ajax_backend.php',
				{sel: 'get_ajax_comments', id: id, gid: 'photogallery'},
				function(resp){
					$('#photogallery_popup_comments').html(resp);
					var comments_h = $('#photogallery_popup_comments').outerHeight();
					var comments_offset = $('#photogallery_popup_comments').offset();
					if(comments_h > $(window).height()){
						$(window).scrollTop(comments_offset.top);
					}else{
						var new_top = comments_offset.top + comments_h - $(window).height();
						if(new_top > $(window).scrollTop()){
							$(window).scrollTop(new_top);
						}
					}
				}
			);
			photogallery_comments_loaded = 1;
		}
	}
	
	function likePhoto(id){
		$.ajax({
			url: '{/literal}{$server}{literal}/ajax_backend.php',
			data: {sel: 'like', gid: 'upload', id: id},
			success: function(resp){
				if(resp.status == 1){
					$('#photogallery_likes_count').find('.photogallery_count_animate_cont')
						.append('<li class="photogallery_count">'+resp.likes_count+'</li>')
						.animate({'top': '-=18'}, function(){
							$(this).find('li:first').remove();
							$(this).css('top', 0);
						});
					$('#photogallery_likes_icon').removeClass('photogallery_likes_icon_active').addClass('photogallery_likes_icon_inactive');
				}
			},
			error: function(jqXHR, textStatus, errorThrown){
				$('#photogallery_likes_icon').one('click', function(){likePhoto(photogallery_photo_id)});
			},
			dataType: 'json'
		});
	}
{/literal}
</script>
