<?php
$tag_delivery_btn = '/img/web/bt_delivery_off_gray.png';
if($tag_delivery_count > 0) {
	$tag_delivery_btn = '/img/web/bt_delivery_on_gray.png';
}
$SES_MEMBER_ID              = $this->session->userdata('C_Member_Id');
?>

    <div id="life" class="channel_contents4">
		<div class="wrap">
			<div style="text-align:center;">
				<p class="c_title" >#<?=$tag?> <span style="padding-top:1px;"><a href="javascript:tag_delivery();"><img src="<?=$tag_delivery_btn?>" id="tag_delivery_btn"></a></span></p>
				<p style="padding-bottom:20px;"><span><?=number_format($total_count)?>개의 글이 있어요</span></p>
			</div>
			<div class="channel_top" style="text-align:center;">
			<? 	foreach ($arr_relation_tag as $val) {?>
				<button type="button" class="btn btn-default_bb br20" onclick="location.href='/web/life/tag/<?=$val['tag']?>'" style="padding:10px 40px;"><?=$val['tag']?></button>
			<?	}?>

			</div>
            <div id="tag_list">
    <?      $i=1;
            $tag_count = count($list);
            if($tag_count == 0) echo '<div style="height:100px; text-align:center; padding-top:30px">등록된 태그가 없습니다.</div>';
            foreach ($list as $val) {

                $head_title = '';
                if($val['head_title'] != '')    $head_title = '<span class="beachblue">['.$val['head_title'].']</span> ';
                $title = $head_title.$val['title'];

                $title_txt = mb_strimwidth($title, '0', '80', '..', 'utf-8');


                if($i%3==1) echo '<div class="channel_boxs">';
   ?>

				<div class="channel_con">
                    <div class="art-img" onclick="location.href='/web/life/life_view/<?=$val['idx']?>'" style="cursor:pointer;width:304.58px;height:197.19px;background:url('<?=$val['main_img']?>') no-repeat center; background-size:cover;"></div>
					<p class="chtitle" style="height:57px"><a href="/web/life/life_view/<?=$val['idx']?>"><?=$title_txt?></a><span class="c_name"><a href="/web/life/editor/<?=$val['partner_idx']?>"><?=$val['editor_name']?></a></span><span class="checkno fr">조회 <?=number_format($val['hit_count'])?> </span></p>
				</div>

     <?

                if($i%3==0 || $tag_count==$i)    echo '</div>';

                $i++;
            }
    ?>
            </div>

        <?
            $more_btn_style = 'style="display:none"';
            if($tag_count < $total_count) {
                $more_btn_style = 'style="display:block"';
            }
        ?>
        <div class="channel_bottom" <?=$more_btn_style?> id="tag_more_btn">
            <button type="button" class="btn btn-default br20" onclick="tag_list_more();">더보기 </button>
        </div>
		</div>
	</div>




<script>
var page = 2;
function tag_list_more(){
	var form_data = {
		"page"  : page,
		"tag"   : "<?=$tag?>"
	};
	$.ajax({
        url: '/web/life/tag_list_more',
        async: false,
        type: 'POST',
        dataType: 'HTML',
        data: form_data,
        success: function (rtnHtml) {
        	if(rtnHtml=='') return false;
			var arrHtml = rtnHtml.split("|||||");
			if(arrHtml[0].trim()=='0000') {
				$("#tag_list").append(arrHtml[1]);
				if (arrHtml[3] == "N") {
					$("#tag_more_btn").hide();
				} else {
					$("#tag_more_btn").show();
				}
				page++;

			} else {
				alert(arrHtml[1]);
               	return false;
			}
        },
        error: function (rtnHtml) {
            alert('데이터 가져오기에 실패했습니다.');
            return false;
        }
    });
}


function tag_delivery(){
	if("<?=$SES_MEMBER_ID?>"=="") {
        alert("로그인 후에 이용가능합니다.");
        return;
    }
	var form_data = {
		"main_idx"			: '<?=$tag?>',
		"content_type"		: '9'
	};
	$.ajax({
        url: '/web/comm/delivery_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function (rtnJson) {
            if (rtnJson.code == "0000") {
				$("#tag_delivery_btn").attr("src","/img/web/bt_delivery_"+rtnJson.data+"_gray.png");

            } else {
                alert("저장에 실패했습니다.");
                return false;
            }
        },
        error: function (rtnJson) {
            alert('저장에 실패했습니다.');
            return false;
        }
    });

}




</script>



