

var ScrollButton = 0;
var ScrollStatus = 0;
var ScrollStep = ScrollButton ? 6 : 2;
var ScrollTimeout = ScrollButton ? 50 : 50;
var ScrollTimer;
var ScrollHeight = 0;
var ScrollSize = 0;
var ScrollSpeeder = 3;

function startscrollup2(){
	ScrollStatus = ScrollSpeeder;
	scroll(1);
	return false;
}
function startscrolldown2(){
	ScrollStatus = (-1*ScrollSpeeder);
	scroll(1);
	return false;
}
function startscrollup(){
	ScrollStatus = 1;
	scroll(1);
	return false;
}
function startscrolldown(){
	ScrollStatus = -1;
	scroll(1);
	return false;
}
function stopscroll(a){
	if(a==1 && ScrollStatus == ScrollSpeeder) ScrollStatus = 1;
	else if(a==1 && ScrollStatus == (-1*ScrollSpeeder)) ScrollStatus = -1;
	else ScrollStatus = 0;
	if(!ScrollStatus && ScrollTimer) clearTimeout(ScrollTimer);
}
function scroll(cont){
	if(ScrollTimer) clearTimeout(ScrollTimer);
	if(!ScrollStatus) return;

	var c=document.getElementById("content");
	var pos = parseInt(c.style.top);
	if(isNaN(pos)) pos=0;

	if(ScrollStatus < 0){
		if(pos<(-1*ScrollHeight)) pos=pos+ScrollHeight;
	}
	else if(ScrollStatus > 0){
		if(pos>0) pos=pos-ScrollHeight;
	}
	c.style.top = pos + (ScrollStatus * ScrollStep) +"px";
	if(cont) ScrollTimer=setTimeout('scroll('+cont+');',ScrollTimeout);
}
function h_init(){
	h_buttonparam();
	var b=document.getElementById("buttonBox");
	if(ScrollButton){
		b.style.display = "";
	}else{
		b.style.display = "none";
	}
	var m=document.getElementById("middleBox");
	ScrollSize = h_height();
	m.style.height = ScrollSize+"px";
	var c=document.getElementById("content");
	ScrollHeight=parseInt(c.offsetHeight);
	var tmp=c.innerHTML;

	c.innerHTML=tmp+c.innerHTML;
	var tmph=ScrollHeight;
	cnt=2;
	if(ScrollHeight>0 && ScrollSize>0) while(tmph<ScrollSize) { c.innerHTML+=tmp; tmph+=ScrollHeight; cnt++;};

	c.style.top=(-1*ScrollHeight);

	if(!ScrollButton){
		startscrolldown();
		c.onmouseover=function(){ stopscroll(0); }
		c.onmouseout=function(){ ScrollTimer=setTimeout('startscrolldown();',ScrollTimeout); }
	}
}
function h_height(){
	var frame = parseInt(document.documentElement.clientHeight, 10);
	var mBox = document.getElementById("middleBox");
	if(!mBox) return 0;
	var top = parseInt(mBox.offsetTop, 10);
	var bBox = document.getElementById("bottomBox");
	if(!bBox) return 0;
	var bottom = parseInt(bBox.offsetTop, 10);
	return Math.max(0,(bottom-top));
}
function h_buttonparam(){
	var query = window.location.toString();
	var params = query.split('#');
	if(params[1]!="gomb") return;
	ScrollButton=1;
}
