function doRotate() {
	var all = document.getElementById('rotate').childNodes,
		l = all.length, c, cur, nxt,
		o = 0,
		crossfade = function() {
			o += 10;
			if(o < 100) {
				nxt.style.opacity = (o/100);
				nxt.style.filter = 'alpha(opacity=' + o + ')';
				setTimeout(crossfade, 10);
			} else {
				cur.style.zIndex = 1;
				cur.style.opacity = 1;
				cur.style.filter = 'none';
				cur.style.display = 'none';
				cur.className = '';
				
				nxt.style.zIndex = l;
				nxt.style.opacity = 1;
				nxt.style.filter = 'none';
				nxt.style.display = 'block';
				nxt.className = 'active';
			}
		};
	for(c = 0; c < l; c++) {
		if(all[c].className == 'active') {
			cur = all[c];
			if(c+1 < l) {
				nxt = all[c+1];
			} else {
				nxt = all[0];
			}
		}
	}
	if(nxt && cur && nxt != cur) {
		cur.style.zIndex = l;
		cur.style.opacity = 1;
		cur.style.filter = 'none';
		nxt.style.opacity = 0;
		nxt.style.filter = 'alpha(opacity=0)';
		nxt.style.zIndex = l+1;
		nxt.style.display = 'block';

		nxt.style.width = '100%';
		crossfade();
	}
}

function initRotate() {
	var all = document.getElementById('rotate').childNodes,
		l = all.length, c;
	for(c = l-1; c > -1; c--) {
		if(all[c].nodeType != 1) {
			all[c].parentNode.removeChild(all[c]);
		} else {
			all[c].style.display = 'none';
			all[c].style.zIndex = 1;
		}
	}
	all = document.getElementById('rotate').childNodes;
	l = all.length;
	all[0].style.display = 'block';
	all[0].style.zIndex = l;
	if(l > 1) {
		all[0].className = 'active';
		if(window.addEventListener) {
			window.addEventListener('load', function(){setInterval(doRotate, 5000);}, null);
		} else {
			window.attachEvent('onload', function(){setInterval(doRotate, 5000);});
		}
	}
}

if(document.getElementById('rotate')) {
	initRotate();
}
