
/*
 * Javascript
 * FadeFunctions
 * v.001
 * (c)2008 Christoph Wollgarten, cre8ives.de
 *
 */

function set_opacity(id, val)
{
  var el=document.getElementById(id);
  if(el.style.visibility!='visible') el.style.visibility='visible';
  el.style.filter="Alpha(opacity="+val+")"; /* IE */
  el.style.MozOpacity=(val/100); /* Gecko */
  el.style.opacity=(val/100); /* Opera */
  el.style.KhtmlOpacity=(val/100); /* OS X */
  
}
	
function fade_from_to(id,from,to,duration,pretimer)
{
   if(pretimer>0) 
   { 
     setTimeout("fade_from_to('"+id+"',"+from+","+to+","+duration+")",pretimer); 
   }
   else
   {
     var el=document.getElementById(id);
     var fadetimeunits=80;
     var fadedist=to-from;
     var fadesteps=Math.ceil(duration/fadetimeunits);
     var fadediff=Math.round(fadedist/fadesteps);
   
   
     if(fadedist==0 || duration <= 0)
     {
	   set_opacity(id,to);
	   if(to==0) el.style.visibility='hidden';
     }
     else
     {
	   from=from+fadediff;
	   if(from<0) from=0; else if(from>100) from=100;
   	   set_opacity(id,from);
	   duration=duration-fadetimeunits;
	   setTimeout("fade_from_to('"+id+"',"+from+","+to+","+duration+")",fadetimeunits);
     }
   }
   
}



