// flip through pics in news items for R&A / Open Golf
// Niall King wrote this on 27th March 2008

anchor = false;
autotimeout = false;
xfadetimeout = false;
current=0;
fadeinterval = 3000;

fadepics=function() {
	if (so_imgs.length > 1) {
		so_xfade();
		autotimeout = setTimeout(fadepics,fadeinterval);
	}
}

prepimgs=function() {
	so_imgs = [];
	clearTimeout(autotimeout);
	var thediv = $('imagezoom1');
	if (thediv){
		so_imgs = thediv.getElementsByTagName('IMG');
		for(i=1;i<so_imgs.length;i++) // go through all images except the first and make them invisible
		{
			if (so_imgs.className!='cta')so_imgs[i].xOpacity = 0;
		}
		so_imgs[0].style.opacity = 1; // then make the first one visible
		so_imgs[0].style.filter = "alpha(opacity=100)";
		so_imgs[0].style.display = "block";
		so_imgs[0].xOpacity = 1;
		current=0;
		if (so_imgs.length>1) {
			autotimeout = setTimeout(fadepics,fadeinterval);
		} else {
			clearTimeout(autotimeout);
			so_imgs=null;
		}
		
	}
}

function setOpacity(obj) {
	if(obj.xOpacity>.99) {
		obj.xOpacity = 1;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}
	
function so_xfade() {
	if (so_imgs) {
		nIndex = current+1;
		if (nIndex==so_imgs.length-1) { nIndex=0 ;}
		cOpacity = so_imgs[current].xOpacity;
		nOpacity = so_imgs[nIndex].xOpacity;
		cOpacity-=.05; 
		nOpacity+=.05;
		so_imgs[nIndex].style.display = "block";
		so_imgs[current].xOpacity = cOpacity;
		so_imgs[nIndex].xOpacity = nOpacity;
		setOpacity(so_imgs[current]); 
		setOpacity(so_imgs[nIndex]);
		if(cOpacity<=0) {
			so_imgs[current].style.display = "none";
			current = nIndex;
			clearTimeout(xfadetimeout);
		} else {
				xfadetimeout = setTimeout("so_xfade()",50);
		}
	}
}
addDOMLoadEvent(prepimgs);


