
function Yonca_Scrolling()
{
	this.auto_mode = false;
	this.controlkey = null;
	this.activekey = 0;
	this.scrollinit = false;
	this.cache = new Array();
	this.itemnumber = 0;
}

Yonca_Scrolling.prototype.init = function(controlid, cache, auto_mode)
{
	if (!Dom.get(controlid) || !cache || cache.length == 0)
	{
		return false;
	}

	this.controlkey = controlid;
	this.auto_mode = auto_mode ? true : false;
	this.cache = cache;
	this.itemnumber = cache.length;
	
	this.construct_navigation();
	
	Event.on(window, 'resize', Yonca_Scrolling.prototype.reposition_navigation, this, true);
};

Yonca_Scrolling.prototype.reposition_navigation = function()
{
	var _this = this;
	setTimeout(function(){
		// Nav Linkleri
		var scrollnav = Dom.get(_this.controlkey + '_nav'), 
			scrolltab = Dom.get(_this.controlkey + '_wrapper'),
			scrollbox = Dom.get(_this.controlkey + '_box'),
			scrollcontrol = Dom.get(_this.controlkey + '_navcontrol');
		
		// Nav 'ın Gösterilmesi ve Hizalanması
		var stcoords = Dom.getXY(scrolltab);
		var x = stcoords[0] + scrolltab.offsetWidth - scrollnav.offsetWidth + 1, y = stcoords[1] + 250;	
		
		if (UA.ie < 7)
		{
			x += 1;
		}
		
		Dom.setXY(scrollnav, [x, y], false);
		
		y -= scrollbox.offsetHeight + 5;
		x = stcoords[0] + scrolltab.offsetWidth - scrollbox.offsetWidth + 1;
		
		if (UA.ie < 7)
		{
			x += 1;
		}
		
		Dom.setXY(scrollbox, [x, y], false);
		var fcoords = Dom.getXY(Dom.get(_this.controlkey + '_navlink_' + _this.activekey));
		
		if (UA.ie < 7)
		{
			fcoords[0] += 1;
		}
		
		Dom.setXY(scrollcontrol, [fcoords[0], fcoords[1] - 6], false);
	}, 0);
};

Yonca_Scrolling.prototype.construct_navigation = function()
{
	// Nav Linkleri
	var scrollnav = Dom.get(this.controlkey + '_nav'), 
		scrollnavs = Dom.get(this.controlkey + '_nav_links'),
		scrolltab = Dom.get(this.controlkey + '_wrapper'),
		scrollbox = Dom.get(this.controlkey + '_box'),
		scrollcontrol = Dom.get(this.controlkey + '_navcontrol'),
		firstnav = null;
	for (var i = 0; i < this.itemnumber; i++)
	{
		var nav = document.createElement('a');
		nav.href = 'javascript:;';
		nav.innerHTML = (i + 1);
		nav.id = this.controlkey + '_navlink_' + i;
		
		scrollnavs.appendChild(nav);

		Event.on(nav, 'click', Yonca_Scrolling.prototype.navclick, i, this, true);
		
		if (firstnav === null)
		{
			firstnav = nav;
		}
	}
	
	// Nav 'ın Gösterilmesi ve Hizalanması
	var stcoords = Dom.getXY(scrolltab);
	Dom.setStyle(scrollnav, 'display', '');
	
	var x = stcoords[0] + scrolltab.offsetWidth - scrollnav.offsetWidth + 1, y = stcoords[1] + 250;
	if (UA.ie < 7)
	{
			x += 1;
	}
		
	Dom.setXY(scrollnav, [x, y], false);
	
	// Nav Box güncelleme ve hizalama
	this.set_fields(0);
	
	Dom.setStyle(scrollbox, 'display', '');
	
	y -= scrollbox.offsetHeight + 5;
	x = stcoords[0] + scrolltab.offsetWidth - scrollbox.offsetWidth + 1;
	if (UA.ie < 7)
	{
			x += 1;
	}
	
	Dom.setXY(scrollbox, [x, y], false);
	
	// Kontrol Anahtarı
	Dom.setStyle(scrollcontrol, 'display', '');
	
	var fcoords = Dom.getXY(firstnav);
	if (UA.ie < 7)
	{
			fcoords[0] += 1;
	}
	
	Dom.setXY(scrollcontrol, [fcoords[0], fcoords[1] - 6], false);
};

Yonca_Scrolling.prototype.navclick = function(e, scrollid)
{
	Event.preventDefault(e);
	this.goscroll(scrollid);
};

Yonca_Scrolling.prototype.goscroll = function(i)
{
	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 scrollcontrol = Dom.get(this.controlkey + '_navcontrol');
	var x = Dom.getX(this.controlkey + '_navlink_' + i), y = Dom.getY(scrollcontrol );
	var controlkey_moving = new YAHOO.util.Motion(scrollcontrol, { points: { to: [x, y] } }, 0.45, YAHOO.util.Easing.easeBothStrong);
	controlkey_moving.animate();
	
	var scroll_moving = new YAHOO.util.Scroll(this.controlkey + '_wrapper', { scroll: { to: [(881 * i) + plus, 0] } }, 0.5, YAHOO.util.Easing.easeBothStrong);
	var _this = this;
	scroll_moving.onComplete.subscribe(function()
	{
		_this.set_fields(i);
	});
	scroll_moving.animate();
};

Yonca_Scrolling.prototype.set_fields = function(i)
{
	Dom.get(this.controlkey + '_title').innerHTML = this.cache[i]['title'];
	Dom.get(this.controlkey + '_description').innerHTML = this.cache[i]['description'];
};