
function GetScrollSize () {

	this.X = (window.pageXOffset) ? window.pageXOffset :
			 (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft :
			 (document.body) ? document.body.scrollLeft :
			 undefined;

	this.Y = (window.pageYOffset) ? window.pageYOffset :
			 (document.documentElement.scrollTop) ? document.documentElement.scrollTop :
			 (document.body) ? document.body.scrollTop :
			 undefined;

	return this;

}

function GetPosition (target) {

	try {
		this.X = target.offsetLeft;
		this.Y = target.offsetTop;
		if (target != document.body) {
			var temp = target.offsetParent;
			while (temp != document.body) {
				this.X += temp.offsetLeft;
				this.Y += temp.offsetTop;
				temp = temp.offsetParent;
				}
			}
		this.X += document.body.offsetLeft;
		this.Y += document.body.offsetTop;
		return this;
		} catch (e) {
		return null;
		}

}

function GoScroll () {
	if (document.getElementById("sidemenu")){
	// メニューまでのウィンドウ上部からのオフセット値
	var menuOffset=185;
	// メニューのスクロール速度 大きければ大きい程遅い
	var scrollSpeed=5;

	var Size = new GetScrollSize();
	var Pos = new GetPosition(document.getElementById("sidemenu"));
	if (Size.Y > menuOffset){
		var Offset=0;
	}
	else{
		var Offset=menuOffset - Size.Y;	
	}

	var Distance = (Size.Y + Offset - Pos.Y)/scrollSpeed;

	document.getElementById("sidemenu").style.top = Math.round(Pos.Y + Distance) + "px";
	}
}

window.onload = function () {
	var smoothing=10;
	// 更新間隔（ミリ秒）
	setInterval("GoScroll()", smoothing);
}

//-->

