﻿function Fader() {
    this.curDiv = null;
    this.working = false;
    
    // TODO only seems to work the first time
    this.speed = "fast";
    
    this.fadeOut = function(divId) {
	    var div = document.getElementById(divId);	
	    this.curDiv = null;
	    $(div).fadeOut(this.speed);
    }

    this.fadeIn = function(divId) {
        var div = document.getElementById(divId);
        
        if(this.working) return false;
        
        if (this.curDiv != null) {
        
            var me = this;
            this.working = true;
                        
            $(this.curDiv).fadeOut(this.speed, function() {       
                $(div).fadeIn(me.speed);
                me.working = false;
            });
            
        } else {
	        $(div).fadeIn(this.speed);
	    }
	    
	   this.curDiv = div;
	   return true;
    }
}