/*
	Image Cross Fade Redux
	Version 1.0
	Last revision: 02.15.2006
	steve@slayeroffice.com

	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/

window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);
var d=document;
function so_init()
{
   start(ids[0], arr_times[0]);
   start(ids[1], arr_times[1]);
   start(ids[2], arr_times[2]);
   start(ids[3], arr_times[3]);
   start(ids[4], arr_times[4]);
   start(ids[5], arr_times[5]);
}

function start(id, times)
 {
  var imgs = new Array(), current=0;
  if(!d.getElementById || !d.createElement)return;
	imgs = d.getElementById(id).getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;	 
	setTimeout('so_xfade(\''+id+'\', '+current+', \''+serializa_array(times)+'\')',times[0]);
 }

function so_xfade(id, current, times)
{
	imgs=d.getElementById(id).getElementsByTagName("img");
	times=times.split('|');
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;

	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		setTimeout('so_xfade(\''+id+'\', '+current+', \''+serializa_array(times)+'\')',times[current]);
	}
	else
	{
		setTimeout('so_xfade(\''+id+'\', '+current+', \''+serializa_array(times)+'\')',50);
	}

	function setOpacity(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 serializa_array(array)
 {
  var cad='';
  for (i=0; i<array.length; i++)
   cad+=(cad=='')?array[i]:'|'+array[i];
  return cad;	 
 }