/*
Developed by Kyle Somogyi
*/
function fade(_so)
{
	var me = this;

	me.mc = $(_so.mainElement);
	me.imc = $(_so.mainElement).children().not('button');
	me.ia = [];
	me.ci = 0;
	me.z_index = me.imc.children().length+10;

	me.imc.children().each(function(i, elem)
	{
		me.ia.push($(elem).outerHeight());

		$(elem).attr('shiftrIndex', i).css('z-index', me.z_index);
		me.z_index--;
	});

	// Manually set styles
	me.mc.css(
	{
		'overflow': 'hidden',
		'position': 'relative'
	});
	me.imc.css(
	{
		'position': 'absolute',
		'top': '0px',
		'left': '0px',
		'height': me.imc_h+'px'
	});
	me.imc.children().css(
	{
		'position': 'absolute',
		'top': '0px',
		'left': '0px'
	});
}
fade.prototype.next = function()
{
	var me = this;

	me.imc.children().stop(true, true);
	me.imc.find(':first').stop(true, true).animate(
	{
		'opacity': 0
	}, function()
	{
		me.imc.find(':first').detach().appendTo(me.imc);
		me.imc.children().last().css('opacity', 1);
		me.ci = me.imc.find(':first').attr('shiftrIndex');

		me.reIndex();
	});
};
fade.prototype.prev = function()
{
	var me = this;

	me.imc.children().stop(true, true).last().css('opacity', 0).detach().prependTo(me.imc);
	me.reIndex();
	me.imc.find(':first').stop(true, true).animate(
	{
		'opacity': 1
	}, function()
	{
		me.ci = me.imc.find(':first').attr('shiftrIndex');
	});
};
fade.prototype.reIndex = function()
{
	var me = this;

	me.z_index = me.imc.children().length+10;
	me.imc.children().each(function(i, elem)
	{
		$(elem).css('z-index', me.z_index);
		me.z_index--;
	});
};
