


jQuery.easing.quart = function (x, t, b, c, d) {
	    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

var positionOffset=0;
var scrollTime=500;
var delayTime=200;


$(window).scroll(getScrollEvent);

var flag=false;
function getScrollEvent(){
	var targetOffset =$(document).scrollTop();
	var mainHeight=$('#main').height()-$("#scroll_btn").height();
	var targetHeight=targetOffset-positionOffset;
	
	//ボタンの下はみ出しの禁止
	if(targetHeight>mainHeight){
		targetHeight=mainHeight;
	}

	if(targetOffset>positionOffset){
		$("#scroll_btn").stop();
		$("#scroll_btn").animate({ top: targetHeight }, scrollTime, 'quart');
	}else{
		$("#scroll_btn").stop();
		$("#scroll_btn").animate({ top:0 }, scrollTime, 'quart');
	}	
}


function returnTop(){
	var $target = jQuery(document);
	$("#scroll_btn").stop();
	timer=setTimeout('startScroll()',delayTime);
}

function startScroll(){
	
	$("#scroll_btn").stop();
	$('html,body').animate({ scrollTop:0}, scrollTime*1.5, 'quart',function(){
		$("#scroll_btn").animate({ top:0 }, scrollTime*1, 'quart');
	})
	clearTimeout(timer);
}
