var frameCount = 6;            
var interval = 5000;
var transitionTime = 1500;
var visible = 100;
var invisible = 0;

var state = 0;

function animateBanner() {
	
	var i = 1;
	
	for(i = 1; i < frameCount; i++){
		// Hide all but the first, to start
		changeOpac(0, 'AnimationFrame' + i);
	}
	
	// Call the animation every once in a while
	var timer = setInterval(animateObjects, interval);                          
}

function animateObjects() {
	// Fade one out, fade the next one in
	opacity('AnimationFrame' + state, visible, invisible, transitionTime);
	state = (state + 1) % frameCount;
	opacity('AnimationFrame' + state, invisible, visible, transitionTime);
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

// prevent IE6 from reloading background image every single time the opacity changes
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}