<?php
$channel_name 		=  $result['channel_name'];
$channel_main_img 	=  $result['main_img'];
$channel_idx 		=  $result['idx'];
$category_idx 		=  $result['category_idx'];
$category_name 		=  $result['category_name'];
$channel_intro 		=  $result['channel_intro'];
$channel_icon 		=  $result['channel_icon'];
$content_type = '3';

include_once('life_header_inc.php'); ?>

<div class="channel_contents2">
	<div class="wrap">
		<div class="channel_top">
			<span class="fl">전체글 수 <span class="beachblue"><?= number_format($total_count) ?></span></span>
			<span class="fr">
				<button type="button" onclick="location.href='/web/life/channel/<?= $channel_idx ?>?search_sort=1'" class="btn 
				<? if ($search_sort == '1') {
					echo 'btn-default_bb';
				} else {
					echo 'btn-default';
				} ?> br20">최신순</button>
				<button type="button" onclick="location.href='/web/life/channel/<?= $channel_idx ?>?search_sort=2'" class="btn 
				<? if ($search_sort == '2') {
					echo 'btn-default_bb';
				} else {
					echo 'btn-default';
				} ?> br20">인기순</button>
			</span>
		</div>

		<div class="channel_boxs" id="life_list" style="margin-bottom: 0 !important;">
			<? $i = 1;
			foreach ($list as $val) {
				$title_txt = mb_strimwidth($val['title'], '0', '90', '..', 'utf-8');

				$channel_article_style = '';
				if ($i == count($list)) {
					$channel_article_style = 'style="border-bottom:0 !important"';
				}
				?>
				<div class="channel_cont" <?= $channel_article_style ?>>
					<div class="channel_photo" onclick="location.href='/web/life/life_view/<?= $val['idx'] ?>'" style="cursor:pointer;width:234px;height:151px;background:url('<?= $val['main_img'] ?>') no-repeat center; background-size:cover;"></div>
					<p class="chtitle2"><a href="/web/life/life_view/<?= $val['idx'] ?>"><?= $title_txt ?></a></p>
					<p><img src="/img/web/img_heart.gif"><span class="like"><?= number_format($val['like_count']) ?></span><span class="chname pdl25"><a href="/web/life/editor/<?= $val['partner_idx'] ?>"><?= $val['editor_name'] ?></a></span></p>
				</div>
			<? $i++;
			} ?>
		</div>
		<?
		$life_more_btn_style = 'display:none;';
		if ($total_count > count($list)) {
			$life_more_btn_style = 'display:block;';
		}
		?>
		<div class="channel_bottom">
			<button type="button" class="btn btn-default br20" id="life_more_btn" onclick="channel_list_more();" style="width:18%;margin-left: 41%;<?= $life_more_btn_style ?>">더보기 </button>
		</div>
	</div>
</div>



<script>
	var form_data = {
		"sort": "<?= $search_sort ?>",
		"page": 2,
		"channel_idx": "<?= $channel_idx ?>",
		"ready": true,
		"lastScroll": 0
	};

	$(window).on('scroll', function() {
		var h = window.innerHeight + window.scrollY;
		if (form_data.lastScroll < h && ((h >= document.body.offsetHeight - 60 && h <  document.body.offsetHeight - 40) || h == document.body.offsetHeight)) {
			channel_list_more();
		}
		form_data.lastScroll = h;
	});

	

	function channel_list_more() {
		if (form_data.ready) {
			form_data.ready = false;
			$.ajax({
				url: '/web/life/life_list_more',
				async: false,
				type: 'POST',
				dataType: 'HTML',
				data: form_data,
				success: function(rtnHtml) {
					form_data.ready = true;
					if (rtnHtml == '') return false;
					var arrHtml = rtnHtml.split("|||||");
					if (arrHtml[0].trim() == '0000') {
						$("#life_list").children('.channel_cont').last().removeAttr("style");
						$("#life_list").append(arrHtml[1]);

						if (arrHtml[3] == "N") {
							$("#life_more_btn").hide();
						} else {
							$("#life_more_btn").show();
						}
						form_data.page++;

					} else {
						form_data.ready = false;						
						return false;
					}
				},
				error: function(rtnHtml) {
					alert('저장에 실패했습니다.');
					return false;
				}
			});
		}
	}
</script>
<script type="text/javascript" src="//wcs.naver.net/wcslog.js"></script>
<script type="text/javascript">
	if (!wcs_add) var wcs_add = {};
	wcs_add["wa"] = "2ee4bea3106352";
	wcs_do();
</script>