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

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

	this.controlkey = controlid;
	this.auto_mode = auto_mode ? true : false;
	this.cache = cache;
	this.itemnumber = cache.length;
	this.topmode = top || this.topmode;
	this.scrolly = scrollH || 260;
	
	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'), firstnav = null;
		
		// Nav 'ın Gösterilmesi ve Hizalanması
		var stcoords = Dom.getXY(scrolltab);
		Dom.setStyle(scrollnav, 'display', '');
		
		var x = stcoords[0] + scrolltab.offsetWidth - scrollnav.offsetWidth - 5;
		if (_this.topmode)
		{
			y = stcoords[1];
		}
		else
		{
			y = stcoords[1] + scrolltab.offsetHeight - scrollnav.offsetHeight;	
		}
		Dom.setXY(scrollnav, [x, y], false);
	}, 0);
};

Yonca_Scrolling.prototype.construct_navigation = function()
{
	// Nav Linkleri
	var scrollnav = Dom.get(this.controlkey + '_nav'), scrolltab = Dom.get(this.controlkey + '_wrapper'), firstnav = null;
	var tags = Dom.getElementsBy(__true_function, 'div', Dom.get(this.controlkey + '_scrollcontrol'));

	if (!scrollnav)
	{
		scrollnav = document.createElement('div');
		scrollnav.id = this.controlkey + '_nav';
		scrollnav.className = 'scrollnav';
		document.body.insertBefore(scrollnav, document.body.firstChild);
	}	
		
	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;
		
		if (i == 0)
		{
			nav.className = 'ahover';
		}
		
		scrollnav.appendChild(nav);

		Event.on(nav, 'click', Yonca_Scrolling.prototype.navclick, i, this, true);
		
		if (firstnav === null)
		{
			firstnav = nav;
		}
		
		if (!Lang.isUndefined(this.cache[i]['jslink']))
		{
			this.setclick(tags[i], this.cache[i]['jslink']);
		}
	}
	
	// Nav 'ın Gösterilmesi ve Hizalanması
	var stcoords = Dom.getXY(scrolltab);
	Dom.setStyle(scrollnav, 'display', '');
	
	var x = stcoords[0] + scrolltab.offsetWidth - scrollnav.offsetWidth - 5;
	if (this.topmode)
	{
		y = stcoords[1];
	}
	else
	{
		y = stcoords[1] + scrolltab.offsetHeight - scrollnav.offsetHeight;	
	}
	
	Dom.setXY(scrollnav, [x, y], false);
	
	// Nav Box güncelleme ve hizalama
	this.set_fields(0);
};

Yonca_Scrolling.prototype.setclick = function(obj, jslink)
{
	Dom.setStyle(obj, 'cursor', 'pointer');
	Event.on(obj, 'click', function(e, redir){ Event.preventDefault(e); window.location = redir; }, jslink);
};

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

Yonca_Scrolling.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;
	}
	
	Dom.removeClass(this.controlkey + '_navlink_' + this.activekey, 'ahover');
	
	this.activekey = i;
	Dom.addClass(this.controlkey + '_navlink_' + this.activekey, 'ahover');

	var plus = 0;
	if (i > 0)
	{
		// plus = 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.scrolly * i) + plus] } }, 0.5, YAHOO.util.Easing.easeBothStrong);
	scroll_moving.onComplete.subscribe(function()
	{
		_this.set_fields(i);
		this.getEl().inProgress--;
	});
	scroll_moving.animate();
};

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