$(document).ready(function(){
	//alert(checkbrowsIE6());
	if(checkbrowsIE6()){
		glovalRollOver();
	}
});

/*--------------------------------------------------------------
* グローバルメニューのロールオーバー
*-------------------------------------------------------------*/
function glovalRollOver(){
	//IE系が動かない。エラーの原因
	

		var currentXY = new Array("0px bottom","97px bottom","192px bottom","285px bottom");
		var srcArr = new Array();
		var currentNum = null;
		//onの画像を調べる
		
		//alert($(".gnav li >a img"));
		$(".gnav li > a img").each(function(i){
			var src = $(this).attr("src");
			
			srcArr[i] = src.substr(src.lastIndexOf("/")+1, src.length-6);
		})
			
		//リストの番号をセット
		for(n in srcArr){
			if(srcArr[n].indexOf("_on") != -1){
				currentNum = n;
				break;
			}
		}
		
		
		if(currentNum != null){
			$(".gnav").css({"background-position":currentXY[currentNum]});
		}else{
			$(".gnav").css({"background-position":"-120px bottom"});
		}
		
		moveBg(currentNum);
}

function moveBg(num){
	
	//alert("move")
	
	var currentNum = num;
	var currentXY = new Array(["0px bottom"],["97px bottom"],["192px bottom"],["285px bottom"]);
	
	$(".gnav li").hover(function() {
		var index = $(".gnav li").index(this);
		$(".gnav").stop().animate({ backgroundPosition: currentXY[index] }, { duration: "eaesOutQuart" });
	}, function() {
		var index = $(".gnav li").index(this);
		if(currentNum != null){
			$(".gnav").stop().animate({ backgroundPosition: currentXY[num] }, { duration: "eaesOutQuart" });
		}else{
			if( index == 0 || index == 1 ){ 
				$(".gnav").stop().animate({ backgroundPosition: "-120px bottom" }, { duration: "eaesOutQuart" });
			}else{
				$(".gnav").stop().animate({ backgroundPosition: "425px bottom" }, { duration: "eaesOutQuart" });
			}
		}
	});
}

/*--------------------------------------------------------------
* ブラウザチェック
*-------------------------------------------------------------*/
function checkbrowsIE6(){
	var userAgent = window.navigator.userAgent.toLowerCase();
	var appVersion = window.navigator.appVersion.toLowerCase();

	var result;

	if (userAgent.indexOf("msie") > -1) {
		//alert(appVersion);
		if (appVersion.indexOf("msie 8.0") > -1) {
			//alert("IE8");
			result = true;
		}
		else if (appVersion.indexOf("msie 7.0") > -1) {
			result = true;
		}
		else if (appVersion.indexOf("msie 6.0") > -1) {
			//alert("IE6");
			result = false;
		}
		else {
			//alert("Unknown");
			result = true;
		}
	}else{
			result = true;
	}
	
	return result;
}
