
// JavaScript Document
	var intervalID;
	var interval_cnt=0;
	var totopY;
	function moveToTop(){
		//alert("moveToTOp");
		clearInterval(intervalID);
		interval_cnt=0;
		intervalID=setInterval("_moveToTop()",15);
		//document.getElementById("totop").style.top=toY()+"px";
	}
	function _moveToTop(){
		if(interval_cnt>5){
			
		totopY=currentY()+(toY()-currentY())*0.05;
		if(Math.abs(toY()-totopY)<1){
			document.getElementById("totop").style.top=toY()+"px";
			clearInterval(intervalID);
		}else{
			//alert("toY:"+toY()+". currentY:"+currentY()+", totopY:"+totopY);
			document.getElementById("totop").style.top= Math.round(totopY)+"px";
		}
		}else{
			interval_cnt++;
		}
		
	}
	
	function toY(){
		return document.scroll()+getH()-80;
	}
	function currentY(){
		var top=document.getElementById("totop").style.top;
		
		return Number(top.substr(0,top.length-2));
	}
		
	document.scroll = function(){
		 return this.body.scrollTop  || this.documentElement.scrollTop;
	};
	
	
		
	function getH(){
			var currentH;
			if (!document.all && (document.layers || document.getElementById)) {
				currentH=Number(window.innerHeight);
			}
			// ウィンドウズIE 6・標準モード。
			else if (document.getElementById && (document.compatMode=='CSS1Compat')) {
				currentH=Number(document.documentElement.clientHeight);
			}
			// その他のIE。
			else if (document.all) {
				currentH=Number(document.body.clientHeight);
			}
			return currentH;
	}
window.onload=moveToTop;
window.onscroll=moveToTop;