function initRollOverImages() {
  var image_cache = new Object();
  $("img.swapImg").each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_f2' + this.src.substr(dot, 4);
    image_cache[this.src] = new Image();
    image_cache[this.src].src = imgsrc_on;
    $(this).hover(
      function() {$(this).fadeTo(0,0.1); this.src = imgsrc_on;$(this).fadeTo(250,1);},
      function() {this.src = imgsrc;});
  });
}
function initFlashBlock() {
  $(".flashBlock").each(function(i) {
    $(this).hover(
      function() {$(this).fadeTo(0,0.3);$(this).fadeTo(100,1);});
  });
  $(".BlockLink").click(function(){var LinkTarget = $(this).find("a").attr("target");
	if(LinkTarget =="_blank"){window.open().location=$(this).find("a").attr("href");return false;}
	else if(LinkTarget !="_blank"){window.location=$(this).find("a").attr("href");return false;}
});
}

function changeNewsBlock() {
	$("#CenterNews .centernewsmenublock").hide();
	$("#CenterNews .body").hide();
	$("#CenterNews .menu0").show();
	$("#CenterNews .newsblock0").show();

	$(".changeNews0").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu0").show();$(".newsblock0").show();return false;
	});
	$(".changeNews1").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu1").show();$(".newsblock1").show();return false;
	});
	$(".changeNews2").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu2").show();$(".newsblock2").show();return false;
	});
	$(".changeNews3").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu3").show();$(".newsblock3").show();return false;
	});
	$(".changeNews4").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu4").show();$(".newsblock4").show();return false;
	});

}


function changeNewsBlock2() {
	$("#CenterNews .centernewsmenublock").hide();
	$("#CenterNews .body").hide();
	$("#CenterNews .menu2").show();
	$("#CenterNews .newsblock2").show();

	$(".changeNews0").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu0").show();$(".newsblock0").show();return false;
	});
	$(".changeNews1").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu1").show();$(".newsblock1").show();return false;
	});
	$(".changeNews2").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu2").show();$(".newsblock2").show();return false;
	});
	$(".changeNews3").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu3").show();$(".newsblock3").show();return false;
	});
	$(".changeNews4").click(function(){
			$("#CenterNews .body").hide();$("#CenterNews .centernewsmenublock").hide();$("#CenterNews .menu4").show();$(".newsblock4").show();return false;
	});

}



function changeSitemap() {
	$("#sitemap #sitemapmenu2").hide();
	$("#sitemap #sitemap2").hide();
	$("#sitemap #sitemapmenu1").show();
	$("#sitemap #sitemap1").show();

	$(".changeSitemap1").click(function(){
			$("#sitemap #sitemapmenu2").hide();$("#sitemap #sitemap2").hide();$("#sitemap #sitemapmenu1").show();$("#sitemap1").show();return false;
	});
	$(".changeSitemap2").click(function(){
			$("#sitemap #sitemapmenu1").hide();$("#sitemap #sitemap1").hide();$("#sitemap #sitemapmenu2").show();$("#sitemap2").show();return false;
	});
}

function changeSitemap2() {
	$("#sitemap #sitemapmenu2").show();
	$("#sitemap #sitemap2").show();
	$("#sitemap #sitemapmenu1").hide();
	$("#sitemap #sitemap1").hide();

	$(".changeSitemap1").click(function(){
			$("#sitemap #sitemapmenu2").hide();$("#sitemap #sitemap2").hide();$("#sitemap #sitemapmenu1").show();$("#sitemap1").show();return false;
	});
	$(".changeSitemap2").click(function(){
			$("#sitemap #sitemapmenu1").hide();$("#sitemap #sitemap1").hide();$("#sitemap #sitemapmenu2").show();$("#sitemap2").show();return false;
	});
}

function changeBookCatMenu() {
	$("#searchByBookCategory .catmenublock").hide();
	$("#searchByBookCategory .titlemenu").hide();
	$("#searchByBookCategory #catmenublock1").show();
	$("#searchByBookCategory #titlemenu1").show();

	$(".titlemenuitem1").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu1").show();
			$("#searchByBookCategory #catmenublock1").show();
			return false;
	});
	$(".titlemenuitem2").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu2").show();
			$("#searchByBookCategory #catmenublock2").show();
			return false;
	});
	$(".titlemenuitem3").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu3").show();
			$("#searchByBookCategory #catmenublock3").show();
			return false;
	});
}

function changeBookCatMenu2() {
	$("#searchByBookCategory .catmenublock").hide();
	$("#searchByBookCategory .titlemenu").hide();
	$("#searchByBookCategory #catmenublock2").show();
	$("#searchByBookCategory #titlemenu2").show();

	$(".titlemenuitem1").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu1").show();
			$("#searchByBookCategory #catmenublock1").show();
			return false;
	});
	$(".titlemenuitem2").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu2").show();
			$("#searchByBookCategory #catmenublock2").show();
			return false;
	});
	$(".titlemenuitem3").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu3").show();
			$("#searchByBookCategory #catmenublock3").show();
			return false;
	});
}
function changeBookCatMenu3() {
	$("#searchByBookCategory .catmenublock").hide();
	$("#searchByBookCategory .titlemenu").hide();
	$("#searchByBookCategory #catmenublock3").show();
	$("#searchByBookCategory #titlemenu3").show();

	$(".titlemenuitem1").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu1").show();
			$("#searchByBookCategory #catmenublock1").show();
			return false;
	});
	$(".titlemenuitem2").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu2").show();
			$("#searchByBookCategory #catmenublock2").show();
			return false;
	});
	$(".titlemenuitem3").click(function(){
			$("#searchByBookCategory .titlemenu").hide();
			$("#searchByBookCategory .catmenublock").hide();
			$("#searchByBookCategory #titlemenu3").show();
			$("#searchByBookCategory #catmenublock3").show();
			return false;
	});
}

(function(){
	   var easing = 0.25;
	   var interval = 20;
	   var d = document;
	   var targetX = 0;
	   var targetY = 0;
	   var targetHash = '';
	   var scrolling = false;
	   var splitHref = location.href.split('#');
	   var currentHref_WOHash = splitHref[0];
	   var incomingHash = splitHref[1];
	   var prevX = null;
	   var prevY = null;

	   // ドキュメント読み込み完了時にinit()を実行する
	   addEvent(window, 'load', init);

	   // ドキュメント読み込み完了時の処理
	   function init(){
	     // ページ内リンクにイベントを設定する
	     setOnClickHandler();
	     // 外部からページ内リンク付きで呼び出された場合
	     if(incomingHash){
	       if(window.attachEvent && !window.opera){
	         // IEの場合はちょっと待ってからスクロール
	         setTimeout(function(){scrollTo(0,0);setScroll('#'+incomingHash);},50);
	       }else{
	         // IE以外はそのままGO
	         scrollTo(0, 0);
	         setScroll('#'+incomingHash);
	       }
	     }
	   }

	   // イベントを追加する関数
	   function addEvent(eventTarget, eventName, func){
	     if(eventTarget.addEventListener){
	       // モダンブラウザ
	       eventTarget.addEventListener(eventName, func, false);
	     }else if(window.attachEvent){
	       // IE
	       eventTarget.attachEvent('on'+eventName, function(){func.apply(eventTarget);});
	     }
	   }

	   function setOnClickHandler(){
	     var links = d.links;
	     for(var i=0; i<links.length; i++){
	       // ページ内リンクならスクロールさせる
	       var link = links[i];
	       var splitLinkHref = link.href.split('#');
	       if(currentHref_WOHash == splitLinkHref[0] && d.getElementById(splitLinkHref[1])){
	         addEvent(link, 'click', startScroll);
	       }
	     }
	   }

	   function startScroll(event){
	     // リンクのデフォルト動作を殺す
	     if(event){ // モダンブラウザ
	       event.preventDefault();
	       //alert('modern');
	     }else if(window.event){ // IE
	       window.event.returnValue = false;
	       //alert('ie');
	     }
	     // thisは呼び出し元になってる
	     setScroll(this.hash);
	   }

	   function setScroll(hash){
	     // ハッシュからターゲット要素の座標をゲットする
	     var targetEle = d.getElementById(hash.substr(1));
	     if(!targetEle)return;
	     //alert(scrollSize.height);
	     // スクロール先座標をセットする
	     var ele = targetEle;
	     var x = 0;
	     var y = 0;
	     while(ele){
	       x += ele.offsetLeft;
	       y += ele.offsetTop;
	       ele = ele.offsetParent;
	     }
	     var maxScroll = getScrollMaxXY();
	     targetX = Math.min(x, maxScroll.x);
	     targetY = Math.min(y, maxScroll.y);
	     targetHash = hash;
	     // スクロール停止中ならスクロール開始
	     if(!scrolling){
	       scrolling = true;
	       scroll();
	     }
	   }

	   function scroll(){
	     var currentX = d.documentElement.scrollLeft||d.body.scrollLeft;
	     var currentY = d.documentElement.scrollTop||d.body.scrollTop;
	     var vx = (targetX - currentX) * easing;
	     var vy = (targetY - currentY) * easing;
	     var nextX = currentX + vx;
	     var nextY = currentY + vy;
	     if((Math.abs(vx) < 1 && Math.abs(vy) < 1)
	       || (prevX === currentX && prevY === currentY)){
	       // 目標座標付近に到達していたら終了
	       scrollTo(targetX, targetY);
	       scrolling = false;
	       location.hash = targetHash;
	       prevX = prevY = null;
	       return;
	     }else{
	       // 繰り返し
	       scrollTo(parseInt(nextX), parseInt(nextY));
	       prevX = currentX;
	       prevY = currentY;
	       setTimeout(function(){scroll()},interval);
	     }
	   }

	   function getDocumentSize(){
	     return {width:Math.max(document.body.scrollWidth, document.documentElement.scrollWidth), height:Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)};
	   }

	   function getWindowSize(){
	     var result = {};
	     if(window.innerWidth){
	       var box = d.createElement('div');
	       with(box.style){
	         position = 'absolute';
	         top = '0px';
	         left = '0px';
	         width = '100%';
	         height = '100%';
	         margin = '0px';
	         padding = '0px';
	         border = 'none';
	         visibility = 'hidden';
	       }
	       d.body.appendChild(box);
	       var width = box.offsetWidth;
	       var height = box.offsetHeight;
	       d.body.removeChild(box);
	       result = {width:width, height:height};
	     }else{
	       result = {width:d.documentElement.clientWidth || d.body.clientWidth, height:d.documentElement.clientHeight || d.body.clientHeight};
	     }
	     return result;
	   }

	   function getScrollMaxXY() {
	     if(window.scrollMaxX && window.scrollMaxY){
	       return {x:window.scrollMaxX, y:window.scrollMaxY};
	     }
	     var documentSize = getDocumentSize();
	     var windowSize = getWindowSize();
	     return {x:documentSize.width - windowSize.width, y:documentSize.height - windowSize.height};
	   }

	 }());




$(document).ready(function(){
  $("table.stripe tr:even").addClass("even");
});


$(initRollOverImages);
$(initFlashBlock);
