﻿

var followSpeed
var followTimeSpeed
var followTimer;
var followHeightLimit
var followSMenuID
//ドキュメントをとっておく
var documentS
// スクロール量 ---------------------------------
var isWin9X
var isIE
var isOpera
var isSafari

 var followMenuTopMargin
 var followGoY
 
 var followVY
var followNowY

followDisplayTimer = setTimeout("laygyDisplayInit()",3000);
function laygyDisplayInit(){
	
	document.getElementById(followSMenuID).style.display="block"
}

 followTimer = setTimeout("laygyInit()",1000);



function followSetting(){
	
followSpeed = 15;
followTimeSpeed = 200;
followTimer;
followHeightLimit = 0;
followSMenuID="scrollup"
//ドキュメントをとっておく
documentS=window.document
// スクロール量 ---------------------------------
isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
if (isOpera) isIE = false;
isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0);

followMenuTopMargin = -380
followGoY
 
followVY=0
followNowY=0

myFollowScroller(20)
 followTimer = setTimeout("followpageScroll()",5);
}

function laygyInit(){
	
	followSetting()	
}

function followpageScroll(){
//	document.write("うごいてんの？")
followInitMenu()
}
function getScrollPosition() {

	var obj = new Object();

	obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	obj.y = document.documentElement.scrollTop  || document.body.scrollTop;

	if(isSafari){
//		obj.x = document.body.scrollLeft;
//		obj.y = document.body.scrollTop;
	}
	
	return obj;
}
//ウィンドウ・サイズを取得
function getScreenSize() {
	var obj = new Object();
	if (!isSafari && !isOpera) {
		obj.x = document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth;
		obj.y = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
	} else {
		obj.x = window.innerWidth;
		obj.y = window.innerHeight;
	}
	obj.mx = parseInt((obj.x)/2);
	obj.my = parseInt((obj.y)/2);
	return obj;
}



// var followMenuTopMargin = -380
// var followGoY
function followCheckMenu() {
	//document.getElementById(followSMenuID).style.position="absolute"
	/////////////////////////////////////////////////////////////
	
	var isMSIE = /*@cc_on!@*/false;
	if (isMSIE) {
	//alert("IE")
		//followMenuTopMargin =getScrollPosition().y*-1-200
		//followMenuTopMargin =getScreenSize().y*-1+125//フッターの上
		followMenuTopMargin =getScreenSize().y*-1+125-51
	}else{
	//alert('not IE!');	
		//followMenuTopMargin = self.pageYOffset*-1-200
		//followMenuTopMargin =getScreenSize().y*-1+40+74+10//フッターの上
		followMenuTopMargin =getScreenSize().y*-1+125-51
	}
	
	
	/////////////////////////////////////////////////////////
	if(document.body.offsetHeight > followHeightLimit) {
		//document.getElementById("IF3").innerHTML="IF3="+"+全体else1111px"
			var reTimer = followTimeSpeed;
			var startPoint = parseInt(document.getElementById(followSMenuID).style.top,10);
		
			var isMSIE = /*@cc_on!@*/false;
			if (isMSIE) {
				//alert("IE")
				//var endPoint = document.body.scrollTop;
				var endPoint =getScrollPosition().y;
			} else {
				//alert('not IE!');
				var endPoint = self.pageYOffset;
			}
			//document.getElementById("scrollTop").innerHTML="scrollTop="+endPoint
			/*
			//デバッグ開始
			document.getElementById("reTimer").innerHTML="reTimer="+reTimer
			document.getElementById("startPoint").innerHTML="startPoint="+startPoint
			document.getElementById("endPoint").innerHTML="endPoint="+endPoint
			document.getElementById("offsetHeight").innerHTML="document.body.offsetHeight="+document.body.offsetHeight
			
			//デバッグ終了
		*/

			if(followMenuTopMargin <= endPoint ){
				
				
				endPoint=endPoint - followMenuTopMargin
				//document.getElementById("IF").innerHTML="IF="+"endPoint=endPoint - followMenuTopMargin"
			}else{
				
				endPoint=0;
				//document.getElementById("IF").innerHTML="IF="+"endPoint=0;"
			}
		
			if(startPoint != endPoint) {
				moveAmount = Math.ceil(Math.abs(endPoint - startPoint) / 15);

				if(endPoint<startPoint) {
					
					//document.getElementById("IF2").innerHTML="IF2="+"-moveAmount"
					//document.getElementById(followSMenuID).style.top=parseInt(document.getElementById(followSMenuID).style.top,10) -moveAmount+"px"
					followGoY=parseInt(document.getElementById(followSMenuID).style.top,10) -moveAmount
					//easingBack(followGoY)
					
				}else{
					//document.getElementById("IF2").innerHTML="IF2="+"+moveAmount"
					//document.getElementById(followSMenuID).style.top=parseInt(document.getElementById(followSMenuID).style.top,10) + moveAmount+"px"
					followGoY=parseInt(document.getElementById(followSMenuID).style.top,10) + moveAmount
					//easingBack(followGoY)
				}
			
				reTimer = followSpeed;
			}
	} else {//if(document.body.offsetHeight > followHeightLimit) {のelse
		
			//document.getElementById(followSMenuID).style.top= 0+"px"
			followGoY=0
			//easingBack(followGoY)
			//document.getElementById("IF3").innerHTML="IF3="+"+全体else0px"
	}
		/////////////////////////////////////////////////////////////////////IEがページ下でとまってるよ
		/**/
		if (isMSIE) {
			//alert("IE")
			//document.getElementById(followSMenuID).style.top= 100+"px"
			//document.getElementById("scrollup").style.top= -100+"px"
		}else{
			//alert('not IE!');
			///document.getElementById(followSMenuID).style.top= 0+"px"
		}
		
		
	//document.getElementById(followSMenuID).style.top=followGoY
	easingNone(followGoY)
	followTimer = setTimeout("followCheckMenu();",reTimer);
}
function followInitMenu() {
	/**/
	//document.getElementById(followSMenuID).style.zIndex=123456
	//document.getElementById(followSMenuID).style.position = "absolute";
	/**/
	//document.getElementById(followSMenuID).style.position = "absolute";
	/**/
	if(document.body.offsetHeight > followHeightLimit){ 
		//document.getElementById(followSMenuID).style.top= document.body.scrollTop+"px"
	}
	
	//easingNone(followGoY)
	
	followCheckMenu();
	
	
	//document.getElementById("scrolluper").style.top= 100+"px"
}
//var followVY=0
//var followNowY=0
/**/

function myFollowScroller(N){
	//document.getElementById("scrolluperarrow").style.top=N+"px"
	//document.getElementById(followSMenuID).style.position = "absolute";
	document.getElementById(followSMenuID).style.top=N+"px"
}

function easingNone(targetY){
	followNowY=document.getElementById(followSMenuID).style.top
	followNowY=targetY
	//document.getElementById(followSMenuID).style.top=followNowY+"px"
	//document.getElementById("scrolluperarrow").style.top=followNowY+"px"
	//documentS.getElementById("scrolluperarrow").style.top=followNowY+"px"
	myFollowScroller(followNowY)
	  //デバッグ
	  /*
  document.getElementById("targetY").innerHTML="targetY="+targetY
  //document.getElementById("ay").innerHTML="ay="+ay
 // document.getElementById("followVY").innerHTML="followVY="+followVY
  document.getElementById("followNowY").innerHTML="followNowY="+followNowY
  */
  //デバッグ
}

function easingBack(targetY){
	
	
	followNowY=document.getElementById(followSMenuID).style.top
	var followFriction=0.91
	//var followSpring=1.9
	var followSpring=0.1
	
	//followNowY=targetY
  // var ax:Number = (targetX - sprite.x) * followSpring;  
  /**/
  
  var sa=parseInt(targetY) - parseInt(followNowY)
   var ay= (sa) * followSpring;  
  // vx += ax;  
   followVY += ay;  
  // vx *= followFriction;  
   followVY *= followFriction;  
 //  sprite.x += vx;  
 // followNowY += followVY; 
  followNowY=parseInt(followNowY)+parseInt(followVY);
  now=Math.ceil(followNowY)
  //document.getElementById(followSMenuID).style.top=followNowY+"px"
  //documentS.getElementById(followSMenuID).style.top=followNowY+"px"
  window.document.getElementById(followSMenuID).style.top=followNowY+"px"
  //document.getElementById("scrollup").style.top=followNowY+"px"
  
  //デバッグ
  /*
  document.getElementById("targetY").innerHTML="targetY="+targetY
  document.getElementById("followNowY").innerHTML="followNowY="+followNowY
  document.getElementById("sa").innerHTML="sa="+sa
  document.getElementById("ay").innerHTML="ay="+ay
  document.getElementById("followVY").innerHTML="followVY="+followVY
  

  
  
 
  */
  //デバッグ
  
  
}
//myTimeOut=setTimeout("initer",1000)


//followpageScroll()
//initer()
//

//window.onload = followInitMenu
//document.body.onload=followInitMenu

//document.getElementById("scrolluper").style.top= 100+"px"
//document.body.getElementById("scrollTop").style.top= 100+"px"