/* ナビ周りの挙動設定 */

//$(function(){

var _GFundCatID;	
	
(function(){
	var id;
	
	try{ 
		id = activeNavId;
		
	}catch(e){
		id = getCurrentId();
	}
	
	_GFundCatID = id;
	

	//アクティブなナビの設定
	setActiveNav(id);
	
	//プルダウンの設定
	setPullDown();
	
	function setActiveNav(target){
		id = target;
		
		//サイドナビ設定
		$target = $("#"+target);
		$target.addClass("active");
		$(">a",$target).unbind('mouseenter mouseleave');
		//if($target.parent().hasClass("lv1")) $(">a",$target).css("background","url(/common/img/bg_sidenav_lv1_on.gif) repeat-y left top").css("color","#FFF");
		if($target.parent().hasClass("lv1")) $(">a>img",$target).attr("src",$(">a>img",$target).attr("src").replace("_off","_on"));
		if($target.parent().hasClass("lv2")) $(">a",$target).css("background","url(/common/img/bg_sidenav_lv2_on.gif) repeat-y left top").css("color","#FFF");
		
		$(">.nav",$target).show();
		$target.parents(".nav").show();
		$target.parents(".nav>li").addClass("active")
		.each(function(){
			if($(this).parent().hasClass("lv1")){
				$(">a",this).unbind('mouseenter mouseleave');
				$(">a>img",this).attr("src",$(">a>img",this).attr("src").replace("_off","_on"));
			}else if($(this).parent().hasClass("lv2")){
				$(">a",this).unbind('mouseenter mouseleave').css("background","url(/common/img/bg_sidenav_lv2_on.gif) repeat-y left top").css("color","#FFF");
			}
			
		});
		
		//グローバルナビ設定
		try{
			var id = $("#lnav .lv1>li.active").attr("class").split(" ")[0];
		}catch(e){}
		
		try{
			$("#gnav ."+id+">a>img").attr("src",$("#gnav ."+id+">a>img").attr("src").replace("_off","_on")).unbind('mouseenter mouseleave');
		}catch(e){}
		
		$("#gnav "+id).addClass("active");

	}
	
	function getCurrentId(){
		var path = location.pathname;
		
		if(path.charAt(path.length-1) == "/"){
			path = path.slice(0,-1);
		}
				
		if(!path|(path=="/")|(path=="/index.html")) return "gnavHome";
		
		return "gnav"+path.split("/index.html")[0].split(".html")[0].split("/").join("_");
	}
	
	function setPullDown(){
		$("#gnav>ul>li").each(function(){
			if($(".sub",this).length == 1){
				
					if(!isSmartPhone()){
						
						/* ==========================================
							PCの場合
						========================================== */
						
						$(this).hover(function(){
							$(".sub",this).show(0);	
						},
						function(){
							$(".sub",this).hide(0);	
						});
						
						
					}else{
		
						/* ==========================================
							SmartPhoneの場合
						========================================== */
						
						
						$(">a",this).attr("href",null);
						$(">a",this).click(function(){
							$(".sub",$(this).parent()).show(0)
							.append('<img class="close" style="position:absolute; right:-39px; top:0;" src="/common/img/btn_close_pulldown.gif" width="40" height="40" />');
							
							$(".sub .close",$(this).parent()).click(function(){
								$(this).parent(".sub").hide(0);
								$(this).remove();
							});
						});
					}
			}
		});
	}
})();
//});
