
function Yonca_Scrolling()
{
	this.scroll_height = 110;
	this.scroll_delay = 5000;
	this.scroll_method = YAHOO.util.Easing.elasticOut;
	this.controlkey = null;
	this.activekey = 0;
	this.scrollinit = false;
	this.itemnumber = 0;
	this.topmode = false;
	this.scrolly = 0;
	this.auto_mode = false;
	this.control_timer = null;
	this.controlobj = null;
	this.button_register = false;
}

Yonca_Scrolling.prototype.init = function(controlid)
{
	var controlobj = Dom.get(controlid + '_scrollable');
	if (!controlobj)
	{
		return false;
	}

	this.controlkey = controlid;
	var items = Dom.getElementsBy(__true_function, 'li', controlobj);
	this.itemnumber = items.length;
	if (this.itemnumber < 2)
	{
		return false;
	}
	
	this.controlobj = controlobj;
	if (this.auto_mode)
	{
		var _this = this;
		this.control_timer = setTimeout(function(){ _this.next(true); }, this.scroll_delay);
	}
	
	if (this.button_register)
	{
		Event.on(this.controlkey + '_prevbtn', 'click', this.prev_click, this, true);
		Event.on(this.controlkey + '_nextbtn', 'click', this.next_click, this, true);
	}
};

Yonca_Scrolling.prototype.prev_click = function(e)
{
	this.prev();
};

Yonca_Scrolling.prototype.next_click = function()
{
	this.next(false);
};

Yonca_Scrolling.prototype.prev = function()
{
	var next_scroll = this.activekey - 1;
	if (next_scroll < 0)
	{
		next_scroll = this.itemnumber - 1;
	}
	
	this.goscroll(next_scroll);
}

Yonca_Scrolling.prototype.next = function(auto_mode)
{
	if (this.itemnumber < 2)
	{
		return false;
	}
	
	auto_mode = auto_mode || false;
	var next_scroll = this.activekey + 1;
	if (next_scroll > this.itemnumber - 1)
	{
		next_scroll = 0;
	}
	
	this.goscroll(next_scroll);
	if (auto_mode)
	{
		var _this = this;
		clearTimeout(this.control_timer);
		this.control_timer = setTimeout(function(){ _this.next(true); }, this.scroll_delay);
	}
	else
	{
		clearTimeout(this.control_timer);
	}
};

Yonca_Scrolling.prototype.goscroll = function(i)
{
	var navobj = this.controlobj;
	if (!Lang.isUndefined(navobj.inProgress) && navobj.inProgress > 0)
	{
		return false;
	}
	
	i = Math.max(0, i);
	i = Math.min(i, this.itemnumber - 1);
	if (this.activekey == i)
	{
		return true;
	}
	
	this.activekey = i;
	
	var _this = this;
	if (Lang.isUndefined(navobj.inProgress))
	{
		navobj.inProgress = 0;
	}
	
	navobj.inProgress++;
	var scroll_moving = new YAHOO.util.Scroll(navobj, { scroll: { to: [0, (_this.scroll_height * i)] } }, 1, this.scroll_method);
	scroll_moving.onComplete.subscribe(function()
	{
		this.getEl().inProgress--;
	});
	scroll_moving.animate();
};