window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false, num_imgs = 9;
var img_names = new Array("/images/industries/thumb_aerospace.jpg", 
                          "/images/industries/thumb_automotive.jpg", 
	                      "/images/industries/thumb_contracting.jpg", 
	                      "/images/industries/thumb_defense.jpg", 
	                      "/images/industries/thumb_foundry.jpg", 
	                      "/images/industries/thumb_manufacturing.jpg", 
	                      "/images/industries/thumb_marine.jpg", 
	                      "/images/industries/thumb_medical.jpg", 
	                      "/images/industries/thumb_windenergy.jpg")


img_names.sort(function() {return 0.5 - Math.random()});

function so_init()
{
	if(!d.getElementById || !d.createElement)return;


	if(! d.getElementById('rotator') )	return;
	imgs = d.getElementById('rotator').getElementsByTagName('img');
	imgs[1].src = img_names[1];
	for(i=1;i<imgs.length;i++) 	
	{
		imgs[i].xOpacity = 0;
		imgs[i].src = img_names[i];
	}
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;
	
	
	    setTimeout(so_xfade,3000);
	
}

function so_xfade()
{
	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;
		if(imgs[(current+1) % 10].src.indexOf('.jpg') == -1)
		{
			// IE doesn't like this line for some reason ><
			// imgs[(current+1) % 10] = new Image(348, 260);

			imgs[(current+1) % 10].src = img_names[(current+1) % 10];
		}
		setTimeout(so_xfade,3000);
	}
	else
	{
		setTimeout(so_xfade,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) + ')';
	}
	
}