/*
1.ロールオーバー
2.文字サイズ変更
*/

//1.ロールオーバー
(function($){
	$.fn.rollover = function(postfix) {
		postfix = postfix || '_on';
		return this.not('[src*="'+ postfix +'."]').each(function() {
				var img = $(this);
				var src = img.attr('src');
				var src_on = [
						src.substr(0, src.lastIndexOf('.')),
						src.substring(src.lastIndexOf('.'))
				].join(postfix);
				img.hover(
						function() {
								img.attr('src', src_on);
						},
						function() {
								img.attr('src', src);
						}
				);
		});
	};
})(jQuery);



$(function(){
					 
	$('img.imgover').rollover();			 
	
//2.文字サイズ変更
	var cookieName ='fontSize';
	$('#hNav').before('<dl class="fontSize" id="size-m"><dt><img src="/common/images/txt_fontsize.gif" alt="文字サイズの変更" width="85" height="12" /></dt><dd class="size-s">小</dd><dd class="size-m">中</dd><dd class="size-l">大</dd></dl>');
	if($.cookie(cookieName)!=null||''){
		setFontSize($.cookie(cookieName));
	}
	$('dl.fontSize dd').bind('click',function(){
		setFontSize($(this).attr('class'));
	});
	function setFontSize(fontSize){
		$('body').attr('class',fontSize);
		$('dl.fontSize').attr('id',fontSize);
		$.cookie(cookieName, fontSize, {path: '/' });
	}
	
//3.フッター調整
	$("#fNav li:last-child")
    .css({border:"none"})
		
//4.サイドナビ調整
	$("#sNav li:first-child")
    .css({background:"none"})

//5.パンくず調整
	$("#path li:last-child")
    .css({margin:"0.1em 0 0 0"})

//6.研究員紹介ページ調整
	$('.namecard').each(function(){
    jQuery(this).find("li:odd").addClass("odd");
	});
	
	
	$('.namecard li.odd').after('<li class="clear"></li>');

});

//7.ページトップへ
function backToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
		if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
		}
		if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
		}
	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
	if (x > 0 || y > 0) {
	window.setTimeout("backToTop()", 25);
	}
}

