// JavaScript Document

/*

_id : id名
_visible : 表示させる数

*/

function ScrollAreaA( _id, _visible, _margin ){
	
	var o = new Object();
	
	o.id = _id;
	o.targetID = "#" + o.id;// スクロールさせるID
	o.len = $("li",o.targetID).length;// liの数
	o.limit = o.len - _visible;// 何回スクロールできる回数
	o.visible = _visible;
	o.count = 0;
	o.margin = _margin;
	o.isMoving = false;
	
	o.init = function(){
		this.setBtnFunc();
	}
	
	o.scroll = function( nextPos ){
		
		$( this.targetID ).animate(
			{ top:nextPos },
			{ duration:1000, easing:"easeOutQuad", complete:function(){ o.isMoving = !o.isMoving } }
		);
		
	}
	
	o.scrollUp = function(){
		if(this.count > 0 && !this.isMoving){
			this.isMoving = !this.isMoving;
			this.count--;
			var nListHeight = $(this.targetID + " li:eq(" + (this.count) + ")").height();
			var nowPos = pixelToNumber( $(this.targetID).css("top") );
			var nextPos = nowPos + nListHeight + this.margin;
			this.scroll( nextPos );
		}
	}
	
	o.scrollDown = function(){
		if(this.count < this.limit && !this.isMoving){
			this.isMoving = !this.isMoving;
			this.count++;
			var nListHeight = $(this.targetID + " li:eq(" + (this.count-1) + ")").height();
			var nowPos = pixelToNumber( $(this.targetID).css("top") );
			var nextPos = nowPos - nListHeight - this.margin;
			this.scroll( nextPos );
		}
	}
	
	o.setBtnFunc = function(){
		$("#" + this.id + "-btn-up").click(function(){
			o.scrollUp();
		});
		$("#" + this.id + "-btn-dn").click(function(){
			o.scrollDown();
		});
	}
	
	o.init();
	
}




// css内のpositionの値（String）をNumberに変換
function pixelToNumber( val ){
	var newVal = new Number( val.slice(0,-2) );
	return newVal;
}


$(function(){
	var aaa = new ScrollAreaA( "ind-sm-list", 1, 15 );
	var bbb = new ScrollAreaA( "ind-blog-list", 1, 13 );
});