<?php
$arr_tag = explode(" ",$result['tag']);
$arr_tag = array_filter(array_map('trim',$arr_tag));

$title 				=  $result['title'];
$content 			=  $result['content'];
$main_img 			=  $result['main_img'];
$channel_main_img 	=  $result['channel_main_img'];
$editor_name 		=  $result['editor_name'];
$category_name 		=  $result['category_name'];
$channel_name 		=  $result['channel_name'];
$sub_title 			=  $result['sub_title'];
$hit_count 			=  $result['hit_count'];
$display_date 		=  $result['display_date'];
$partner_img 		=  $result['partner_img'];
$channel_idx 		=  $result['channel_idx'];
$partner_idx 		=  $result['partner_idx'];
$category_idx 		=  $result['category_idx'];
$video_url 			=  $result['video_url'];


 # session
$SES_MEMBER_ID              = $this->session->userdata('C_Member_Id');


$bookmark_img = '/img/web/star_off.png';
if($bookmark_count > 0) {
	$bookmark_img = '/img/web/star_on.png';
}
$content_type = '3';


?>
 	<? include_once ('life_header_inc.php');?>

	<div class="life_contents" style="margin-top:70px;">
		<img src="<?=$main_img?>" width="0" height="0">
	<? 	if($video_url!='') {?>
		<div style="text-align:center; display: block;"><iframe type="text/html" src="<?=$video_url?>" allowfullscreen="true" style="border: 0px; display: block; margin: 0px; width: 560px; height: 315px;" data-ratio="0.5625" data-width="560" data-height="315"></iframe></div>
	<?	}?>
		<div class="view_article">

		    <?=$content?>
		</div>
	</div>
	<div class="life_tags">
		<div class="wrap">
			<div class="cover_profile3">
                <div onclick="location.href='/web/life/editor/<?=$partner_idx?>'" style="cursor:pointer;margin:auto;border-radius: 65px;width:65px;height:65px;background:url('<?=$result['partner_img']?>') no-repeat center; background-size:cover;"></div>
			</div>
        <? if(count($arr_tag)>0) { ?>
			<div class="tags">Tags
            <?  foreach ($arr_tag as $key=>$val) {
                    if($key>0) echo ', ';
            ?>
                    <span class="beachblue"><a href="/web/life/tag/<?=$val?>"><?=$val?></a></span>
            <?  }?>
            </div>

        <?  }?>
			<div class="panel_btns">
                <span><a href="javascript:;" class="btn btn-default br15 share_btn" style="padding:5px 30px;"><img src="/img/web/img_upload2.gif"> <span id="share_count"></span></a></span>
                <span><a href="javascript:like_proc();" class="btn btn-default br15" style="padding:5px 30px;"><img src="/img/web/img_heart.gif"> <span id="like_count"><?=number_format($result['like_count'])?></span></a></span>
            </div>
		</div>
	</div>
	<div class="life_contents">
		<? require_once(APPPATH."views/web/comm/comment_inc.php");?>
	</div>

	<? include_once ('life_footer_inc.php');?>


<? require_once(APPPATH."views/web/comm/share_box_inc.php"); ?>



<script>

$('.share_btn').click(function(e) {
	$("#share_box").toggle();
    var popH = $(this).offset().top;
    $('.popup_share').css('left','50%');
	$('.popup_share').css('top',popH+'px');

});

$(".mask").on('click', function(event){
    $(event.target).parent().hide();

});


function bookmark(){
	if("<?=$SES_MEMBER_ID?>"=="") {
        alert("로그인 후에 이용가능합니다.");
        return;
    }
	var form_data = {
		"content_idx"			: "<?=$idx?>",
		"content_type"			: "<?=$content_type?>"
	};
	$.ajax({
        url: '/web/comm/bookmark_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function (rtnJson) {
            if (rtnJson.code == "0000") {
				$("#bookmark_img").attr("src", "/img/web/star_"+rtnJson.data.bookmark_status+".png");
				$("#share_box").hide();
				if(rtnJson.data.bookmark_status == 'off') {
                    alert("북마크함에서 삭제 되었습니다");
                    return false;
                } else {
                    alert("북마크함에 추가 되었습니다");
                }
                

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

}

function like_proc(){
	if("<?=$SES_MEMBER_ID?>"=="") {
        alert("로그인 후에 이용가능합니다.");
        return;
    }
	var form_data = {
		"content_idx"			: "<?=$idx?>",
		"content_type"			: "<?=$content_type?>"
	};
	$.ajax({
        url: '/web/comm/like_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function (rtnJson) {
            if (rtnJson.result_code == "0000") {
            	var like_count = setComma(rtnJson.result_data.like_count);
				$("#like_count").html(like_count);

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

}



</script>

