var old_size_mode;


$(document).ready(function(){


	var height_val = 0; // 뎁스 height 중에 가장큰거 구함
	$(".depth_box").each(function(){
		if(height_val<$(this).height()) height_val = $(this).height();
	});


	//드롭다운 메뉴 {
		function chkSize(){
			var windowInnerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
			if(windowInnerWidth < 1025){

				//현재상태가 모비일이 아닐때{
					if(old_size_mode && old_size_mode != 'mobile') {
						$("#topMenu , #topMenu li.menu_list a.depth_link ,#topMenu a.depth_link2").unbind("mouseenter keyup mouseleave click").removeClass("menu_on");
						$("#topMenu").removeAttr("style")
						$('body').removeAttr('style')
						$('.m_menu_wrap_bg').removeAttr('style')
						//$('#topMenu .depth_box').css("display","block")
						$('#header .top_etc_link ul').removeAttr('style')
					}
				//}
				
				//현재상태가 모비일 일때{
					$("#topMenu , #topMenu li.menu_list a.depth_link, #topMenu a.depth_link2").unbind("mouseenter keyup mouseleave click");
					//$('#topMenu .depth_box').css("display","block");
					$('#topMenu li.menu_list a.depth_link').click(function(){
						var depth_box = $(this).parent().children('.depth_box');
						$(".depth_box").not(depth_box).hide();
						$(depth_box).toggle() ;
						if($(depth_box).is(':visible')){
							$('#topMenu li.menu_list a').addClass('menu_on').not(this).removeClass('menu_on');
						}else{
							$('#topMenu li.menu_list a').removeClass('menu_on');
						}
					})
					
					/*//3뎁스
					$('#topMenu a.depth_link2').click(function(){
						var depth_box2 =  $(this).parent().children('.three_depth')
						$(".three_depth").not(depth_box2).hide(0);
						$(depth_box2).toggle(); 
					});*/
				//}
				
				//$(".main_product_box ul").attr("data-cycle-carousel-visible", "2")
				
		
				old_size_mode = 'mobile';
			}else{
				//{모바일 상태의 이벤트 빼기
					$("#topMenu li.menu_list a.depth_link, #topMenu a.depth_link2").unbind("click");
					$('#topMenu .depth_box').css("display","none");
				//}
				//현재상태가 데스크탑이 아닐때
					if(old_size_mode &&  old_size_mode != 'desktop') {
						$("#topMenu").css("display","block");
						$(".three_depth").css("display","none");
						$('#topMenu li.menu_list a').removeClass("menu_on");
						
						chk_menu1('desktop');
						/*chk_menu2('desktop');*/
					}
				//}

				old_size_mode = 'desktop';
				
				//{데스크탑 클릭이벤트
					$("#topMenu").removeAttr("style")
					$('body').removeAttr('style')
					$('#header .top_etc_link ul').removeAttr('style')
					$('.m_menu_wrap_bg').removeAttr('style')
					$('#topMenu li.menu_list a.depth_link').bind("mouseenter keyup", function(){
						$('#topMenu li.menu_list a').addClass("menu_on").not(this).removeClass("menu_on");
						$(".depth_box").show(0).css({"height":height_val});
						$(".depth_box_wra_box").show(0).css({"height":height_val});
					})
					$("#topMenu").bind("mouseleave" , function(){
						$("#topMenu li.menu_list a").removeClass("menu_on");
						$(".depth_box").hide().removeAttr("style");
						$(".depth_box_wra_box").hide().removeAttr("style");
					});	
					
				//)데스크탑 클릭이벤트
			}
			chk_menu1(old_size_mode);
			/*chk_menu2(old_size_mode);*/
		}

		// mobile 에서 1depth 있는 링크 #none; 처리{
			function chk_menu1(mode) {
				var menu_depth1;
				var main_notice_depth1;
				$("#topMenu li a.depth_link").each(function(i) { 
					menu_depth1 = $(this)

					if(mode == 'mobile') {
						// 링크 임시 저장 후 #none; 처리
						if(menu_depth1.attr('href') != '#none;') {
							menu_depth1.attr('href_', menu_depth1.attr('href'));
							menu_depth1.attr('href', '#none;');
							if($(this).next().children().size() == 0){
								var link_url = menu_depth1.attr('href_');
								menu_depth1.attr('href', link_url);
							}
						}
					} else if(mode == 'desktop') {
						// 링크 복원
						if(menu_depth1.attr('href_')) {
							//alert(menu_depth1.attr('href') + ',' + menu_depth1.attr('href_'));
							menu_depth1.attr('href', menu_depth1.attr('href_'));
							menu_depth1.attr('href_', '');
						}
					}
				});


				$(".tep_list dt a").each(function(i) { 
					main_notice_depth1 = $(this)

					if(mode == 'mobile') {
						// 링크 임시 저장 후 #none; 처리
						if(main_notice_depth1.attr('href') != '#none;') {
							main_notice_depth1.attr('href_', main_notice_depth1.attr('href'));
							main_notice_depth1.attr('href', '#none;');
							
						}
					} else if(mode == 'desktop') {
						// 링크 복원
						if(main_notice_depth1.attr('href_')) {
							//alert(main_notice_depth1.attr('href') + ',' + main_notice_depth1.attr('href_'));
							main_notice_depth1.attr('href', main_notice_depth1.attr('href_'));
							main_notice_depth1.attr('href_', '');
						}
					}
				});
			}
		//}


		//{모바일 메뉴버튼
			$("p.menu_btn").bind("click keyup" ,function(){
				$("#topMenu").toggle(0, function(){
					if($("#topMenu").is(':hidden')){
						$('body').removeAttr('style')
						$('.m_menu_wrap_bg').removeAttr('style')
					}else{
						$('body').css({"position":"fixed" ,"height":"100%", "overflow":"hidden"})
						$('.m_menu_wrap_bg').css({"position":"fixed", "right":"0","width":"20%", "height":"100%" ,"background":"#000", "opacity":"0.8", "z-index":"100"})
						$('.menu_btn_colse').click(function(){
							$("#topMenu").hide();
							$('body').removeAttr('style')
							$('.m_menu_wrap_bg').removeAttr('style')
						});
					}
				});
			});

			$('.menu_btn_colse').click(function(){
				$("#topMenu").hide();
			});

			$("#header .top_etc_link .title").click(function(){
				var top_etc_link_box = $(this).next("ul");
				$(top_etc_link_box).toggle();
			});

			
		//}

		$(window).resize(function(){ 
			chkSize();
		});
		chkSize();	

	//{메뉴별 아이디 추가
	$(".menu_list").each(function(){
		var menu_list_id = $(this).index()
		$(this).attr("id", "topMenu"+menu_list_id);
	});

	$(".notice_tep").each(function(){
		var menu_list_id = $(this).index()
		$(this).attr("id", "notice_tep"+menu_list_id);
	});
	//}



	//{상단
	$('.first_top_go').click(function(){
		$("html, body").animate({ scrollTop: 0 }, 200);
	});
	//}


	$(".sub_guide_menu .this_page_name").bind("mouseenter keyup", function(){
		$(this).toggleClass("this_page_name_on");
		$(this).children("#sub_guide_menu_wrap").show();
	});
	$(".sub_guide_menu .this_page_name").bind("mouseleave ", function(){
		$(this).toggleClass("this_page_name_on");
		$(this).children("#sub_guide_menu_wrap").hide();
	});


	$(".main_notice  h3").first().addClass("first_h3");
	$(".main_notice  div").first().addClass("on_check");
	

	$('.notice_tep').each(function(){
		var btn_event = $(this).children('.btn')
		var no_event = $(this).siblings('.notice_tep')
		$(btn_event).on("mouseover keyup click",function(){
			var show_box = $(this).parent()
			$(no_event).not(show_box).removeClass('on_check')
			$(show_box).addClass('on_check')
		});
	});


	$(window).scroll(function () {
		var body_height = $(document).scrollTop();	
		body_position(body_height);
		body_position_teb(body_height);
	});






	$(".mobile_select_menu .this_page_text").click(function(){
		$(this).next("ul").toggle();
	});

	
	function body_position(str){
		if(str > 0){
			$('#header').addClass("on_scroll");

		}else{
			$('#header').removeClass("on_scroll");
		}
	}


});



function allmenu_detail_show_box(){
	
	$('.allmenu_detail_show_box_wrap').lightbox_me({
		centered: true,  //센터
		closeClick: false,	//닫기 외버튼 안됨 
		closeEsc: false,	//닫기 외버튼 안됨 
		overlaySpeed: 250,  // 전체검정색
		lightboxSpeed: 400, // 레이어튀어나오는속도
		overlayCSS: {background: 'black', opacity: .1},
		modalCSS: {top: '0%'}
	});
	
}



//{달력
	$(function() {
		$(".sdate_calendar").datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
			monthNamesShort: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
			dayNames: ['일','월','화','수','목','금','토'],
			dayNamesShort: ['일','월','화','수','목','금','토'],
			dayNamesMin: ['일','월','화','수','목','금','토'],
			changeYear: true,
			changeMonth: true
		})
	});
//}

