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

$ci=& get_instance();

$ci->load->library('comm');
$arr_news_comm = $ci->comm->fn_news_right();

$arr_main_news          = $arr_news_comm['arr_main_news'];
$arr_recomm_column      = $arr_news_comm['arr_recomm_column'];
$arr_recomm_life        = array(); //$arr_news_comm['arr_recomm_life'];
$arr_life_ranking       = $arr_news_comm['arr_life_ranking'];
// $arr_p_photo            = $arr_news_comm['arr_p_photo'];
// $arr_p_video            = $arr_news_comm['arr_p_video'];
$arr_realtime_keyword   = $arr_news_comm['arr_realtime_keyword'];

$ci->load->model('life_model');
$ci->load->helper('general');
$lifeRecommends = $ci->life_model->findByCategoryId(array_flatten($ci->config->item('categories')))
->order_by('like_count', 'desc')->limit(3)->get()->result_array();

foreach ($lifeRecommends as $val) {
array_push($arr_recomm_life,
	array('title' => $val['title'], 'sub_content' => $val['sub_title'],
		'main_img' => $val['mainImg'], 'content_idx' => $val['idx']));
}

$main_news_class = 'section';
$main_news_style='';
if($controller == 'search') {
	$main_news_class = 'lifepopular';
	$main_news_style = 'style="margin-top:0"';
}
?>


<div class="list_right">
    <?php  if($method == 'column') { echo '<div style="height:20px"></div>'; } ?>
    <?php  if($controller !='search') { ?>
    <div class="banner2"><a href="https://www.christiantoday.co.kr/" target="_blank"><img src="<?php echo imgSrc('/img/web/banner_0217.jpg')?>"></a>
    </div>
    <?php  } ?>

    <div class="<?php echo $main_news_class?>" <?php echo $main_news_style?>>
        <h4>주요뉴스</h4>

        <?php 
				$i=1;
				$main_news_count 	= count($arr_main_news);
				$main_news_page 	= ceil($main_news_count/10);
				foreach ($arr_main_news as $key=>$val) {

					$curr_page = ceil($i/10);


					$title_txt = mb_strimwidth($val['title'], '0', '38', '..', 'utf-8');
					$display_style = 'block';
					if($i > 10)	$display_style = 'none';
			?>
        <div class="section_box main_news_page<?php echo $curr_page?>" style="display:<?php echo $display_style?>">
            <span class="no"><?php echo $val['rank']?></span>
            <span><a href="/web/news/news_view/<?php echo $val['content_idx']?>/<?php echo  cleanUrl($val['title'])?>"><?php echo $title_txt?></a></span>
        </div>
        <?php 
					$i++;
				}


				if($main_news_count > 10) {
			?>
        <div class="viewall">
            <span>
                <a href="javascript:change_main_news_page(-1)"><img src="<?php echo imgSrc('/img/web/img_section_left.jpg')?>"></a><a href="javascript:change_main_news_page(1)"><img src="<?php echo imgSrc('/img/web/img_section_right.jpg')?>"></a>
            </span>
        </div>
        <?php 	}?>
    </div>
    <?php  if($controller !='search') {?>



    <div class="recommend">
        <h4>추천연재</h4>
        <?php    foreach ($arr_recomm_column as $val) {

           			$title_txt = mb_strimwidth($val['title'], '0', '60', '..', 'utf-8');
           	?>



        <div class="recommend_box">
            <div class="art-info">
                <a href="/web/news/columnist/<?php echo $val['partner_idx']?>/<?php echo  cleanUrl($val['title'])?>"><span class="tit"> <?php echo $val['column_name']?></a></span>
                <div><a href="/web/news/column_view/<?php echo $val['content_idx']?>/<?php echo  cleanUrl($val['title'])?>"><?php echo $title_txt?></a></div>
            </div>
            <div class="art-img" onclick="location.href='/web/news/column_view/<?php echo $val['content_idx']?>/<?php echo  cleanUrl($val['title'])?>'"
                style="cursor: pointer;width:62px;width:62px; height:62px; background:url('<?php echo $val['theme_img']?>') no-repeat center; background-size:cover;"></div>
        </div>

        <?php   }?>

    </div>

    <?php 	}?>

    <?php  if($method == 'news_view') {?>

    <div class="banner2"><a
            href="https://www.yanadoo.co.kr/freepass/neverGiveupNew?&utm_source=criteo_pc&utm_medium=da_criteo&utm_campaign=%EB%A6%AC%ED%83%80%EA%B2%9F%ED%8C%85&utm_content=%EC%B4%88%ED%8A%B9%EA%B0%80"
            target="_blank"><img src="<?php echo imgSrc('/img/web/banner1_0204.jpg')?>"></a>
        <!-- PC_라이프_우측하단 
<ins class="adsbygoogle"
     style="display:inline-block;width:250px;height:250px"
     data-ad-client="ca-pub-7071495522658800"
     data-ad-slot="1272145884"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script> -->
    </div>


    <?php 	} else {?>
    <!--<div class="issue">
					<h4>실시간 급상승</h4>
            <?php   $i=1;
                foreach ($arr_realtime_keyword as $val) {
                    if($i==1)   echo '<div style="float:left; width:48%; padding-right:2%">';
                    if($i==6)   echo '<div style="float:left; width:48%; padding-left:2%">';

                    $keyword_txt = mb_strimwidth($val['keyword'], '0', '17', '..', 'utf-8');

            ?>
                    <div class="issue_box">
                        <span class="no"><?php echo $i?></span>
                        <span><a href="/web/search/?search_keyword=<?php echo urlencode($val['keyword'])?>"><?php echo $keyword_txt?></a></span>
                    </div>

            <?php 
                    if($i==5 || $i==10 || $i == count($arr_realtime_keyword)) echo '</div>';

					if($i==10)	break;


                    $i++;
                }?>

				</div>-->
    <?php 	}?>
    <?php $this->load->view('cmtv/news_side_box'); ?>

    <div class="section">
        <h4>크로스맵 인기글 </h4>


        <?php 
				$i=1;
				$life_ranking_count 		= count($arr_life_ranking);
				$life_ranking_page 	= ceil($life_ranking_count/10);
				foreach ($arr_life_ranking as $key=>$val) {

					$curr_page = ceil($i/10);

					$title_txt = mb_strimwidth($val['title'], '0', '38', '..', 'utf-8');
					$display_style = 'block';
					if($i > 10)	$display_style = 'none';
			?>
        <div class="section_box life_ranking_page<?php echo $curr_page?>" style="display:<?php echo $display_style?>">
            <span class="no"><?php echo $val['rank']?></span>
            <span><a href="/web/life/life_view/<?php echo $val['content_idx']?>/<?php echo  cleanUrl($val['title'])?>"><?php echo $title_txt?></a></span>
        </div>

        <?php 
					$i++;
				}


				if($life_ranking_count > 10) {
			?>
        <div class="viewall">
            <span><a href="javascript:change_life_ranking_page(-1)"><img src="<?php echo imgSrc('/img/web/img_section_left.jpg')?>"></a><a href="javascript:change_life_ranking_page(1)"><img
                        src="<?php echo imgSrc('/img/web/img_section_right.jpg')?>"></a></span>
            <span style="float:right; font-size:13px;"><a href="/web/life/ranking">전체보기 &gt;</a> </span>
        </div>

        <?php 	}?>

    </div>
    <?php  if($controller !='search') {?>
    <div class="life">
        <h4>추천 콘텐츠</h4>
        <?php 
				$i=1;
				foreach ($arr_recomm_life as $val) {
					$class = 'i-cover2';
					$height = '134';
					$title_len = '15';
					if($i==1) {
						$class = 'i-cover';
						$height = '268';
						$title_len = '40';
					}

					$title_txt = mb_strimwidth($val['title'], '0', $title_len, '..', 'utf-8');


		?>
        <div class="<?php echo $class?>" onclick="location.href='/web/life/life_view/<?php echo $val['content_idx']?>'" style="cursor: pointer">
            <span class="shadow"></span>
            <div style="width:<?php echo $height?>px; height:163px; background:url('<?php echo imgSrc($val['main_img'])?>') no-repeat center; background-size:cover;"></div>
            <p class="txt"><?php echo $title_txt?></p>
        </div>

        <?php 
					if($i > 2) break;
					$i++;

				}
		?>

    </div>
    <?php 	}?>

</div>


<script>
$(document).ready(function() {
    setInterval("popular_media_interval()", 7000);
});

var main_news_curr_page = 1;

function change_main_news_page(page) {
    var total_page = "<?php echo $main_news_page?>";
    var move_page = main_news_curr_page + page;
    if (move_page > 0 && total_page >= move_page) {
        $(".main_news_page" + move_page).show();
        $(".main_news_page" + main_news_curr_page).hide();
        main_news_curr_page = move_page;
    }
}


var life_ranking_curr_page = 1;

function change_life_ranking_page(page) {
    var total_page = "<?php echo $life_ranking_page?>";
    var move_page = life_ranking_curr_page + page;
    if (move_page > 0 && total_page >= move_page) {
        $(".life_ranking_page" + move_page).show();
        $(".life_ranking_page" + life_ranking_curr_page).hide();
        life_ranking_curr_page = move_page;
    }
}

function change_popular_media(id) {
    $("#popular_photo").hide();
    $("#popular_video").hide();
    $("#" + id).show();
}


function popular_media_interval() {
    $("#popular_photo").toggle();
    $("#popular_video").toggle();
}
</script>