/* 左ナビ移動スクリプト */

//ナビゲーションの表示位置
var timer;
var offsetTop = -270;
var navID="leftmenu";
var totalHeight;
var menulHeight;
var scrollHeight;

function mvMenuTimer(){
	clearInterval(timer);
	
	totalHeight = document.getElementById("container").offsetHeight;
	menuHeight = document.getElementById("leftmenu").offsetHeight;
	scrollHeight = totalHeight - menuHeight + offsetTop;
	
	if(document.getElementById(navID) != null){
		timer=setTimeout("mvMenu()",50);
	}else{
		timer=setTimeout("mvMenuTimer()",50);
	}
}

//移動用関数
function mvMenu(){
	pastYcss = document.getElementById(navID).style.top;
	
	//現在のスクロール座標を取得
	if(document.all){
		//IEなどのブラウザ
		nowY = document.documentElement.scrollTop;
	}else{
		//それ以外のブラウザ
		nowY = self.pageYOffset;
	}
	nowY += offsetTop;
	
	if(nowY < 0){
		nowY = 0;
	}else if(nowY > scrollHeight){
		nowY = scrollHeight;
	}
	
	pastY = pastYcss.split("px");

	movY = nowY + ((pastY[0] - nowY) * 0.85);

	//メニューのブロックを移動させる
	if(document.getElementById){
		document.getElementById(navID).style.top = movY + "px";
	}else if(document.all){
		document.all(navID).style.pixelTop = movY - document.all(navID).style.pixelTop;
	}

	if(Math.abs(pastY[0] - nowY) > 1){
		timer=setTimeout("mvMenu()",10)
	}

}

window.onscroll=mvMenuTimer;

