Fly.ListScroller = function(element, options)
{
	this.options = options || { };
	
	this.options.viewHeight = this.options.viewHeight || '200px';
	
	this.element = element;

	if (this.element.clientHeight-32 < parseInt(this.options.viewHeight))
	{
		this.element.style.marginTop = '16px';
	}
	else
	{	
		this.scrollSpeed = 4;
	
		Fly.Dom.create(
			['div',{'=':'scroller',style:{textAlign:'center'}},
				['img',{'=':'uparrow',id:'navUp-arrow',style:{width:'68px',height:'10px'},src:'/img/detail-arrowup.gif'}],
				['div',{'=':'viewport',style:{textAlign:'left',position:'relative',height:this.options.viewHeight,overflow:'hidden'}},
					['div',{'=':'content',style:{position:'absolute',left:'0',top:'0'}}]
				],
				['img',{'=':'dnarrow',id:'navDown-arrow',style:{width:'68px',height:'10px'},src:'/img/detail-arrowdown.gif'}]
			], this
		);
	
		this.uparrow.onmouseover = this.startScrollUp.bind(this);
		this.dnarrow.onmouseover = this.startScrollDown.bind(this);
			
		this.uparrow.onmouseout = this.stopScrolling.bind(this);
		this.dnarrow.onmouseout = this.stopScrolling.bind(this);
			
		this.element.parentNode.replaceChild(this.scroller,this.element);
		this.content.appendChild(this.element);
	}	

	this.element.style.position = 'static';
	this.element.style.visibility = 'visible';
};

Fly.ListScroller.prototype.startScrollDown = function()
{
	this.stopScrolling();
	
	this.motion = new PeriodicalExecuter(this.scrollDown.bind(this), .05);
}

Fly.ListScroller.prototype.scrollDown = function()
{
	if (parseInt(this.content.style.top) >= (this.content.clientHeight*(-1)+this.viewport.clientHeight))
	{
		this.content.style.top = parseInt(this.content.style.top) - this.scrollSpeed + "px";
	}
	else
	{
		this.stopScrolling();
	}
}

Fly.ListScroller.prototype.startScrollUp = function()
{
	this.stopScrolling();
	
	this.motion = new PeriodicalExecuter(this.scrollUp.bind(this), .05);
}

Fly.ListScroller.prototype.scrollUp = function()
{
	if (parseInt(this.content.style.top) < 0)
	{
		this.content.style.top = parseInt(this.content.style.top) + this.scrollSpeed + "px";
	}
	else
	{
		this.stopScrolling();
	}
}

Fly.ListScroller.prototype.stopScrolling = function()
{
	if (this.motion) this.motion.stop();
}

