var WindowManager = function()
{
    var curWindowID;
    var lastWindow;
    var mode = "default";

    this.show = function(id,x,y)
    {
        //fade first, queue up the 2nd
        if(x && y) Utility.setBounds(id,x,y);
        this.lastWindow = this.curWindowID;
        this.curWindowID = id;
        if(this.lastWindow != this.curWindowID)
        {
            switch(mode)
        	{
        	    case "fade":
        	       this.lastWindow ? Utility.fadeInOut(this.curWindowID,this.lastWindow) : Utility.fadeIn(this.curWindowID);
        	    break;
                default:
        	       this.lastWindow ? Utility.swap(this.lastWindow,this.curWindowID) : Utility.turnOn(this.curWindowID);
        	    break;
        	}
        }
    }
    this.hide = function()
    {
        switch(mode)
        {
            case "fade":
                if(this.curWindowID) Utility.fadeOut(this.curWindowID);
            break;
            default:
                if(this.curWindowID) Utility.turnOff(this.curWindowID);
            break;
        }
        
        this.curWindowID = null;
    }
    this.swap = function(id1,id2,group,x1,y1,x2,y2)
    {
        if(x1 && y1 && x2 && y2)
        {
            Utility.setBounds(id1,x1,y1);
            Utility.setBounds(id2,x2,y2);
        }
        this.lastWindow = this.curWindowID;
        this.curWindowID = id2;
        if(this.lastWindow != this.curWindowID)
        {
            switch(mode)
            {
                case"fade":
                    Utility.fadeInOut(id2,id1);
                break;
                default:
                    Utility.swap(id1,id2);
                break;
            }
        } 
    }
    this.setDefault = function(id)
    {
        this.curWindowID = id;
    }
    this.setMode = function(arg)
    {
        mode = arg;
    }
}

var Modal = new WindowManager();
Modal.setMode("fade");
