function fades(div)
{
  this.currentLevel = 0;
  this.delay;
  this.div = div;
  this.fadeStep;
  this.optimumFadePerStep = 5;
  this.startingOp;
  this.endingOp;
  this.autoHide = false;
  this.intervalID;
  
  this.changeOpacity = function (op)
  {
    var mozop = op / 100;
    this.div.style.opacity = mozop;
    this.div.style.filter = "alpha(opacity="+op+")"; 
    this.div.style.KHTMLOpacity = mozop;
  }
  
  this.divHide = function ()
  {
    this.div.style.visibility = 'hidden';
    this.div.style.display = 'none';
  }
  
  this.divShow = function ()
  {
    this.div.style.visibility = 'visible';
    this.div.style.display = 'block';
  }
  
  this.divFade = function (fromOp,toOp,timeReq,hide_or_not)
  {
    if(hide_or_not == "hideOn")
      this.autoHide = true;
  
    this.delay = timeReq * (this.optimumFadePerStep/100);
    this.fadeStep = Math.abs(fromOp - toOp) * (this.optimumFadePerStep/100);
  
    this.startingOp = fromOp;
    this.endingOp = toOp;
    this.currentLevel = this.startingOp;
    if(this.startingOp<this.endingOp)
    {
      this.divShow();
      //this.fadeIn();
      this.intervalID = window.setInterval("document.getElementById(\'"+this.div.id+"\').fades.fadeIn()",this.delay);
    }
    else if(this.startingOp>this.endingOp)
    {
      //this.fadeOut();
      this.intervalID = window.setInterval("document.getElementById(\'"+this.div.id+"\').fades.fadeOut()",this.delay);
    }
  }
  
  this.fadeIn = function ()
  {
    this.changeOpacity(this.currentLevel);
    this.currentLevel += this.fadeStep;
  /*
    if(this.currentLevel <= this.endingOp)
    {
      setTimeout("document.getElementById(\'"+this.div.id+"\').fades.fadeIn()", this.delay);
    }
    */
    if(this.currentLevel >= this.endingOp)
    {
      window.clearInterval(this.intervalID);
    }
  }
  
  this.fadeOut = function ()
  {
    this.changeOpacity(this.currentLevel);
    this.currentLevel -= this.fadeStep;
  /*
    if(this.currentLevel >= this.endingOp)
    {
      setTimeout("document.getElementById(\'"+this.div.id+"\').fades.fadeOut()",this.delay);
    }
    */
    if(this.currentLevel <= 0)
    {
      window.clearInterval(this.intervalID);
      if(this.autoHide)
      {
        this.divHide();
        this.autoHide = false;
      }
    }
  }
}