window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var imgs_l = new Array(), imgs_c = new Array(), imgs_r = new Array(), current_l=0, current_c=0, current_r=0;

function so_init()
{
	if ($('.photos'))
	{
		imgs_l = $('.photos img');
		for(i=1; i<imgs_l.length; i++)
		{
			imgs_l[i].xOpacity = 0;
		}
		imgs_l[0].style.display = 'block';
		imgs_l[0].xOpacity = .99;

		// Начальный запуск 3000 мс
		setTimeout(so_xfade_l, 3000);
	}
}

function so_xfade_l()
{
	cOpacity = imgs_l[current_l].xOpacity;
	nIndex = imgs_l[current_l+1] ? current_l+1:0;
	nOpacity = imgs_l[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgs_l[nIndex].style.display = 'block';
	imgs_l[current_l].xOpacity = cOpacity;
	imgs_l[nIndex].xOpacity = nOpacity;

	setOpacity_l(imgs_l[current_l]);
	setOpacity_l(imgs_l[nIndex]);

	if(cOpacity<=0)
	{
		imgs_l[current_l].style.display = 'none';
		current_l = nIndex;
		setTimeout(so_xfade_l, 3000);
	}
	else
	{
		setTimeout(so_xfade_l,50);
	}

	function setOpacity_l(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}

function so_xfade_c()
{
	cOpacity = imgs_c[current_c].xOpacity;
	nIndex = imgs_c[current_c+1] ? current_c+1:0;
	nOpacity = imgs_c[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgs_c[nIndex].style.display = 'block';
	imgs_c[current_c].xOpacity = cOpacity;
	imgs_c[nIndex].xOpacity = nOpacity;

	setOpacity_c(imgs_c[current_c]);
	setOpacity_c(imgs_c[nIndex]);

	if(cOpacity<=0)
	{
		imgs_c[current_c].style.display = 'none';
		current_c = nIndex;
		setTimeout(so_xfade_c, 3000);
	}
	else
	{
		setTimeout(so_xfade_c,50);
	}

	function setOpacity_c(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}

function so_xfade_r()
{
	cOpacity = imgs_r[current_r].xOpacity;
	nIndex = imgs_r[current_r+1] ? current_r+1:0;
	nOpacity = imgs_r[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgs_r[nIndex].style.display = 'block';
	imgs_r[current_r].xOpacity = cOpacity;
	imgs_r[nIndex].xOpacity = nOpacity;

	setOpacity_r(imgs_r[current_r]);
	setOpacity_r(imgs_r[nIndex]);

	if(cOpacity<=0)
	{
		imgs_r[current_r].style.display = 'none';
		current_r = nIndex;
		setTimeout(so_xfade_r, 3000);
	}
	else
	{
		setTimeout(so_xfade_r,50);
	}

	function setOpacity_r(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}
