/*
Developed by Kyle Somogyi
*/
function slide_horizontal(_so)
{
	var me = this;

	me.so = _so;
	me.mc = $(me.so.mainElement);
	me.imc = $(me.so.mainElement).children().not('.buttonPrevious, .buttonNext');
	me.ia = [];
	me.ci = 1;
	me.imc_w = 0;

	var tE = me.imc.children(),
		j = tE.length;
	do
	{
		me.ia.push($(tE[j]).outerWidth());
		me.imc_w += $(tE[j]).outerWidth();

		$(tE[j]).attr('shiftrIndex', j);
	} while(j--);

	// Manually set styles
	me.mc.css(
	{
		'overflow': 'hidden',
		'position': 'relative'
	});
	me.imc.css(
	{
		'position': 'absolute',
		'top': '0px',
		'left': '0px',
		'width': me.imc_w+'px'
	});
	me.imc.children().css(
	{
		'float': 'left'
	});
}
slide_horizontal.prototype.next = function()
{
	var me = this,
		imc = me.imc,
		ix=0,
		fi=0;
	while(ix<me.so.jumpAmount)
	{
		fi+=me.ia[me.ci]
		ix++;
		if(me.ci >= imc.children().length)
			me.ci = 1;
		else
			me.ci++;
	}
	imc.stop(true, true).animate(
	{
		'left': '-='+fi+'px'
	}, function()
	{
		var tE = me.imc.children(),
			j = tE.length,
			tA = [];
		do
		{
			if(j < me.so.jumpAmount)
			{
				tA.push(tE[j]);
				$(tE[j]).remove();
			}
		} while(j--);
		$(tA.reverse()).appendTo(imc);

		imc.css('left', '0px');
	});
};
slide_horizontal.prototype.prev = function()
{
	var me = this,
		imc = me.imc,
		ix=0,
		fi=0;
	while(ix<me.so.jumpAmount)
	{
		fi+=me.ia[me.ci]
		ix++;
		if(me.ci <= 1)
			me.ci = imc.children().length;
		else
			me.ci--;
	}

	var tE = me.imc.children(),
		j = tE.length-1,
		tA = [];
	do
	{
		if(j >= (tE.length - me.so.jumpAmount))
		{
			tA.push(tE[j]);
			$(tE[j]).remove();
		}
	} while(j--);
	$(tA.reverse()).prependTo(imc);
	
	imc.css('left', '-'+fi+'px');
	imc.stop(true, true).animate(
	{
		'left': '0px'
	});
};
