
// JS functionality to fade images into each other 

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 200);
    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 obj = document.getElementById(id).style;
        opacity = (opacity == 100)?99.999:opacity;
        // IE/Win
        obj.filter = "alpha(opacity:"+opacity+")";
        // Safari<1.2, Konqueror
        obj.KHTMLOpacity = opacity/100;
        // Older Mozilla and Firefox
        obj.MozOpacity = opacity/100;
        // Safari 1.2, newer Firefox and Mozilla, CSS3
        obj.opacity = opacity/100;
    
} 


function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 200);
    var timer = 0;



    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";


    //make image transparent
    changeOpac(0, imageid);    


    //make new image
    width = document.getElementById(imageid).width;
    height = document.getElementById(imageid).height;

    document.getElementById(imageid).width = 0;
    document.getElementById(imageid).height = 0;

    document.getElementById(imageid).src = imagefile;

    document.getElementById(imageid).width = width;
    document.getElementById(imageid).height = height;
	

    //fade in image
    for(i = 1; i <= 130; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * 30));
        timer +=1;
    }
}
