function Fader(name, step) {
  this.objname = name;
  if(step)
    this.step = step;
  else
    this.step = 0.02;
  
  this.obj = null;
  this.interval = null;
  this.timeout = 50;
  this.opacityMin = 0.0;
  this.opacityMax = 0.7;
  this.dir = 1;
  this.currOpacity = 1.0;
  var self;
  
  this.doFade = function() {
    if(self.dir < 0 && self.currOpacity <= self.opacityMin) {
      self.fadeFinished();      
    } else if(self.dir > 0 && self.currOpacity >= self.opacityMax) {
      self.fadeFinished();
    } else {
      self.currOpacity = self.currOpacity + self.step * self.dir;
      if(self.currOpacity < 0) {
        self.currOpacity = 0;
      }
      self.setOpacity();
    }
  }
  
  this.init = function() {
  	if(!this.obj) {
      this.obj = document.getElementById(this.objname);
    }
  }
  
  this.setOpacity = function() {
  	this.init();
  	this.obj.style.opacity = this.currOpacity;
    this.obj.style.filter = 'alpha(opacity=' + this.currOpacity*100 + ')';
  }
  
  this.fade = function(dir) {
    this.dir = dir;
    this.init();
    self = this;
    this.interval = window.setInterval(self.doFade, this.timeout);
  }
  
  this.fadeIn = function() {
    this.fade(1);
  }
  
  this.fadeOut = function() {
    this.fade(-1);
  }
  
  this.fadeFinished = function() {
  	window.clearInterval(self.interval);
    self = undefined;
    this.fadeNotify();
  }
  
  this.fadeNotify = function() {
  	// do nothing here -> overwrite method for get notification when fading is done.
  }
}
