$(function(){
	//$("#gwMainMenu .gwSubMenu").hide();
	
	//第1階層のロールオーバーアニメーション変数
	var OvClass1 = "imgoverGnavi1", //ロールオーバーする要素のクラス名
	OvClass2 = "imgoverGnavi2", //ロールオーバーする要素のクラス名
	OvClass3 = "imgoverGnavi3", //ロールオーバーする要素のクラス名
	OvClass4 = "imgoverGnavi4", //ロールオーバーする要素のクラス名
	OvStr = "_on", //ロールオーバー後の画像に追加する文字列
	OvImg = "ovImg",
	Speed = 400; //アニメーションの速度
	
	
	
	
	//高さなどを自動設定
	$("#gwMenu").css("height",$("#gwMainMenu img").eq(1).attr("height"));
	
	$("#gwMainMenu .gwSubMenu").css("width",$("#gwMainMenu img").eq(1).attr("width"));
	$("#gwMainMenu li").css("width",$("#gwMainMenu img").eq(1).attr("width"));
	$("#gwMainMenu li a").css("width",$("#gwMainMenu img").eq(1).attr("width"));
	$("#gwMainMenu .gwSubMenu li").css("width",$("#gwMainMenu img").eq(1).attr("width")-2);
	$("#gwMainMenu .gwSubMenu li a").css("width",$("#gwMainMenu img").eq(1).attr("width")-2);
		
	
	
	
	
	//ドロップダウン動作
	$("#gwMainMenu li.main").hover(
		function(){
			$(this).find(".gwSubMenu").slideDown(200);
			$(this).find(".mago").hide();
			//$(this).find("img").attr("src",$(this).find("img").attr("id") + "_on.jpg");
		},
		function(){
			$(this).find(".gwSubMenu").slideUp(400);
			//$(this).find("img").attr("src",$(this).find("img").attr("id") + ".jpg");
		}
	);
	$("#gwMainMenu li.sub").hover(
		function(){
			$(this).find(".gwSubMenu").slideDown(200);
			//$(this).find(".gwSubMenu").slideDown(200);
			//$(this).find("img").attr("src",$(this).find("img").attr("id") + "_on.jpg");
		},
		function(){
			$(this).find(".gwSubMenu").slideUp(400);
			//$(this).find("img").attr("src",$(this).find("img").attr("id") + ".jpg");
		}
	);
	
	
	
	//第3階層表示時の第2階層のカラム表示

	$("#subSubMenuTakenoko").hover(
		function(){
			$("#subMemnuTakenoko").addClass("gwSubMenuHover");
		},
		function(){
			$("#subMemnuTakenoko").removeClass("gwSubMenuHover");
		}
	);

	$("#subSubMenuKaiseki").hover(
		function(){
			$("#subMemnuKaiseki").addClass("gwSubMenuHover");
		},
		function(){
			$("#subMemnuKaiseki").removeClass("gwSubMenuHover");
		}
	);
		
	$("#subSubMenuDeli").hover(
		function(){
			$("#subMemnuDeli").addClass("gwSubMenuHover");
		},
		function(){
			$("#subMemnuDeli").removeClass("gwSubMenuHover");
		}
	);
	
	
	
	
	
	//classがimgoverGnaviのimg要素に対しての処理
	$("li."+OvClass1).each(function(){

		var thisLi = $(this),
		thisImage = $("li."+OvClass1 + " img.imgoverImgae"),
		Url = thisImage.attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1"+OvStr+"$2");

		function OvElmLen(){ //ロールオーバー画像表示確認関数
			return thisImage.prev("img."+OvImg).length;
		}

		//ホバーイベント
		thisLi.hover(
		function(){
			if(!thisImage.attr("src").match(OvStr+".")){
				if(!OvElmLen()){
					if(jQuery.support.checkOn && jQuery.support.htmlSerialize && !window.globalStorage){ //Operaバグ対策
						thisImage.before("<span style='display:inline-block;' class='"+OvImg+"' ></span>");
					}
					thisImage.css({position:"relative"}).before("<img style='position:absolute;' class='"+OvImg+"' src='"+Url+"' alt='' />");
				}
				thisImage.stop().animate({opacity:"0"},Speed);
			}
		},
		function(){
			if(OvElmLen()){
				thisImage.stop().animate({opacity:"1"},Speed,function(){
					thisImage.css({position:"static"})
					.prevAll("."+OvImg).remove();
				});
			}
		})

	});
	
	
	
	//classがimgoverGnaviのimg要素に対しての処理
	$("li."+OvClass2).each(function(){

		var thisLi = $(this),
		thisImage = $("li."+OvClass2 + " img.imgoverImgae"),
		Url = thisImage.attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1"+OvStr+"$2");

		function OvElmLen(){ //ロールオーバー画像表示確認関数
			return thisImage.prev("img."+OvImg).length;
		}

		//ホバーイベント
		thisLi.hover(
		function(){
			if(!thisImage.attr("src").match(OvStr+".")){
				if(!OvElmLen()){
					if(jQuery.support.checkOn && jQuery.support.htmlSerialize && !window.globalStorage){ //Operaバグ対策
						thisImage.before("<span style='display:inline-block;' class='"+OvImg+"' ></span>");
					}
					thisImage.css({position:"relative"}).before("<img style='position:absolute;' class='"+OvImg+"' src='"+Url+"' alt='' />");
				}
				thisImage.stop().animate({opacity:"0"},Speed);
			}
		},
		function(){
			if(OvElmLen()){
				thisImage.stop().animate({opacity:"1"},Speed,function(){
					thisImage.css({position:"static"})
					.prevAll("."+OvImg).remove();
				});
			}
		})

	});
	
	
	//classがimgoverGnaviのimg要素に対しての処理
	$("li."+OvClass3).each(function(){

		var thisLi = $(this),
		thisImage = $("li."+OvClass3 + " img.imgoverImgae"),
		Url = thisImage.attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1"+OvStr+"$2");

		function OvElmLen(){ //ロールオーバー画像表示確認関数
			return thisImage.prev("img."+OvImg).length;
		}

		//ホバーイベント
		thisLi.hover(
		function(){
			if(!thisImage.attr("src").match(OvStr+".")){
				if(!OvElmLen()){
					if(jQuery.support.checkOn && jQuery.support.htmlSerialize && !window.globalStorage){ //Operaバグ対策
						thisImage.before("<span style='display:inline-block;' class='"+OvImg+"' ></span>");
					}
					thisImage.css({position:"relative"}).before("<img style='position:absolute;' class='"+OvImg+"' src='"+Url+"' alt='' />");
				}
				thisImage.stop().animate({opacity:"0"},Speed);
			}
		},
		function(){
			if(OvElmLen()){
				thisImage.stop().animate({opacity:"1"},Speed,function(){
					thisImage.css({position:"static"})
					.prevAll("."+OvImg).remove();
				});
			}
		})

	});	
	
	
	//classがimgoverGnaviのimg要素に対しての処理
	$("li."+OvClass4).each(function(){

		var thisLi = $(this),
		thisImage = $("li."+OvClass4 + " img.imgoverImgae"),
		Url = thisImage.attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1"+OvStr+"$2");

		function OvElmLen(){ //ロールオーバー画像表示確認関数
			return thisImage.prev("img."+OvImg).length;
		}

		//ホバーイベント
		thisLi.hover(
		function(){
			if(!thisImage.attr("src").match(OvStr+".")){
				if(!OvElmLen()){
					if(jQuery.support.checkOn && jQuery.support.htmlSerialize && !window.globalStorage){ //Operaバグ対策
						thisImage.before("<span style='display:inline-block;' class='"+OvImg+"' ></span>");
					}
					thisImage.css({position:"relative"}).before("<img style='position:absolute;' class='"+OvImg+"' src='"+Url+"' alt='' />");
				}
				thisImage.stop().animate({opacity:"0"},Speed);
			}
		},
		function(){
			if(OvElmLen()){
				thisImage.stop().animate({opacity:"1"},Speed,function(){
					thisImage.css({position:"static"})
					.prevAll("."+OvImg).remove();
				});
			}
		})

	});
	
	
});

