// JavaScript Document
$(document).ready(function(){	
	//init
	$(".list-nav-global")
	.find("ul")
	.css({"opacity":"0","height":"0","border":"solid 1px #b0acaa"});
	
	if (navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0) {
		
		 $(".list-nav-global").each(function(){
			$(this).click(function(){
				var targetDiv = $(this);
				$(this)
				.find("ul")
				.stop()
				.animate({"opacity":"1"},300,"easeOutCubic",function(){
					$(this).animate({"height":"102px"},300,"easeOutCubic")
					.delay(7000).animate({height: "0"},300,"easeOutCubic",function(){
						$(this).animate({"opacity":"0"},300,"easeOutCubic");	
					});
				});
				
				$(".list-nav-global").not(targetDiv)
				.find("ul")
				.stop()
				.animate({height: "0"},300,"easeOutCubic",function(){
					$(this).animate({"opacity":"0"},300,"easeOutCubic")
				});
			});
		});
	}else{
		
		$(".list-nav-global").hover(function(){
			$(this)
			.find("ul")
			.stop()
			.animate({"opacity":"1"},300,"easeOutCubic",function(){
				$(this).animate({"height": "102px"},300,"easeOutCubic");	
			})
		},function(){
			$(this)
			.find("ul")
			.stop()
			.animate({height: "0"},300,"easeOutCubic",function(){
				$(this).animate({"opacity":"0"},300,"easeOutCubic");
			});
		});
	}
});

function ini_nav_local_change(){
	//init
	$("ul.active","#nav-local")
	.css("opacity","1")
	.not($("ul.active","#nav-local"))
	.css("left","135px")
	.css("opacity","0");
	/*
	$("#nav-local").css("height",$("ul.active","#nav-local").height() + 6);
	
	
	var targetLi = $("li","#nav-global");
	
	$("li","#nav-global").click(function(){
		//クリックしたグローバルナビのliのインデックスナンバーを取得
		var targetLiIndex = $(this).index();
		
		//クリックしたグローバルナビのliの親のdivのインデックスナンバーを取得
		var targetDivIndex = $(this).parent().parent().index();
		
		//クリックしたグローバルナビのliの親のdivのインデックスナンバーに対応する入れ替えたいローカルナビの親のdivの中の、さらにクリックしたグローバルナビのliのインデックスナンバーに対応するに対応するローカルナビのulを選択
		var targetUl = $($("ul",$($("div","#nav-local")[targetDivIndex]))[targetLiIndex]);
		
		//ターゲットとなるul以外のulを選択し、アニメーションしていなければフェードアウトさせる
		$("ul","#nav-local").not(targetUl).filter(":not(:animated)")
		.animate({opacity:0,left:"135px"},300,"easeOutCubic",function(){
			//ターゲットとなるulの高さを取得
			var targetUlHeight = targetUl.height();
			//ローカルナビを選択し、アニメーションしていなければローカルナビの高さをターゲットのulの高さまでアニメーションさせる
			$("#nav-local").filter(":not(:animated)")
				.animate({height:targetUlHeight + 6},300,"easeOutCubic",function(){
				//ターゲットのulを選択し、ターゲットのulがアニメーションしていなければフェードインさせる
				targetUl.filter(":not(:animated)")
				.animate({opacity:1,left:"150px"},300,"easeOutCubic");
			});
		});
	});
	*/	
}

var preLoadImg = new Object();

function initRollOvers(){
    $("img.rollover").each(function(){
        var imgSrc = this.src;
        var onSrc = imgSrc.replace("_off","_on");
        preLoadImg[imgSrc] = new Image();
        preLoadImg[imgSrc].src = onSrc;
        $(this).hover(function(){
			this.src = onSrc;
		},function(){
			this.src = imgSrc;
		});
    });
}

$(document).ready(function(){
	initRollOvers();
});
