<?
# session
$SES_MEMBER_ID              = $this->session->userdata('C_Member_Id');
$SES_MEMBER_NAME            = $this->session->userdata('C_Member_Name');
$SES_MEMBER_NICNAME         = $this->session->userdata('C_Member_Nicname');
$SES_MEMBER_PROFILE         = $this->session->userdata('C_Member_Profile');
$SES_MEMBER_GROUPNAME       = $this->session->userdata('C_Member_Group_Name');
$SES_MEMBER_INTRO           = $this->session->userdata('C_Member_Intro');
$SES_MEMBER_EMAIL           = $this->session->userdata('C_Member_Email');

if($SES_MEMBER_PROFILE == '')   $SES_MEMBER_PROFILE = '/img/web/img_profile_l.png';
if($SES_MEMBER_NICNAME == '')   $SES_MEMBER_NICNAME = $SES_MEMBER_NAME;

$controller = $this->uri->segment(2);
$method = $this->uri->segment(3);
if($controller != 'search') {
    $search_keyword = '';
}
$content_type    = trim($this->input->get_post('content_type', TRUE));


$ci=& get_instance();

# 영적기상도
$ci->load->model('web/m_weather');
$arr_weather = $ci->m_weather->weather_join_relation_article_limit1();

# 실시간급상승 검색어
$ci->load->model('web/m_realtime_keyword');
$arr_realtime_keyword    = $ci->m_realtime_keyword->realtime_keyword_all_list();

$return_data['arr_realtime_keyword']        = $arr_realtime_keyword;

?>

<div class="top">
	<div class="wrap">
		<div class="area_links">
			<span><a href="javascript:bookmark_site('<?=$site_info['homepage_title']?>', 'http://crossmap.co.kr')">즐겨찾기</a> </span>
			<span class="bar"><img src="/img/web/mypage_bar.gif" alt=""></span>
			<span><a href="/web/cs/faq_view/33?search_keyword=&search_category1=31&search_category2=02&data_num=2">시작페이지로</a> </span>
		</div>


<? if($SES_MEMBER_ID=='') {?>
		<div class="area_ingo">
			<span><a href="javascript:commonLayerOpen('login_layer')">로그인</a> </span>
			<span class="bar"><img src="/img/web/mypage_bar.gif" alt=""></span>
			<span ><a href="/m/" class="current" target="_blank">모바일 보기</a> </span>
			<span class="social">
				<a href="/"><img src="/img/web/img_home.png" alt="home"></a>
				<a href="https://www.facebook.com/crossmapkr/" target="_blank"><img src="/img/web/img_facebook.png" alt="facebook"></a>
				<a href="https://www.instagram.com/crossmapkr/" target="_blank"><img src="/img/web/img_instagram.png" alt="instagram"></a>
			</span>
		</div>
<? } else {?>
		<div class="news_ingo">
			<span class="profile"><img src="<?=$SES_MEMBER_PROFILE?>" alt="profile" width="21" width="21"></span>
			<span class="arrow"><a href="javascript:change_toggle('mybox');"><span class="beachblue"><?=$SES_MEMBER_NICNAME?></span> 님</a> </span>
			<span class="bar"><img src="/img/web/mypage_bar.gif" alt="info"></span>
			<span class="beachblue"><a href="/m/" target="_blank">모바일 보기</a> </span>
			<span class="social">
				<a href="/"><img src="/img/web/img_home.png" alt="home"></a>
				<a href="https://www.facebook.com/crossmapkr"><img src="/img/web/img_facebook.png" alt="facebook"></a>
				<a href="https://www.instagram.com/crossmapkr/"><img src="/img/web/img_instagram.png" alt="instagram"></a>
			</span>
		</div>
        <? require_once(APPPATH."views/web/comm/mybox_inc.php"); ?>
<? }?>

	</div>	<!--wrap-->
</div><!--top-->

<div class="header">
	<div class="special">
		<div class="wrap">
			<div class="logo">
				<a href="/"><img src="/img/web/logo.jpg" alt="logo"></a>
			</div>
			<div class="search">
            <form name="search_form" id="search_form" method="get" action="/web/search/" onsubmit="return submit_check(); return false;">
				<input type="text" class="window" id="search_keyword" name="search_keyword" value="<?=$search_keyword?>" onkeyup="onkeyup_search_keyword(this.value);">
				<span id="search_arrow" class="src_icon arrow_down_on"></span>
				<div class="src_sumit" style="cursor:pointer;" onclick="search_keyword_proc('')" id="search_btn">
                    <img src="/img/web/img_search.gif" style="padding-left: 10px; padding-top: 9px;">
                </div>
            </form>
			</div>
            <div class="open_search" id="search_keyword_box" style="display:none">
                <div class="roll_box" id="search_keyword_list"></div>
            </div>
        </div>
    </div>

    <div class="section_navbar">
        <div class="wrap">

<? if($controller == 'search' || $controller == 'news') {?>
        <? if($controller=='search') {?>
            <ul class="menu">
                <li><a href="/web/search/?search_keyword=<?=urlencode($search_keyword)?>"  <? if($method=='') { echo 'class="current"';}?>>통합검색 </a></li>
                <li><a href="/web/search/image?search_keyword=<?=urlencode($search_keyword)?>" <? if($method=='image') { echo 'class="current"';}?>>이미지 </a></li>
                <li><a href="/web/search/list?search_keyword=<?=urlencode($search_keyword)?>&content_type=3" <? if($content_type=='3') { echo 'class="current"';}?>>라이프</a></li>
                <li><a href="/web/search/news?search_keyword=<?=urlencode($search_keyword)?>" <? if($method=='news') { echo 'class="current"';}?>>뉴스</a></li>
                <li><a href="/web/search/video?search_keyword=<?=urlencode($search_keyword)?>" <? if($method=='video') { echo 'class="current"';}?>>동영상</a></li>
                <li><a href="/web/search/list?search_keyword=<?=urlencode($search_keyword)?>&content_type=2" <? if($content_type=='2') { echo 'class="current"';}?>>칼럼</a></li>
            </ul>
        <? } else {?>

            <ul class="menu">
                <li><a href="/">홈</a></li>
                <li><a href="/web/life/">라이프 </a></li>
                <li><a href="/web/news/" class="current">뉴스</a></li>
            </ul>

        <? }?>


            <!--div class="condition" id="cross_header_weather" style="display:none">
				<span class="tt">영적기상도 </span>
            <ul>
		<?
			foreach ($arr_weather as $val) {
		?>
				<li style="height:40px;cursor: pointer" onclick="location.href='/web/news/news_view/<?=$val['relation_article_idx']?>'">
                    <span class="country"><?=$val['continent']?></span>
                    <span><?=$val['country']?><span class="weather"><img src="<?=$val['weather_icon']?>" width="22"></span> <?=$val['weather_content']?></span>
				</li>

        <?	}?>
		  	</ul>

            </div-->

<?  } else {?>

            <ul class="menu">
                <li><a href="/" <? if($controller=='') { echo 'class="current"'; }?> >홈</a></li>
                <li><a href="/web/life/" <? if($controller=='life') { echo 'class="current"'; }?>>라이프 </a></li>
                <li><a href="/web/news/" <? if($controller=='news') { echo 'class="current"'; }?>>뉴스</a></li>
            </ul>
            <div class="roll" id="roll_realtime_keyword" style="display:none">
            <ul>
        <?
            foreach ($arr_realtime_keyword as $key=>$val) {
                $keyword = mb_strimwidth($val['keyword'], '0', '25', '..', 'utf-8');
        ?>
                <li>
                    <span class="number beachblue"><?=$val['rank']?></span>
                    <span class="roll_txt"><a href="/web/search/?search_keyword=<?=urlencode($keyword)?>"><?=$keyword?></a></span>
                    <span><a href="javascript:change_toggle('realtime_rank');"><img src="/img/web/roll_down.gif"></a></span>
                </li>
        <?
                }
        ?>
            </ul>
            </div>

            <div class="open_roll" id="realtime_rank" style="display:none">
                <div class="txt">실시간 급상승</div>
                <ul class="ranking">
                  <li style="width:48%"><a href="javascript:change_realtime_rank(1);" id="realtime_btn1" class="current">1-10위</a></li>
                  <li style="width:2%"><img src="/img/web/img_ranking.gif"></li>
                  <li style="width:48%"><a href="javascript:change_realtime_rank(2);" id="realtime_btn2">11-20위</a></li>
                </ul>
                <ul class="roll_box" id="realtime_keyword_list1">
            <?
                foreach ($arr_realtime_keyword as $key=>$val) {

                    if($key == 10) echo '<ul class="roll_box" id="realtime_keyword_list2" style="display:none">';

                    $last_rank  = $val['last_rank'];
                    $rank       = $val['rank'];

                    $class = '';
                    $last_rank_txt = '';
                    if($last_rank==0){
                        $class = 'new';
                        $last_rank_txt = 'NEW';
                    } else {
                        $calc_rank = $last_rank - $rank;
                        if($calc_rank == 0){   // 같음
                            $last_rank_txt = '-';
                        } else if($calc_rank > 0){   // up
                            $last_rank_txt = '<img src="/img/web/btn_up.jpg">'.$calc_rank;
                        } else {
                            $last_rank_txt = '<img src="/img/web/btn_down.jpg">'.abs($calc_rank);
                        }
                    }

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


            ?>
                    <div>
                        <div class="issue_box">
                            <span class="no"><?=$rank?></span>
                            <span><a href="/web/search/?search_keyword=<?=urlencode($val['keyword'])?>"><?=$keyword?></a></span>
                            <span class="bbox <?=$class?> updown"><?=$last_rank_txt?></span>
                        </div>
                    </div>


            <?
                    if($key == 9)   echo '</ul>';


                } ?>

                </ul>
            </div>

<?  }?>

            </div>
    </div><!--//section_navbar-->
</div><!--//header-->


<script type="text/javascript">
$(function() {
<? if($controller == 'search' || $controller == 'news') {?>
    $('#cross_header_weather').show();
	$('#cross_header_weather').vTicker();
<? } else {?>

	<?//20180808 높이 조정문제 수정을 위해 시차 조정?>
	$(document).ready(function() {
		$('#roll_realtime_keyword').show();
		$('#roll_realtime_keyword').vTicker();
	});


<?  }?>
});

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

    var container = $("#realtime_rank");
    if( container.has(e.target).length === 0)   container.hide();

    var container = $("#search_keyword_box");
    if( container.has(e.target).length === 0){
        container.hide();
        $("#search_arrow").removeClass();
        $("#search_arrow").addClass('src_icon arrow_down_on');
    }
});

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

});


// 실시간급상승
function change_realtime_rank(page){
    $("#realtime_keyword_list1").hide();
    $("#realtime_keyword_list2").hide();
    $("#realtime_keyword_list"+page).show();


    $("#realtime_btn1").removeClass();
    $("#realtime_btn2").removeClass();
    $("#realtime_btn"+page).addClass('current');

}


// 검색
function onkeyup_search_keyword(val){
    if(val == '') {            
        $("#search_arrow").removeClass();
        $("#search_keyword_list").empty();
        $("#search_keyword_box").hide();
        $("#search_arrow").addClass('src_icon arrow_down_on');
    } else {
        var form_data = {
            "keyword"	: val
        };
        console.log("this data is "+JSON.stringify(form_data));
        $.ajax({
            url: '/web/search/search_keyword',
            type: 'POST',
            dataType: 'JSON',
            data: form_data,
            success: function (rtnJson) {
                console.log("retrun Json code"+ JSON.stringify(rtnJson));
                if (rtnJson.code == "0000") {
                    var count = rtnJson.data.length;
                    var content = '';
                    for(var i=0;i<count;i++) {
                        var result = rtnJson.data[i];
                        var result_keyword = result.keyword;
                        keyword = result_keyword.replace(val, '<span class="on">'+val+'</span>')
                        content+= ' <div><span><a href="javascript:search_keyword_proc(\''+result_keyword+'\');">'+keyword+'</a></span><span class="close fr"></span><span class="date fr"></span></div>';
                    }
                    $("#search_keyword_list").html(content);
                    $("#search_arrow").removeClass();
                    $("#search_keyword_box").show();
                    $("#search_arrow").addClass('src_icon arrow_up_on');
                } else {
                    $("#search_arrow").removeClass();
                    $("#search_keyword_list").empty();
                    $("#search_keyword_box").hide();
                    $("#search_arrow").addClass('src_icon arrow_down_on');
                }
            },
            error: function (rtnJson) {
            }
        });
    }
}

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

function search_keyword_proc(search_keyword){
    if(search_keyword == '') {
        search_keyword = $("#search_keyword").val();
    }
    
    var result = true;
    if(search_keyword!='')  result = search_keyword_reg(search_keyword);
    if(result==true) {
        $("#search_keyword").val(search_keyword);
        $("#search_form").submit();
    }

}


// 즐겨찾기
function bookmark_site(title,url) {
    if(window.chrome){  // Google Chrome
      alert("Ctrl+D키를 누르시면 즐겨찾기에 추가하실 수 있습니다.");
   } else if (window.sidebar) { // firefox
       window.sidebar.addPanel(title, url, "");
   } else if(window.opera && window.print) { // opera
      var elem = document.createElement('a');
      elem.setAttribute('href',url);
      elem.setAttribute('title',title);
      elem.setAttribute('rel','sidebar');
      elem.click();
   } else if(window.external) {   // Internet Explorer
        window.external.AddFavorite(url, title);
    }
}

</script>

