var timerID = 0;
var upSpeed = 10;
var downSpeed = -10;
var interval = 100;
var position = 'top';//top - middle - bottom
var nowPosition;

//それぞれのIDの現在の状態 moveflag=0; topが0 / moveflag=1; topが-の途中 / moveflag=2; topが-のmax
function isPosition(pos) {

	if(position == pos){
		return 1;
	}else{
		return 0;
	}

}

function setPosition(pos) {
	position = pos;
}

function scrollUp(listid, areaid) {
	if(!isPosition('top')){
		//alert('top');
		timerID = setTimeout("scrollUp(listid,areaid)", 50);
		moveByLAYER(listid,0,upSpeed);
	}
	if(nowPosition >= 0){
		//alert('top');
		stopScroll();
		setPosition('top');
	}

}

function scrollDown(listid, areaid) {

	range = getLayHightOj(areaid) - getLayHightOj(listid);

	if (navigator.userAgent.indexOf("Mac") >= 0 && navigator.appName.indexOf("Microsoft") >= 0) {

	}else{
		range = range + 10;
	}

	//alert(range);
	//alert(isPosition('bottom'));
	
	//alert(downSpeed);
	//alert(listid);
	//moveByLAYER(listid,0,downSpeed);
	
	if(!isPosition('bottom')){
		//alert('bottom');
		//scrollDown(listid,areaid);
		timerID = setTimeout("scrollDown(listid,areaid)", 50);
		moveByLAYER(listid,0,downSpeed);
	}
	//alert(range);
	if(nowPosition <= range){
		//alert('nowposition:'+nowposition);
		//alert('range:'+range);
		stopScroll();
		setPosition('bottom');
	}
}

function stopScroll(){
	//alert('aa');
	if(timerID != '') clearTimeout(timerID)
}


function moveByLAYER(layerID,offsetx,offsety){

	var oj = getLayStyleOj(layerID);

	if(document.getElementById){	//e5,e6,n6,n7,m1,o6,o7,s1用

		oj.left=parseInt(oj.left)+parseInt(offsetx )+'px'
		oj.top =parseInt(oj.top) +parseInt(offsety)+'px'
		nowPosition = parseInt(oj.top);
		setPosition('middle');

	} else if(document.all){		//e4用

		oj.pixelLeft += offsetx
		oj.pixelTop  += offsety
		nowPosition = parseInt(oj.top);
		setPosition('middle');

	}
}

//--layerIDで指定したオブジェクトをリターン(必ずonload後に実行すること)

function getLayStyleOj(layerID){  

	if(document.getElementById){		//e5,e6,n6,n7,m1,o6,o7,s1用
		return document.getElementById(layerID).style;
	}else if(document.all){			//e4用
		return document.all(layerID).style;
	}else if(document.layers){			//n4用
		return document.layers[layerID];
	}
}

function getLayHightOj(layerID){  

	if(document.getElementById){
		return document.getElementById(layerID).offsetHeight;
		//e5,e6,n6,n7,m1,o6,o7,s1用
	}else if(document.all){
		return document.all(layerID).offsetHeight;
		//e4用
	}
}
