<?php
$method =  $this->uri->segment(3);

$content_type = '3';

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

$logo_url = '/';
if($method=='editor' || $method=='channel') {
	$logo_url = '/web/life/channel_recommend';
}

?>

	<div class="channel_header">
		<div class="wrap_cover">
		<? if($method=='editor') {?>
			<div class="cover_image" style="background: url(<?=$editor_main_img?>) no-repeat left top; display: block;background-size: cover;height:310px;background-position: 50% 50%;"></div>
		<?	} else {?>
			<div class="cover_image" style="background: url(<?=$channel_main_img?>) no-repeat left top; display: block;background-size: cover;height:310px;background-position: 50% 50%;"></div>
		<?	}?>
			<div class="cover_inner"></div>
			<div class="cover_top" style="z-index:9995;">
				<h1 class="channel_logo"><a href="/"><img src="/img/web/logo_channel.png"></a></h1>
		<? 	if($method=='channel') {?>
				<a href="/web/life/channel/<?=$channel_idx?>"><span class="channel_title"><?=$channel_name?></span></a>
		<?	} else {?>
				<span class="channel_title"><a href="/web/life/editor/<?=$partner_idx?>"><?=$editor_name?></a></span>
		<?	}?>
				<span class="channel_search"></span>
				<span class="channel_menu"><a href="javascript:;"><img src="/img/web/search_menu.png" class="side_menu_btn"></a></span>
				<div class="channel_search" id="life_search1" style="z-index:8887;"><a href="javascript:search_show();"><img src="/img/web/search_channel.png"></a></div>
				<div class="srch2" id="life_search2" style="z-index:8888;display:none;">
					<form name="search_form" id="search_form" action="/web/search/" method="get" onsubmit="return submit_check(); return false;">
					<span>
						<input type="text" name="search_keyword" id="search_keyword">
						<a href="javascript:search();"><img src="/img/web/search_channel2.png" alt="검색하기"></a>
					</span>
					</form>
				</div>

			</div>
		</div>
		<div class="wrap_channel">

		<? if($method=='channel') {
				$channel_delivery_btn = '/img/web/bt_delivery_off_white.png';
				if($channel_delivery_count > 0) {
					$channel_delivery_btn = '/img/web/bt_delivery_on_white.png';
				}

		?>
			<div class="cover_cell">
				<div>
					<p style="margin-bottom:15px;"><span style="background: url('/img/web/bgbg3.png') repeat-x left bottom;  padding-bottom:8px;"><a href="/web/life/category/<?=$category_idx?>"><?=$category_name?></a></span></p>
					<p><img src="/img/web/img_home_c.png"><span class="chdate"><?=number_format($total_count)?> Stories</span></p>
				</div>
				<div class="titlewrap">
					<div class="title_profile" style="border-radius: 39px;width:39px;height:39px;background:url('<?=$channel_icon?>') no-repeat center; background-size:cover;"></div>
					<span class="chtit"><?=$channel_name?></span>
					</div>
				<p class="chtxt"><?=$channel_intro?></p>
				<p class="delivery_top"><?=number_format($channel_delivery_total_count)?>명에게 배달중</p>
			</div>

		<?	} else if ($method=='editor'){?>


			<div class="cover_cell">
				<div>
					<p style="margin-bottom:15px;"><span style="background: url('/img/web/bgbg3.png') repeat-x left bottom;  padding-bottom:8px;"><a href="/web/life/category/<?=$category_idx?>"><?=$category_name?></a> <img src="/img/web/bg5.gif" style="padding: 2px 5px 0 5px;"> <a href="/web/life/channel/<?=$channel_idx?>"><?=$channel_name?></a></span></p>
					<p><img src="/img/web/img_home_c.png"><span class="chdate"><?=number_format($total_count)?> Stories</span></p>
				</div>
				<h2 class="chtit"><a href="/web/life/editor/<?=$partner_idx?>"><?=$editor_name?></a></h2>
				<p class="chtxt"><?=$editor_intro?></p>
			</div>
			<div class="cover_profile">
				<div style="margin:auto;border-radius: 88px;width:88px;height:88px;background:url('<?=$partner_img?>') no-repeat center; background-size:cover;"></div>
			</div>
			<div class="cover_social">
				<a href="/web/life/editor/<?=$partner_idx?>"><img src="/img/web/f_icon1.png" alt="" title=""></a>
				<? if($sns_id1!='') { ?><a href="https://www.facebook.com/<?=$sns_id1?>" target="_blank"><img src="/img/web/f_icon3.png"></a><? }?>
				<? if($sns_id2!='') { ?><a href="https://instagram.com/<?=$sns_id2?>" target="_blank"><img src="/img/web/f_icon2.png"></a><? }?>
				<? if($sns_id3!='') { ?><a href="https://band.us/band/<?=$sns_id3?>" target="_blank"><img src="/img/web/f_icon8.png"></a><? }?>
				<? if($sns_id4!='') { ?><a href="https://story.kakao.com/ch/<?=$sns_id4?>" target="_blank"><img src="/img/web/f_icon6.png"></a><? }?>
				<? if($sns_id5!='') { ?><a href="https://story.kakao.com/<?=$sns_id5?>" target="_blank"><img src="/img/web/f_icon7.png"></a><? }?>
			</div>


		<?	} else {?>
			<div class="cover_cell">
				<div>
					<p style="margin-bottom:15px;"><span style="background: url('/img/web/bgbg3.png') repeat-x left bottom;  padding-bottom:8px;"><a href="/web/life/category/<?=$category_idx?>"><?=$category_name?></a> <img src="/img/web/bg5.gif" style="padding: 2px 5px 0 5px;"> <a href="/web/life/channel/<?=$channel_idx?>"><?=$channel_name?></a></span></p>
				</div>
				<h2 class="chtit"><?=$title?></h2>
				<p class="chdate">
					<? if($sub_title != '') {
						echo $sub_title.' <span style="padding:0 10px;">|</span>';

					} ?><p class="chdate">조회 <?=number_format($hit_count)?><span style="padding:0 10px;">|</span><?=substr($display_date, 0, 10)?> </p>
				<p class="cheditor"><a href="/web/life/editor/<?=$partner_idx?>"><?=$editor_name?></a></p>
			</div>
			<div class="cover_profile2" onclick="location.href='/web/life/editor/<?=$partner_idx?>'" style="cursor: pointer">
                <div style="margin:auto;border-radius: 65px;width:65px;height:65px;background:url('<?=$partner_img?>') no-repeat center; background-size:cover;"></div>
            </div>

		<?	}?>

        <? if($method == 'life_view') {?>
			<div class="cover_star">
				<a href="javascript:bookmark();"><img src="<?=$bookmark_img?>" id="bookmark_img"></a>
			</div>
        <?  } else if($method == 'channel') {?>
			<div class="cover_star">
				<a href="javascript:channel_delivery();"><img src="<?=$channel_delivery_btn?>" id="channel_delivery_btn"></a>
			</div>

		<?	}?>
		</div>
	</div>

<script>
// 레이어 이외의 공간 클릭시 close
$(document).mouseup(function (e){
    var container = $("#life_search2");
    if( container.has(e.target).length === 0)   container.hide();
	$("#life_search1").show();
});



$('.side_menu_btn').click(function(e) {
	var element = $(".channel_header");
	var doc_width = element.width();

	$("#side_menu_layer").toggle();
    var popH = $(this).offset().top;
    $("#side_menu_layer").css('top','0px');
	$("#side_menu_layer").css('left',doc_width+'px');

});

function submit_check() {
    if(!$("#search_keyword").val()) {
        alert('검색어를 입력하세요.');
        return false;
    } else {
        return true;
    }
}

function search(){
    $('#search_form').submit();
}

function search_show(){
	$("#life_search1").hide();
	$("#life_search2").show();
	$("#search_keyword").focus();
}

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

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

}





</script>
