var timer = 50;

function ScrollAreaA( _id ){
	
	var o = new Object();
	
	o.id = _id;
	o.targetID = "#" + o.id;// スクロールさせるID
	o.height = $(o.targetID).height();// liの数
	o.limit = o.height - 210;
	o.movePos = 10;// 一回の移動量
	o.count = 0;
	o.margin = 5;
	o.flag = null;
	o.intID;
	o.isMoving = false;
	
	o.init = function(){
		this.setBtnFunc();
	}
	
	o.scroll = function(){
		
		var nowPos = pixelToNumber( $(this.targetID).css("top") );
		var nextPos;
		if( this.flag == "dn" ){
			if( nowPos > -this.limit ){
				nextPos = nowPos - this.movePos;
			}
		}else if( this.flag == "up" ){
			if( nowPos < 0 ){
				nextPos = nowPos + this.movePos;
			}else if( nowPos >= 0 ){
				nextPos = 0;
			}
		}
		
		$(this.targetID).css("top",nextPos);
		
	}
	
	o.scrollUp = function(){
		this.intervalClear();
		this.flag = "up";
		this.intID = setInterval( function(){o.scroll();}, timer );
	}
	
	o.scrollDown = function(){
		this.intervalClear();
		this.flag = "dn";
		this.intID = setInterval( function(){o.scroll();}, timer );
	}
	
	o.rollout = function(){
		this.intervalClear();
		this.flag = null;
	}
	
	o.intervalClear = function(){
		clearInterval( this.intID );
	}
	
	o.setBtnFunc = function(){
		$("#" + this.id + "-btn-up").mouseover(function(){
			o.scrollUp();
		});
		$("#" + this.id + "-btn-up").mouseout(function(){
			o.rollout();
		});
		$("#" + this.id + "-btn-dn").mouseover(function(){
			o.scrollDown();
		});
		$("#" + this.id + "-btn-dn").mouseout(function(){
			o.rollout();
		});
	}
	
	o.init();
	
}




// css内のpositionの値（String）をNumberに変換
function pixelToNumber( val ){
	var newVal = new Number( val.slice(0,-2) );
	return newVal;
}


$(function(){
	var aaa = new ScrollAreaA( "sm-column-topic1" );
	var bbb = new ScrollAreaA( "sm-column-topic2" );
});
