var frameCount = 7;            
var interval = 3000;
var transitionTime = 1000;
var visible = 100;
var invisible = 0;

var state = 0;
window.onload = animateTelevision;

function animateTelevision() {
/* Television */

var i = 0;

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 + ")";
}
