// JavaScript Document

// Easingの追加
jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

//イージング移動
jQuery(document).ready(function(){
	jQuery('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				if ($target.attr('id') == 'page_top') {
					//アンカーターゲットが「page_top」の時
					var targetOffset = 0;
				} else {
					var targetOffset = Math.round($target.offset().top) - 20;  //アンカー位置からマイナス30px
					
					//ドキュメントの高さ
					var docH = Math.max.apply( null, [document.body.clientHeight , document.body.scrollHeight, document.documentElement.scrollHeight, document.documentElement.clientHeight] );
					
					//クライアント領域（ウィンドウの高さ）を求める
					var cliH;
					if ((!document.all || window.opera) && document.getElementById) {
						// IE以外。
						cliH = window.innerHeight;
					} else if (document.getElementById && (document.compatMode=='CSS1Compat')) {
						// ウィンドウズIE 6・標準モード。
						cliH = document.documentElement.clientHeight;
					} else if (document.all) {
						// その他のIE。
						cliH = document.body.clientHeight;
					}
					
					var maxH = docH - cliH;
					
					//targetOffsetがmaxHよりも大きいとイージング途中で移動しきってしまうので、maxHをtargetOffsetにセットし直す。
					if(targetOffset > maxH) {
						targetOffset = maxH;
					}
				}
			jQuery('html,body').animate({ scrollTop: targetOffset }, 1000, 'quart');
			return false;
			}
		}
	});

});
