
function Yonca_Headline()
{
	this.auto_mode = false;
	this.controlkey = null;
	this.activekey = 0;
	this.scrollinit = false;
	this.cache = new Array();
	this.itemnumber = 0;
	this.scrolly = 0;
	this.timer = null;
	this.ms = 5000;
}

Yonca_Headline.prototype.init = function(controlid, auto_mode, scrollW, ms)
{
	if (!Dom.get(controlid + '_headlines'))
	{
		return false;
	}

	this.controlkey = controlid;
	this.auto_mode = auto_mode ? true : false;
	this.itemnumber = 0;
	this.scrollx = scrollW || 661;
	this.ms = ms || 5000;
	
	this.construct_navigation();
};

Yonca_Headline.prototype.construct_navigation = function()
{
	var headline = Dom.get(this.controlkey + '_headlines');
	var tags = Dom.getElementsBy(__true_function, 'div', headline);
	this.itemnumber = tags.length;
	for (var i = 0; i < this.itemnumber; i++)
	{
		this.cache[i] = { title: tags[i].title };
		tags[i].title = '';
	}
	
	if (this.itemnumber > 1)
	{
		Event.on(this.controlkey + '_next', 'click', Yonca_Headline.prototype.nextScroll, this, true);
		Event.on(this.controlkey + '_prev', 'click', Yonca_Headline.prototype.prevScroll, this, true);
		Event.on(this.controlkey + '_stop', 'click', Yonca_Headline.prototype.stop, this, true);
		
		if (this.auto_mode)
		{
			var _this = this;
			this.timer = setTimeout(function(){ _this.trigger_auto_mode(); }, this.ms);
		}
	}
	
	// Nav Box güncelleme ve hizalama
	this.set_fields(0);
};

Yonca_Headline.prototype.trigger_auto_mode = function()
{
	this.stop();
	this.nextScroll();
	var _this = this;
	this.timer = setTimeout(function(){ _this.trigger_auto_mode(); }, this.ms);
};

Yonca_Headline.prototype.prevScroll = function()
{
	this.stop();
	var gokey = this.activekey - 1;
	if (gokey < 0)
	{
		gokey = this.itemnumber - 1;
	}
	
	this.goscroll(gokey);
};

Yonca_Headline.prototype.stop = function()
{
	clearTimeout(this.timer);	
};

Yonca_Headline.prototype.nextScroll = function()
{
	this.stop();
	var gokey = this.activekey + 1;
	if (gokey >= this.itemnumber)
	{
		gokey = 0;
	}

	this.goscroll(gokey);
};

Yonca_Headline.prototype.goscroll = function(i)
{
	var navobj = Dom.get(this.controlkey + '_wrapper');
	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 plus = 0;
	if (i > 0)
	{
		// plus = i;
	}
	
	var _this = this;
	if (Lang.isUndefined(navobj.inProgress))
	{
		navobj.inProgress = 0;
	}
	var _this = this;
	navobj.inProgress++;
	var scroll_moving = new YAHOO.util.Scroll(navobj, { scroll: { to: [(_this.scrollx * i) + plus, 0] } }, 0.5, YAHOO.util.Easing.easeBothStrong);
	scroll_moving.onComplete.subscribe(function()
	{
		this.getEl().inProgress--;
	});
	scroll_moving.animate();
	this.set_fields(i);
};

Yonca_Headline.prototype.set_fields = function(i)
{
	for (var k in this.cache[i])
	{
		Dom.get(this.controlkey + '_' + k).innerHTML = this.cache[i][k];
	}

	Dom.get(this.controlkey + '_navigation').innerHTML = '' + (i + 1) + ' / ' + this.itemnumber;
};