﻿
function opacity(id, opacStart, opacEnd, millisec) { 

    //speed for each frame 
    var speed = Math.round(millisec / 100); 
   // alert(speed);
    var timer = 0; 
    
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
   // alert('fade out');
        for(i = opacStart; i >= opacEnd; i--) { 
            window.setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
          
        } 
    } else if(opacStart < opacEnd) { 
    //alert('fade in');
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            window.setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
           
        } 
    }
   
   
        
    
   
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 

    var object = document.getElementById(id); 
    //opacity = (opacity == 100)?99.999:opacity;
    // IE/Win
	object.style.filter = "alpha(opacity:"+opacity+", finishopacity=100, style=0)";
    // Safari<1.2, Konqueror
	object.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	object.style.MozOpacity = opacity/101;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	object.style.opacity = opacity/100;
  //  alert(document.getElementById(id).style.filter);
  
  
    }

function currentOpac(id, opacEnd, millisec) { 
    //standard opacity is 100 
    var currentOpac = 100; 
     
    //if the element has an opacity set, get it 
    if(document.getElementById(id).style.opacity < 100) { 
        currentOpac = document.getElementById(id).style.opacity * 100; 
    } 

    //call for the function that changes the opacity 
    opacity(id, currentOpac, opacEnd, millisec) 
} 
