function Container(obj){
    
    var defaultConfig = {
        "theme" : "default",
        "width" : 400,
        "height" : 180,
        "position" : "absolute",
        "left" : 100,
        "top" : 100,
        "right" : "auto",
        "bottom" : "auto",
        "titleAlign" : "left",
        "contentAlign" : "left",
        "center" : false,
        "overlay" : false,
        "closeable" : true,
        "maximizeable" : false,
        "minimizeable" : false,
        "moveable" : true,
        "resizeable" : true,
        "size" : "normal",
        "title" : "",
        "icon" : "",
        "content" : "",
        "allowOffScreen" : false
    };
        
    obj.windows = [];

    obj.sendToFront = function(frame){
        var inst = this.windows.removeInstanceOf(frame);
        if(inst !== null){
            this.windows.push(inst);
            if(this.lastChild != frame){
                this.appendChild(frame);
            }
        }
    };

    obj.sendToBack = function(frame){
        this.windows.unshift(this.windows.removeInstanceOf(frame));
        if(this.firstChild != frame){
            this.insertBefore(frame,this.firstChild);
        }
    };

    obj.removeFrame = function(frame){
        this.windows.removeInstanceOf(frame);
        if(frame !== undefined){
            if(frame.overlay != undefined){
                frame.overlay.parentNode.removeChild(frame.overlay);
            }
            var parent = frame.parentNode;
            if (parent !== undefined){
                parent.removeChild(frame);
            }
        }
        this.sendToFront(this.lastChild);
    };

    obj.getWindowCount = function(){
        return obj.windows.length;
    };

    obj.appendFrame = function(frame){
        if(frame.className == "frame"){
            obj.windows.push(frame);
            try{
                obj.addContent(frame);
            }catch(e){
                obj.appendChild(frame);
            }
            frame.validate();
            frame.scrollIntoView();
            return frame;
        }else{
            throw "Not a frame.";
        }
    };

    obj.createFrame = function(config){
        var options = {};
        if(config === null){
            options = defaultConfig;
        }else{
            if(config['center'] === true){
                var left = this.offsetWidth/2 - config['width'] / 2;
                var top = this.offsetHeight/2 - config['height'] / 2;
                config['left'] = (left < 0) ? 0 : left;
                config['top'] = (top < 0) ? 0 : top;
            }
            for(var name in defaultConfig){
                if(config[name] !== undefined){
                    options[name] = config[name];
                }else{
                    options[name] = defaultConfig[name];
                }
            }
        }
        var frame = System.frame(options);
        frame.className = "frame";
        if(config.maximized === true){
            frame.maximize();
        }
        if(config.overlay === true){
            frame.overlay = obj.createOverlay();
        }
        obj.appendFrame(frame);
        return frame;
    };

    obj.createOverlay = function(){
        var overlay = new Image();
        overlay.src = "/Images/overlay.png";
        overlay.style.width = this.clientWidth;
        overlay.style.height = this.clientHeight;
        overlay.style.position = "absolute";
        overlay.style.left = this.offsetLeft + "px";
        overlay.style.top = this.offsetTop + "px";
        this.appendChild(overlay);
        overlay.scrollIntoView();
        return overlay;
    }

    obj.empty = function(){
        for(var x = obj.childNodes.length; x > 0; x--){
            obj.remove(obj.childNodes[x-1]);
        }
    };

    return obj;

}
