// Television Javascript, Main Page Include

var frameCount = 2;            
var interval = 4000;
var transitionTime = 1000;
var visible = 100;
var invisible = 0;
var state = 0;

animateTelevision();

function animateTelevision() {
    /* Television */  
    
    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;
    //if (opacity > 0) {
    //    object.background = "url(Television/" + id + ".jpg) no-repeat center center"
        //alert(object.background);
    //}
    object.opacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}