﻿
var bBlend = true;
var blendDelay = 500; //in ms
var blendDuration = 1500; //in ms
var imgID1 = "";
var imgID2 = "";

function fadeIn(id) {
    //document.title = "fadeId(" + id + ")";
    var callfade = "fade('" + id + "',0,100," + blendDuration + ")";
    if(bBlend) window.setTimeout(callfade, blendDelay);   
}

function fade(id, opacStart, opacEnd, duration) 
{   
    var waitstep;
    var delay = 0;   
    var i;
    
    //determine the direction for the blending, if start and end are the same nothing happens
    if (opacStart > opacEnd) {
        waitstep = Math.round(duration / (opacStart - opacEnd)) 
        for (i = opacStart; i >= opacEnd; i--) 
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')", waitstep * i);           
        }
    }
    else if (opacStart < opacEnd) 
    {
        waitstep = Math.round(duration / (opacEnd - opacStart)) + delay;
        for (i = opacStart; i <= opacEnd; i++) 
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')", waitstep * i);                       
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
   // document.title = "op: " + opacity + " | id: " + id;
    var object = document.getElementById(id).style;
    //document.title = document.getElementById(id);
    object.display = "block";
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";    
}