var opacitymin = 0;
var opacityiconlow = 30;
var opacityiconhigh = 50;
var opacitymax = 100;
var speed = 20;
var displayonrate = 20;
var displayoffrate = 10;


// -----------

var runningfades = 0;
var fadingArray = new Array;





function setOpacity(what, value) { 
if (what) {
// IE/Win
  what.style.filter = 'alpha(opacity:' + value + ')';
  
  // Safari<1.2, Konqueror
  what.style.KHTMLOpacity = value/100;
  
  // Older Mozilla and Firefox
  what.style.mozOpacity = (value/100 == 1) ? 0.98 : value/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  what.style.opacity = (value/100 == 1) ? 0.98 : value/100;
}
}






function initFader(fader, start, end, rate, remove) {

	var temp = new Object();
  temp.fader = fader;
  temp.opacity = start;
  temp.rate = ((start < end) ? 1 : -1) * Math.abs(rate);
  temp.end = end;
  temp.remove = remove;

  var temparray = new Array;
  for (i in fadingArray)
    if (fadingArray[i].fader == fader)
      temp.opacity = fadingArray[i].opacity;
    else
      temparray.push(fadingArray[i]);

  fadingArray = temparray;

  if (temp.rate != 0)
    fadingArray.push(temp);

  if (runningfades == 0) {
    setTimeout('recurseFades()', speed);
    runningfades = 1;
  }
}







function recurseFades() {
  var temparray = new Array;
  while (fadingArray.length > 0) {
    temp = fadingArray.pop();

    temp.opacity = temp.opacity + temp.rate;

    temp.opacity = Math.max(Math.min(opacitymax, temp.opacity), opacitymin);

    if (temp.rate > 0)
      temp.opacity = Math.min(temp.opacity, temp.end);
    else
      temp.opacity = Math.max(temp.opacity, temp.end);

    setOpacity(temp.fader, temp.opacity);

    if ((temp.opacity < temp.end && temp.rate > 0) || (temp.rate < 0 && temp.opacity > temp.end)) {
      temparray.push(temp);
    } else {
      if (temp.remove) {
        temp.fader.style.display = 'none';
        temp.fader.src = '';
      }
    }
  }
  fadingArray = temparray;
  if (fadingArray.length == 0) {
    runningfades = 0;

} else {
    setTimeout('recurseFades()', speed);
  }
}




function initFadeIn(fader) {
  fader.style.display = "block";
  initFader(fader, opacitymin, opacitymax, displayonrate, false);
  return false;
}




function initFadeOut(fader) {
  initFader(fader, opacitymax, opacitymin, displayoffrate, true);
  return false;
}


