/*石田大成社NINOオリジナルアンカースクロールスクリプト*/
/*パクらないで！*/
/*Win:IE6,NN4,7,NN8,Opera8.5,Firefox1*/
/*Mac:IE5.1(Classic),IE5.2(osx),NN4,7(classic),NN7.1,Opera8.5,Firefox1,safari1.2*/

var timeID;

var IE = navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1;
var OPERA = navigator.userAgent.indexOf("Opera") != -1;
var MAC = navigator.userAgent.indexOf("Mac") != -1;

wH = 0;
function getInnerSize(){
	//ウィンドウサイズを取得するスクリプト
	if( document.all || ( document.getElementById && IE )){
		wH = document.body.clientHeight;

	}else if( document.layers || document.getElementById ){
		wH = window.innerHeight;
	}
}
//getInnerSize();

idouSaki = 0;
function getAnchorPos(elementID){//:::::::::::::::::::::::::::::::>-----------------------------------------------------
	//ターゲットアンカーのx座標、y座標を求める
	var objnew = new Object();
	if( document.getElementById ){
		var obj = document.getElementById(elementID);
		objnew.y = obj.offsetTop;
		while((obj = obj.offsetParent) != null){
			objnew.y += obj.offsetTop;
		}
	}else if( document.all ){
		var obj = document.all(elementID);
		objnew.y = obj.offsetTop;
		while((obj = obj.setParent) != null){
			objnew.y += obj.offsetTop;
		}
	}else if( document.layers ){
		objnew.y = document.anchors[elementID].y;
	}
	else{
		objnew.y = 0;
	}

//alert(objnew.y);

	//ページの長さ取得
	if( document.all ){
		if(OPERA){
			pH = document.body.scrollHeight;//---Operaでウィンドウの高さを取得してしまう
		}else{
			if(MAC){
				pH = document.body.offsetHeight;//---MacIE用
			}else{
				if(document.body.scrollHeight){
					pH = document.body.scrollHeight;
				}
			}
		}
		//pH = (document.all)? document.body.scrollHeight : document.body.height;//------これじゃMacIEで値とれない
	}else{
		pH = document.height+5 ;
	}

	//移動先決定--------------
/*	if( (pH - wH) < objnew.y ){
		idouSaki = objnew.y - ( wH - ( pH - objnew.y ));
	}else{
		idouSaki = objnew.y;
	}
*/

idouSaki = objnew.y;

//alert(pH+':'+wH);

	flag = false;
	idou();
}

function getScrollTop(){//:::::::::::::::::::::::::::::::>-----------------------------------------------------
	//現在の縦位置を取得
	if(IE){
		return document.body.scrollTop;
	}else if(window.pageYOffset){
		return window.pageYOffset;
	}else{
		return 0;
	}
}

//動きの滑らかさ
idouRitu = 0.2;
//動くスピード
speed = 1;
//最終位置の吸着幅
gosa = 1;

oldysc = 0;
flag = false;
function idou(){
	//flagがfalseの場合のみ通る
	if(!flag){
		ysc = getScrollTop();
		ysc += (( idouSaki - ysc ) *idouRitu ) *speed;
		//Stop&最終位置に移動
		if(( idouSaki-gosa < ysc && ysc < idouSaki+gosa ) || ( ysc == oldysc )){
			ysc = idouSaki;
			flag = true;
		}
		window.scrollTo(0,ysc);
		oldysc = ysc;
	}

	if(!flag){
		timeID = setTimeout("idou()",100);
	}else{
		clearTimeout(timeID);
	}
}
