/* Global Navigation Bar */
function gnbFnc(){
var topmenu = $('.topmenu');
var topmenus = topmenu.find('li.topbtn');
var topmenusA = topmenus.find('a');
var topmenusUl = topmenus.find('ul');
topmenus.bind('mouseenter',function(){
topmenusA.removeClass('hover')
topmenus.removeClass('on');
$(this).addClass('on');
topmenusUl.stop().animate({"height": 240 + "px","padding-top": 10 + "px"},300);
})
topmenu.bind('mouseleave focusout',function(e){
topmenusUl.stop().animate({"height": 0 + "px","padding-top": 0 + "px"},300)
topmenus.removeClass('on');
})
topmenusA.bind('focusin',function(){
topmenus.removeClass('on');
topmenusA.removeClass('hover')
$(this).addClass('hover').closest('.topbtn').addClass('on')
topmenusUl.stop().css({"height": 240 + "px","padding-top": 10 + "px"},300);
})
}
function gnb(dep1, dep2, dep3){
var $header = $("#header_wrap");
var $gnb = $(".topmenu");
var $gnb_1dep = $(".topmenu > li");
var $gnb_2dep = $(".topmenu > li > ul > li");
$header.css({'height':'96px'});
if (dep1) {
$gnb_1dep.eq(dep1-1).addClass('active').attr('title','현재 활성화 되어있는 1차 메뉴입니다.');
if (dep2) {
$gnb_1dep.eq(dep1-1).find('ul li').eq(dep2-1).find('a').addClass('active2').attr('title','현재 활성화되어 있는 2차 메뉴입니다.');
}
}
/* //gnb 리셋 */
function lnb(dep1, dep2){
$('body').append("");
var temp_lnb = $('#temp_lnb');
var $lnb = $('.lnb'),
$lnbBox = $('.leftmenu'),
$lnb_1dep = $('.lnb > li'),
$lnb_2dep = $('.lnb li .lnb_dep2 > li'),
$onLnb_1dep = $lnb_1dep.eq(dep1-1),
$onLnb_2dep = $lnb_1dep.eq(dep1-1).find('.lnb_dep2'),
$lnb_1depBtn = $lnb_1dep.find('>a'),
dep1Cnt = dep1,
dep2Cnt = dep2
//$lnb_1dep.find('img').clone().appendTo(temp_lnb)
$lnb_1dep.find('img').each(function(){
$(this).clone().appendTo(temp_lnb);
$(this).clone().attr('src',on).appendTo(temp_lnb);
})
temp_lnb.remove();
$('.lnb_dep2').hide();
function initLnb(){
//$('.lnb_dep2').css('display','none');
//$('.lnb_dep2').stop().slideUp();
$('.lnb_dep2').hide();
$lnb_1dep.removeClass('on').find('> a > img').each(off)
$lnb_1dep.eq(dep1-1).addClass('on').find('> a > img').each(on);
if(dep2){
//$onLnb_2dep.css('display','block');
//$onLnb_2dep.slideDown();
$onLnb_2dep.show();
$onLnb_2dep.find('li').eq(dep2-1).addClass('on').find('> a > img').each(on);
}
}
initLnb();
$lnb_1dep.bind('click', function(e){
//if( $(this).index() != dep1 - 1){
e.stopPropagation();
//$lnb_1dep.find('> a > img').each(off);
$(this).siblings().find('> a > img').each(off);
$(this).find('> a > img').each(on); // 2013-08-27
$(this).addClass('active');
//$(this).closest('li').siblings().find('ul').stop().slideUp();
$(this).closest('li').siblings().find('ul').stop().hide();
//$(this).find('ul').slideDown();
$(this).find('ul').show();
//}
});
$(window).bind('keyup',function(e){if(e.keyCode == 16){isTab = false}})
$lnb_1dep.find('>a').bind('keydown',function(e){
if($(this).parent().index() != 0){
if(e.keyCode == 9 && e.shiftKey){
e.preventDefault();
$lnb_1dep.eq($(this).closest('li').index() - 1).find(' > a').trigger('focus').next('ul.lnb_dep2').find('li:last-child > a').focus();
}
}
})
$lnb_1dep.bind('focusin', function(e){
//if( $(this).index() != dep1 - 1){
e.stopPropagation();
$lnb_1dep.find('> a > img').each(off);
$(this).find('> a > img').each(on); // 2013-08-27
$(this).addClass('active');
$(this).closest('li').siblings().find('ul').stop().hide();
$(this).find('ul').stop().show();
//}
});
$lnb_2dep.bind('mouseenter focusin', function(e){
if( !$(this).hasClass('on')){
$onLnb_2dep.find('li').removeClass('on');
$(this).find('> a > img').each(on); // 2013-08-27
$(this).addClass('on');
}
});
$lnb_2dep.bind('mouseleave focusout', function(e){
//if( !$(this).hasClass('on')){
$(this).removeClass('on');
$(this).find('> a > img').each(off);
//}
});
$lnbBox.bind('mouseleave',function(e){
initLnb();
})
$('ul.location li:first-child a').bind('focusin',function(){
$('.lnb_dep2').hide();
$lnb_1dep.find('> a > img').each(off);
$lnb_1dep.eq(dep1-1).addClass('on').find('> a > img').each(on);
if(dep2){
$onLnb_2dep.show();
$onLnb_2dep.find('li').eq(dep2-1).addClass('on').find('> a > img').each(on);
}
})
$lnb.find('li').eq(0).find('>a').bind('keydown',function(e){
if(e.keyCode == 9 && e.shiftKey){
$('.lnb_dep2').hide();
$lnb_1dep.find('> a > img').each(off);
$lnb_1dep.eq(dep1-1).addClass('on').find('> a > img').each(on);
if(dep2){
$onLnb_2dep.show();
$onLnb_2dep.find('li').eq(dep2-1).addClass('on').find('> a > img').each(on);
}
}
})
/*
$lnb.find('li:last > a').bind('blur',function(e){
$('.lnb_dep2').stop().hide();
$lnb_1dep.eq(dep1-1).addClass('on').find('> a > img').each(on);
if(dep2){
$onLnb_2dep.stop().show();
$onLnb_2dep.find('li').eq(dep2-1).addClass('on').find('> a > img').each(on);
}
})
*/
}
lnb(dep2, dep3);
}
$(function(){
gnbFnc();
});