
//LNB 쿠키
function fn_href(url, cd) {
    // 수정 : sdh, 2011-01-18, 테스트 사이트용 도메인 구분로직 추가
    var hostname = window.location.hostname;

    if (url == "") { alert("준비중입니다."); return; }
    //cd==108 /CustCenter/AsUpgrade
    //cd==120 /CustCenter/AsUpgrade 업그레이드 대행점안내 LNB 이동
    if (cd == 108) { cd = 120; }
    setCookie('menu_cd', cd, 1);

    var chkint = url.indexOf("http://www.inavi.com/", 0);
    var chkintS = url.indexOf("https://www.inavi.com/", 0);
    var chkMap = url.indexOf("map.inavi.com/NaviMap/MapMain", 0);

    if (url == "http://www.inavi.com/") {
        url = "http://www.inavi.com/";
    }
    else if (url == "https://www.inavi.com/") {
        url = "http://www.inavi.com/";
    }
    else if (chkint > -1) {
         url = url;
    } else {
         if (chkMap > -1) {
            url = url;
        } else {
            url = "http://" + hostname + url;
        }
    }

    if (chkintS > -1) {
        //url = url.replace("https://www.inavi.com/", "http://www.inavi.com/");
        url = url.replace("https://", "http://");
    }

    if(cd == 162 || cd ==163 || cd == 161)
    {
        //url = url.replace("http://www.inavi.com/", "https://www.inavi.com/");
        url = url.replace("http://", "https://");
    }

    location.href = url;
}


$(document).ready(function () {
   //alert("dddddd:::" + $("#Lnb_Url_Cd").val());
    var depth_02_parCd = "";
    $(".depth2").find('img').each(function (i, o) {
        if ($("#Lnb_Url_Cd").val() == $(o).attr("cd")) {
            //alert($(o).attr("cd") + ",,,,,i::;" + i);
            depth_02_parCd = $(o).attr("par_cd");
            $(o).parent().parent().addClass("selected");
            $(o).attr("src", $(o).attr("on"));
        }
    });
    $(".depth1 > a > img").each(function (i, o) {
        if (depth_02_parCd == $(o).attr("cd")) {
            //alert("par_cd:::::" + $(o).attr("cd"));
            $(o).parent().parent().addClass("selected");
            $(o).attr("src", $(o).attr("on"));
        } else if ($("#Lnb_Url_Cd").val() == $(o).attr("cd")) {
            //alert("1depthCd ::KHS:" + $(o).attr("cd"));
            $(o).parent().parent().addClass("selected");
            $(o).attr("src", $(o).attr("on"));
        }

    });

    //2depth menu mouseover
    $('ul#topnav .sub-menu  .depth3-menu li').mouseover(function () {
        var link = $(this).closest("li");
        var image = $(link).find("img");
        var imgsrc = $(image).attr("src");
        //alert(imgsrc);
        //var on = imgsrc.replace(/_off.gif$/gi, "_on.gif");

        var on = $(image).attr('on');
        // alert(on);
        //$(img).attr('src', on);

        $(image).attr("src", on);
    });

    //2depth menu mouseout
    $('ul#topnav .sub-menu .depth3-menu li').mouseout(function () {
        var link = $(this).closest("li");
        var image = $(link).find("img");
        var imgsrc = $(image).attr("off");

        //var off = imgsrc.replace(/_on.gif$/gi, "_off.gif");
        var off = $(image).attr('off');
        $(image).attr("src", off);
        //        if (!$(this).parent().hasClass('selected')) {
        //            alert("imgsrc::::" + imgsrc);
        //            // var off = imgsrc.replace(/_on.gif$/gi,'_off.gif');
        //            var off = $(img).attr('off');
        //            $(image).attr('src', off);

        //        }
    });

    initMenu();
});

/************************** SNB 실행 **************************/

function initMenu() {
    $('#menu ul').hide();
    //$('#menu ul:first').show();

    //default
    $('#menu > .selected').find('ul').css({ 'display': 'block' });

    //click
    $('#menu li a').click(
		function () {
		    var checkElement = $(this).next();
		    if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		        //return false;
		    }
		    if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		        $('#menu ul:visible').slideUp('normal');
		        checkElement.slideDown('normal');
		        //return false;
		    }
		}
	);

    //mouseover
    $('#menu li a').mouseover(
		 function () {
		     var img = $(this).find('img')
		     var imgsrc = $(img).attr('src');
		     //alert("over::"+$(img).attr('src'));
		     //var on = imgsrc.replace(/_off.gif$/gi,'_on.gif');
		     var on = $(img).attr('on');
		     $(img).attr('src', on);
		 }
	);

    //mouseout
    $('#menu li a').mouseout(
		function () {
		    var img = $(this).find('img');
		    var imgsrc = $(img).attr('off');

		    //selected 된 요소일 경우 처리
		    if (!$(this).parent().hasClass('selected')) {
		        // alert("imgsrc:eeeeeeeeeeeeee:::" + imgsrc);
		        // var off = imgsrc.replace(/_on.gif$/gi,'_off.gif');
		        var off = $(img).attr('off');
		        $(img).attr('src', off);

		    }
		}
	);

}
/************************** //SNB 실행 **************************/


$(function () {
    /************************** GNB **************************/
    function megaHoverOver() {
        $(this).find(".sub-menu").stop().fadeTo('fast', 1).show();
        $(this).find(".sub-menu").css({ "width": $(window).width() });
        //높이값 fix
        $(this).find(".sub-menu").find(".section").each(function (index) {

            var minheight = 150; //최소 높이값
            var height = $(this).eq(0).height(); //section 영역 높이값
            var twodepth = 0; //2depth 영역

            twodepth = $(this).children();

            if (height < minheight) {
                twodepth.css({ "height": minheight });
            } else {
                twodepth.css({ "height": height });
            }
        });
    }

    function megaHoverOut() {
        $(this).find(".sub-menu").stop().fadeTo('fast', 0, function () {
            $(this).hide();
        });
    }

    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 500, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    $("ul#topnav li .sub-menu").css({ 'opacity': '1' });
    $("ul#topnav li").hoverIntent(config);

    /************************** 전체보기 **************************/
    //Adjust height of overlay to fill screen when page loads
    $("#overlay").css({ "width": $(window).width(), "height": $(window).height() });

    //When the link that triggers the message is clicked fade in overlay/msgbox
    $(".fnt_control-btn-area").click(function () {
        $("#whole-menu-layer").fadeIn();
        $('#overlay').delay(800).css({ 'display': 'block', 'opacity': '0.5' });
        return false;
    });

    //When the message box is closed, fade out
    $(".whole-pop-close").click(function () {
        $("#whole-menu-layer").delay(800).css({ 'display': 'none' });
        $('#overlay').delay(800).css({ 'display': 'none' });
        return false;
    });

    //Adjust height of overlay to fill screen when browser gets resized
    $(window).bind("resize", function () {
        $("#overlay").css("height", $(window).height());
    });
    /************************** //전체보기 **************************/


});

/************************** 로그인 **************************/
function fnLoginChk() {
    if ($("#txtUserID2").val() == "") {
        alert("아이디을(를) 입력하세요.");
        $("#txtUserID2").focus();
        return false;
    }
    if ($("#txtPassword2").val() == "") {
        alert("비밀번호을(를) 입력하세요.");
        $("#txtPassword2").focus();
        return false;
    }

    var tmppassPW = $("#txtPassword2").val();
    var passPW = tmppassPW.replace(/&/gi, ';');

    //fnAjax("/Members/Login/LoginChk?userid=" + $("#txtUserID2").val() + "&password=" + $("#txtPassword2").val(), location.href);
    fnAjax("/Members/Login/LoginChk?userid=" + $("#txtUserID2").val() + "&password=" + passPW, location.href);

    return false;
}
function fnLogOut() {
    var hostname = window.location.hostname;
    location.href = "http://"+ hostname +"/Members/Login/Logout";
}
function fnMemberGo(gubun) {
    var hostname = window.location.hostname;
    if (gubun == "1")
        location.href = "https://"+ hostname +"/Members/PersonalInfo/";
    else
        location.href = "http://"+ hostname +"/Members";
}
/************************** //로그인 **************************/

/***********************************************************/

function fnGoLogin(url) {
    var hostname = window.location.hostname;
    alert("로그인이 필요한 서비스 입니다.\n로그인 후 이용해주세요.");
    location.href = "http://" + hostname + "/Members/Login/?reurl=" + encodeURIComponent(url);
}

function fnGoLoginMenu(url, cd) {
    var hostname = window.location.hostname;
    alert("로그인이 필요한 서비스 입니다.\n로그인 후 이용해주세요.");
    setCookie('menu_cd', cd, 1);
    location.href = "http://" + hostname + "/Members/Login/?reurl=" + encodeURIComponent(url);
}

function fnDiquestSearch(keyword) {

    location.href = "/Search/Search/Total?search_term=" + encodeURIComponent(keyword);
}

function fntxtDiquestSearch() {

    var searchtxt = $("#txtDiquest").val();

    if (searchtxt == "") {
        alert("검색어를 입력하세요");
    }
    else {
        location.href = "/Search/Search/Total?search_term=" + encodeURIComponent(searchtxt);
    }
}

//상단 인기검색어 이전/다음
function fnSearchPrevNext(curpage, topsize) {
    $.getJSON("/Home/Keyword", { cur: curpage, tops: topsize }, function (data) {
        $(".header_cont .search_area .keyword").remove();
        $(".header_cont .search_area .btn-set").remove();

        $(".header_cont .search_area").append(data);
    });
}
