/**
 * 김무건 || Elkha (elkha1914@hotmail.com)
 * http://elkha.kr
 * 2010-08-27
 **/

menu_ani = "default";

(function($){

	// 애니메이션 정의
	var menu = {
		"default" : { width:"show", height:"show" },
		"slideDown" : { height:"show", opacity:"show" },
		"slideRight" : { width:"show", opacity:"show" },
		"false" : { opacity:"show" }
	};

	// 상단 레이어 포커스
	var login_input = {
		"default" : { "blur":"#333", "focus":"#222" },
		"t2" : { "blur":"#fff", "focus":"#eff5e1" },
		"t3" : { "blur":"#fff", "focus":"#eff5e1" },
		"t4" : { "blur":"#fff", "focus":"#eff5e1" },
		"t5" : { "blur":"#fff", "focus":"#eff5e1" }
	};

	// 서브메뉴 배경색
	var lnb_bg = {
		"default" : { "out":"#eee", "hover":"#ddd" },
		"t2" : { "out":"#f7f7f7", "hover":"#e9e9e9" },
		"t3" : { "out":"#fff", "hover":"#f6f6f6" },
		"t4" : { "out":"#f4f4f4", "hover":"#e6e6e6" },
		"t5" : { "out":"#f4f4f4", "hover":"#f4f4f4" }
	};

	function ieSelectFunc (tmp) {
		var ieSelect = false;
		if($.browser.msie == true) ieSelect = parseInt($.browser.version);
		if(ieSelect == 6) $('#container select').css({visibility:tmp});
	}

	$(document).ready(function(){

		var gnb = $("#gnb");
		var gnbHover = false; // 마우스가 메뉴를 벗어난 경우 false

		// 메인 메뉴 함수
		function gnb_func(select){
			gnbHover = true;
			var menu_speed = (menu_ani=="false")? 0 : "fast";

			if(select){
				select.addClass("hover")
					.parents("li").addClass("hover");
				ieSelectFunc("hidden");
			} else {
				ieSelectFunc("visible");
			}
			$("#gnb li:not('.hover') ul").not(":animated").fadeOut(menu_speed)
				.find("a").fadeTo(0, 1);
			$("#gnb .hover").removeClass("hover")
				.children("ul")/*.not(":animated")*/.animate(
					menu[menu_ani], // "width":"show", "height":"show"
					menu_speed, // "fast"
					function(){ if(Design == "t2") $(this).children("li").children("a").fadeTo(0, 0.85); }
			);
		}

		// 메인 메뉴 액션
		gnb.find("li").hover(function(){
			gnb_func( $(this) );
		}).children("a").focus(function(){
			gnb_func( $(this).parent("li") );
		});
		gnb.mouseleave(function(){
			gnbHover = false;
			setTimeout(function(){
				if(!gnbHover) gnb_func( false );
			}, 1000);
		});
		$('*:not("#gnb a")').focus(function(){
			gnb_func( false );
		});

		// 검색창 focus/blur
		$("#header .search .inputText").focus(function(){
			$(this).parents("form").addClass("focus");
		})
		.blur(function(){
			$(this).parents("form").removeClass("focus");
		});

		// 상단 레이어 열기
		$("#header .hLayer .open").click(function(){
			if( $(this).attr("href").match("#") ) { // 본문내 URL일 경우 레이어 펼침
				$("#header .bg-out").removeClass("on");
				$(this).next(".bg-out").addClass("on");
				$("#header .bg-out:not('.on')").slideUp("fast");
				$(this).next(".bg-out").slideToggle("fast", function(){
					$("#uid, #hSearch", this).focus();
				});
				return false;
			}
		});

		// 상단레이어 닫기
		$("#header .hLayer .close").click(function(){
			$(this).parents(".bg-out").slideUp("fast");
		});

		// 로그인 메시지 여닫기
		$("#keepA").click(function(){
			if( $(this).attr("checked") == true ) {
				$("#header .hLayer .keep_caution").animate({
					"opacity":"show",
					"right":"93%"
				}, "fast");
			} else {
				$("#header .hLayer .keep_caution").animate({
					"opacity":"hide",
					"right":"100%"
				}, "fast");
			}
		});

		// 상단 레이어 포커스 애니메이션
		$("#header .hLayer .inputText").focus(function(){
			$(this).stop().animate({
				"backgroundColor":login_input[Design].focus
			}, "fast");
		})
		.blur(function(){
			$(this).stop().animate({
				"backgroundColor":login_input[Design].blur
			}, "fast");
		});

		// 위젯 하위메뉴 펼치고 닫기
		$("#column .lnb .more button").click(function(){
			$(this).parents(".li2").toggleClass("on");
			if( $(this).parents(".li2").attr("class").match("on") ) $(this).parent(".more").next("ul").show("fast");
			else $(this).parent(".more").next("ul").hide("fast");
		});

		// 위젯 메뉴 배경 애니메이션
		$("#column .lnb .sec a").hover(function(){
			if(lnb_bg[Design].out != lnb_bg[Design].hover) $(this).stop().animate({"backgroundColor":lnb_bg[Design].hover}, "fast");
		}, function(){
			if(lnb_bg[Design].out != lnb_bg[Design].hover) $(this).stop().animate({"backgroundColor":lnb_bg[Design].out}, "fast");
		});

		// 확장메뉴 펼침
		$("#column .lnb .expandY").addClass("on")
			.children(".ul3").show("fast");
	});
})(jQuery);

