/*-----------------------------------------------*/
//sksp.js
/*-----------------------------------------------*/

function $(id) {
	return document.getElementById(id);
}

function addEvent(o, e, f, c) {
	if (e == 'DOMMouseScroll'){
		if (window.addEventListener) window.addEventListener('DOMMouseScroll', f, false);
			window.onmousewheel = document.onmousewheel = f;
	}
	else {
	(o.addEventListener) ? o.addEventListener(e, f, c) : o.attachEvent('on' + e, f);
	}
}



addEvent(window,"load", function(){
	var anchor = $("top-of-page").getElementsByTagName("a")[0];
	addEvent(anchor,"click",anchorSet,false);
},false);

function anchorSet(e){
	(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	scrollInterval = setInterval(smoothScroll, updateDuration);
}


var scrollInterval = null;
var speed = 0.9;
var updateDuration = 10;

function smoothScroll(e) {
	clearInterval(scrollInterval);
	var top = document.body.scrollTop || document.documentElement.scrollTop;
	if (top > 0) {
		top = Math.floor(top * speed);
		window.scrollTo(0, top);
		scrollInterval = setInterval(smoothScroll, updateDuration);
	}
}

var stopScroll = function (e) {
			if (scrollInterval != null) {
				clearInterval(scrollInterval);
				scrollInterval = null;
			}
		};
		
addEvent(document, 'mousedown', stopScroll, false);
addEvent(window, 'DOMMouseScroll', stopScroll, false);



