﻿/*=====================================================================================
' namespace : Gnb                                      
' 기     능 : 도요타 상단 메뉴 정의 함수 
'-------------------- 변경이력 --------------------------------------------------------
'    작 성 자        소  속         작 성 일               비   고              
'------------------------------------------------------------------------------------
'  1. CVS           CVS           2011.11.02       최초 작성                       
'======================================================================================*/
Gnb = {

	seIndex : null,

	Load : function(i) {
		if( i != null) {
			$("#gnb .menu_list li").eq(i).children("a").children("img").attr("src", $("#gnb .menu_list li").eq(i).children("a").children("img").attr("src").replace(/_off/g, "_on"));
			$("#gnb .submenu").eq(i).slideDown(300);
		}
	},

    /*'=================================================================
    ' 함수명 : Gnb.CreateGnb()
    ' 기  능 : 상단 메뉴 이벤트 생성처리
    '-------------------- 변경이력 ------------------------------------ 
    '    작 성 자        소  속         작 성 일         비   고 
    ’-----------------------------------------------------------------
    '  1. CVS           CVS           2011.11.02       최초 작성                       
    '================================================================*/
	CreateGnb: function() {

		//Gnb.Load(Gnb.seIndex);
		
		//1차 메뉴 효과
		$("#gnb .menu_list li").hover(function() {
			
			//MouseOver 모든 1차 메뉴 이미지 초기화
			$("#gnb .menu_list li").each(function(index) {
				$(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace(/_on/g, "_off"));
			});
			//MouseOver 모든 2차 메뉴 숨기기
			$("#gnb .submenu").hide();

			//MouseOver 해당 1차 메뉴 이미지변경, 2차 메뉴 보이기
			var index = $("#gnb .menu_list li").index(this);
			$(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace(/_off/g, "_on"));
			$("#gnb .submenu").eq(index).slideDown(300);

		}, function() {
			
			//1차메뉴 MouseOut
			var index = $("#gnb .menu_list li").index(this);
			if($("#gnb .submenu").eq(index).attr("display") == "none") {
				$(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace(/_on/g, "_off"));
			}
	
		});

		//2차 메뉴 이미지 롤오버
		$("#gnb .submenu ul li").hover(function() {
			var index = $("#gnb .submenu ul li").index(this);
			$(this).children("a").children("img").attr("src", function() {
				return $(this).attr("src").replace(/_off/g, "_on");
			});
		}, function() {
			$(this).children("a").children("img").attr("src", function() {
				return $(this).attr("src").replace(/_on/g, "_off");
			});
		});


		//Gnb 빠져날올대 초기화 하기
		$("#gnb").hover(function() {
		}, function() {
			$("#gnb .menu_list li").each(function(index) {
				$(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace(/_on/g, "_off"));
			});
			$("#gnb .submenu").hide();
		});

		
	}
}

/*=====================================================================================
' namespace : Lnb                                      
' 기     능 : 도요타 좌측메뉴 공통 정의 함수 
'-------------------- 변경이력 --------------------------------------------------------
'    작 성 자        소  속         작 성 일               비   고              
'------------------------------------------------------------------------------------
'  1. CVS           CVS           2011.10.19       최초 작성                       
'======================================================================================*/
Lnb = {

	lnbTimer: null,
	seIndex: null,
	depth01: null,
	depth02: null,

	Init: function() {

		var lnbVal = $("#lnbCode").val();
		if(lnbVal != '' && lnbVal != null) {
			Lnb.depth01 = lnbVal.split(':')[0];
			Lnb.depth02 = lnbVal.split(':')[1];
		}
		if(Lnb.depth01 != null && Lnb.depth02 != null) {

			$(".lnb ul li span img").attr("src", function() {
				var index = $(".lnb ul li span img").index(this);
				var src = null;
				if(index == Lnb.depth01) {
					src = $(".lnb ul li span img").eq(index).attr("src").replace(/_off/g, "_on");
				}else{
					src = $(".lnb ul li span img").eq(index).attr("src").replace(/_on/g, "_off");
				}
				return src
			});

			var ts = $(".lnb ul").children("li").eq(Lnb.depth01);
			if($(ts).children("ul").css("display") == 'none') {
				$(".lnb ul").children("li").children("ul").hide();
				$(ts).children("ul").slideDown(function() {
					$(this).children("li").eq(Lnb.depth02).children("a").children("img").attr("src", function() {
						return $(this).attr("src").replace(/_off/g, "_on");
					});
				});
			} else {
				$(ts).children("ul").children("li").eq(Lnb.depth02).children("a").children("img").attr("src", function() {
						return $(this).attr("src").replace(/_off/g, "_on");
				});
			}
		}

	},

	CreateLnb: function () {

		if ($("div").hasClass("lnb")) {

			Lnb.Init();

			$(".lnb").find("span").children("img").each(function (index) {
				
				//1차 뎁스 오버 설정
				$(this).hover(function () {
					
					clearTimeout(Lnb.lnbTimer);
					
					
					$(this).attr("src", $(this).attr("src").replace(/_off/g, "_on"));
					var ts = this;
					Lnb.seIndex = index;

					//2차 뎁스 설정
					if ($(this).parent().parent().next("ul").length > 0) {
						$(this).parent().parent().next("ul").slideDown(300);
					}

					//1차 뎁스 유지
					$("span").children("img").each(function (sIndex) {
						if (Lnb.seIndex == sIndex) {
						} else {
							if ($(this).parent().parent().next("ul").length > 0) {
								$(this).parent().parent().next("ul").slideUp(200);
							}
							$(this).attr("src", $(this).attr("src").replace(/_on/g, "_off"));
						}
					});

				});

				//2차 뎁스 오버 설정
				if ($(".lnb ul li ul").length > 0) {
					$(".lnb ul li ul li a img").hover(function () {
						$(this).attr("src", $(this).attr("src").replace(/_off/g, "_on"));
					}, function () {
						$(this).attr("src", $(this).attr("src").replace(/_on/g, "_off"));
					});
				}

			});

			$(".lnb").hover(function() {}, function() {
				clearTimeout(Lnb.lnbTimer);
				Lnb.lnbTimer = setTimeout("Lnb.Init();clearTimeout(Lnb.lnbTimer);", 2000);
			});

		}
	}
}

/*'=====================================================================================
' 함수명 : ready()
' 기  능 : 페이지 로드시 이벤트 설정처리
'-------------------- 변경이력 -----------------------------------------------------
'    작 성 자        소  속         작 성 일               비   고              
’----------------------------------------------------------------------------------
'  1. PHJ           ---             2011.10.19             최초 작성                
'======================================================================================*/
$(document).ready(function () {

	$(document).pngFix();
	Lnb.CreateLnb();

}); 
