var windowY = 600;
var goto = 0;
var steps = 20;
var currentstep = 0;
var diff = 0;
var windowHeight = 0;
var browserHeight = 0;

function topOfPage() {
	if (document.body.scrollTop) {
		windowY = document.body.scrollTop;
	}
	else if (document.documentElement.scrollTop) {
		windowY = document.documentElement.scrollTop;
	}
	currentstep = 1;
	goto = 136;
	diff = windowY - goto;
	scrollPage();
}

function bottomOfPage() {
	if (document.body.scrollTop) {
		windowY = document.body.scrollTop;
		windowHeight = document.body.scrollHeight;
		browserHeight = window.innerHeight;
	}
	else if (document.documentElement.scrollTop) {
		windowY = document.documentElement.scrollTop;
		windowHeight = document.documentElement.scrollHeight;
		browserHeight = document.documentElement. clientHeight;
	}
	//alert(browserHeight);
	currentstep = 1;
	goto = windowHeight - browserHeight - 48;
	diff = windowY - goto;
	scrollPage();
}

function scrollPage() {
	if (currentstep <= steps) {
		var scrollby = windowY - Math.floor(diff*Math.sin(Math.PI*currentstep/(2*steps)));
		currentstep++;
		//alert(scrollby);
		window.scroll(0,scrollby);
		setTimeout('scrollPage()',10);
	}
}

function addKeyDetect() {
	if (window.addEventListener) {
		window.addEventListener('keyup', keyPress, false);	
	}
	else if (document.attachEvent) {
		document.attachEvent('onkeyup', keyPress);	
	}
	else {
		document.onkeyup = keyPress;	
	}
}

function keyPress (event) {
	var key = event.keyCode;
	//alert(key);
	if (key == 37) {pages.goBackJS();}
	else if (key == 38) {topOfPage();}
	else if (key == 39) {pages.goForwardJS();}
	else if (key == 40) {bottomOfPage();}
}

if (window.addEventListener) {
	window.addEventListener('load', addKeyDetect, false);	
}
else if (window.attachEvent) {
	window.attachEvent('onload', addKeyDetect);	
}
else {
	window.onload = addKeyDetect;	
}