var easing = 0.5;
var interval = 10;
var d = document;
var scrolling = false;
var targetY = 0;
var prevY = null;



function setScroll(){
	easing = 0.5;
	var y = 0;
	var maxScroll = getScrollMax();
	targetY = Math.min(y, maxScroll);
	if(!scrolling){
 		scrolling = true;
 		scroll();//
	}
}

function _setScroll(){
	easing = 0.8;
	var y = 0;
	var maxScroll = getScrollMax();
	targetY = Math.min(y, maxScroll);
	if(!scrolling){
 		scrolling = true;
 		scroll();//
	}
}

function scroll(){
	var currentY = d.documentElement.scrollTop || d.body.scrollTop;
	var vy = (targetY - currentY) * easing;
	var nextY = currentY + vy;
	if((Math.abs(vy) < 1) || (prevY === currentY)){
 		scrollTo( 0, targetY);
 		scrolling = false;
 		prevY = null;
 		return;
	}else{
 		scrollTo( 0, parseInt(nextY));
 		prevY = currentY;
 		setTimeout(function(){scroll()},interval);//
	}
}

function getDocumentSize(){
	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}

function getWindowSize(){
	var result = {};
	if(window.innerWidth){
 		var box = d.createElement('div');
 		with(box.style){
		position = 'absolute';
		top = '0px';
		left = '0px';
		width = '100%';
		height = '100%';
		margin = '0px';
		padding = '0px';
		border = 'none';
		visibility = 'hidden';
 		}
 		d.body.appendChild(box);
 		var height = box.offsetHeight;
 		d.body.removeChild(box);
 		result = height;
	}else{
 		result = d.documentElement.clientHeight || d.body.clientHeight;
	}
	return result;
}

function getScrollMax() {
	if(window.scrollMaxY){
 		return window.scrollMaxY;
	}
	return ( getDocumentSize() - getWindowSize() );
}
function scrollTop(){
	scrollTo( 0, 0);
}
