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});
						//$(".depth_box_wra_box").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");
						//$(".depth_box_wra_box .default_layout").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);
	});
	//}



	//{상단
	$('.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();
	});



	$('#favorite').on('click', function(e) {
		var bookmarkURL = window.location.href;
		var bookmarkTitle = document.title;
		var triggerDefault = false;

		if (window.sidebar && window.sidebar.addPanel) {
			// Firefox version < 23
			window.sidebar.addPanel(bookmarkTitle, bookmarkURL, '');
		} else if ((window.sidebar && (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)) || (window.opera && window.print)) {
			// Firefox version >= 23 and Opera Hotlist
			var $this = $(this);
			$this.attr('href', bookmarkURL);
			$this.attr('title', bookmarkTitle);
			$this.attr('rel', 'sidebar');
			$this.off(e);
			triggerDefault = true;
		} else if (window.external && ('AddFavorite' in window.external)) {
			// IE Favorite
			window.external.AddFavorite(bookmarkURL, bookmarkTitle);
		} else {
			// WebKit - Safari/Chrome
			alert((navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D 키를 눌러 즐겨찾기에 등록하실 수 있습니다.');
		}

		return triggerDefault;
	});


	$(window).scroll(function () {
		var body_height = $(document).scrollTop();	
		body_position(body_height);
		body_position_teb(body_height);
	});


	function body_position(str){
		if(str > 0){
			$('#header').addClass("on_scroll");
			$('.view_professor_detail #teb').addClass("on");

		}else{
			$('#header').removeClass("on_scroll");
			$('.view_professor_detail #teb').removeClass("on");
		}
	}

	function body_position_teb(str){
		if(str > 700){
			$('.view_professor_detail #teb').addClass("on");
			var list_on = $(this).children().find("a")
			//var list_on = $(this).children().find("a")
			$(".view_professor_detail #teb li a").click(function(){
				$(".view_professor_detail #teb li a").removeClass("on_check");
				$(this).addClass("on_check");

			});

		}else{
			$('.view_professor_detail #teb').removeClass("on");
			$(".view_professor_detail #teb li a").removeClass("on_check");
			$(this).removeClass("on_check");
		}
	}




	$(".mobile_select_menu .this_page_text").click(function(){
		$(this).next("ul").toggle();
	});

	


	//메인출력관련
	$(".main_notice dt").first().addClass("fist_title on");
	$(".main_notice dd").first().addClass("first");
	$(".notice_list_ul_box").each(function(){
		var first_li = $(this).children()
		$(first_li).first().addClass("first_li");
	});


	//공지사항(탭메뉴 공통적용)
	$('dl.tep_list').each(function(){
		var btn_dt = $(this).children('dt')
		var btn_dd = $(this).children().siblings('dd')
		$(btn_dt).bind("mouseenter keyup" ,function(){
			var box = $(this).next('dd');
			$(this).addClass('on')
			$(btn_dt).not(this).removeClass('on');
			$(btn_dd).not(box).hide();
			$(box).show();
		});
	});
	//}



});



//{달력
	$(function() {
		$(".sdate_calendar").datepicker({
			dateFormat: 'yy-mm-dd',
			maxDate: 0, 
			yearRange: "-100:+0",
			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
		})
	});
//}

