function Frame(configuration){

    var frame = function(configuration){

        // Properties
            var div = document.createElement("div");
                div.content = [];
            var container;
            var tlBorder;
            var tmBorder;
            var trBorder;
            var blBorder;
            var bmBorder;
            var brBorder;
            var mlBorder;
            var mmBorder;
            var mrBorder;
            var titleBar;
            var titleIcon;
            var titlePane;
            var contentPane;
            var titleListeners = [];
            var contentListeners = [];
        //

        function createDiv(className){
            var div = document.createElement("div");
            div.className = className;
            return div;
        }

        function createContainer(){
            container = createDiv("frameContainer");

            tlBorder = container.appendChild(createDiv("frameTL"));
            tmBorder = container.appendChild(createDiv("frameTM"));
            trBorder = container.appendChild(createDiv("frameTR"));
            mlBorder = container.appendChild(createDiv("frameML"));
            mmBorder = container.appendChild(createDiv("frameMM"));
            mrBorder = container.appendChild(createDiv("frameMR"));
            blBorder = container.appendChild(createDiv("frameBL"));
            bmBorder = container.appendChild(createDiv("frameBM"));
            brBorder = container.appendChild(createDiv("frameBR"));

            if(div.resizeable !== false && div.resizeable !== "false"){
                //var func = function(dir){ div.direction = dir; div.resize(); };
                System.publish(tlBorder).addSubscriber("onmousedown", function(){ div.direction = "nw"; div.resize(); });
                System.publish(tmBorder).addSubscriber("onmousedown", function(){ div.direction = "n"; div.resize(); });
                System.publish(trBorder).addSubscriber("onmousedown", function(){ div.direction = "ne"; div.resize(); });
                System.publish(mlBorder).addSubscriber("onmousedown", function(){ div.direction = "w"; div.resize(); });
                System.publish(mrBorder).addSubscriber("onmousedown", function(){ div.direction = "e"; div.resize(); });
                System.publish(blBorder).addSubscriber("onmousedown", function(){ div.direction = "sw"; div.resize(); });
                System.publish(bmBorder).addSubscriber("onmousedown", function(){ div.direction = "s"; div.resize(); });
                System.publish(brBorder).addSubscriber("onmousedown", function(){ div.direction = "se"; div.resize(); });
            }

            div.appendChild(container);
        }

        function createTitlebar(){
            var title = document.createElement("div");
                title.className = "frameTitlebar";
            div.appendChild(title);
            titleBar = title;
        }

        function createTitleIcon(){
            var tIcon = document.createElement("div");
                tIcon.className = "frameIcon";
            titleBar.appendChild(tIcon);
            titleIcon = tIcon;
        }

        function createTitlePane(){
            titlePane = document.createElement("div");
                titlePane.className = "frameTitle";
                titlePane.style.textAlign = div.titleAlign;
            System.publish(titlePane);
            titleBar.appendChild(titlePane);

            if(div.moveable !== false && div.moveable !== "false"){
                titlePane.addSubscriber("onmousedown", div.move);
                titlePane.style.cursor = "move";
            }

        }

        function createControls(){
            if (div.closeable !== false && div.closeable !== "false"){
                var close = document.createElement("div");
                    close.className = "frameClose";
                System.publish(close).addSubscriber("onclick", div.close);
                titleBar.appendChild(close);
            }
            if (div.maximizeable !== false && div.maximizeable !== "false"){
                var maxButton = document.createElement("div");
                    maxButton.className = "frameMaximize";
                System.publish(maxButton).addSubscriber("onclick", div.maximize);
                titleBar.appendChild(maxButton);
            }
            if (div.minimizeable !== false && div.minimizeable !== "false"){
                div.addSubscriber("minimize", div.minimize);
                var minButton = document.createElement("div");
                    minButton.className = "frameMinimize";
                System.publish(minButton).addSubscriber("onclick", div.minimize);
                titleBar.appendChild(minButton);
            }
        }

        function createContentPane(){
            contentPane = document.createElement("div");
                contentPane.className = "frameContent";
                contentPane.style.textAlign = div.contentAlign;
            div.appendChild(contentPane);
        }

        function parseConfig(config){
            var value;
            for(value in config){
                if(value !== "content"){
                    div[value] = config[value];
                }
            }
        }

        function construct(config){
            System.publish(div);
            div = Moveable(Resizeable(Minimizeable(Maximizeable(Closeable(div)))));
            
            parseConfig(config);
            div.addSubscriber("onmousedown", function(obj){ obj.parentNode.sendToFront(obj); });

            createContainer();
            createTitlebar();
            createTitleIcon();
            createTitlePane();
            createControls();
            createContentPane();

            if(div.isMaximizeable() && div.maximized === true){
                div.maximize();
            }

            System.windowmanager.appendStyleSheet("/Themes/"+div.theme+"/style/frame.css");
        }

        div.addOnTitlechange = function(action){ titleListeners.push(action); };
        div.addOnContentchange = function(action){ contentListeners.push(action); };
        div.validate = function(){
            var screenDimensions = System.display.getScreenDimensions();
            // Wrapper Div
                div.style.width = div.width + "px";
                div.style.height = div.height + "px";
                div.style.position = div.position;
                if (div.left !== "auto" || div.right !== "auto" || div.top !== "auto" || div.top !== "auto"){
                    div.style.left = (div.left === "auto") ? "auto" : div.left + "px";
                    //div.style.right = (div.right === "auto") ? "auto" : div.right + "px";
                    div.style.top = (div.top === "auto") ? "auto" : div.top + "px";
                    //div.style.bottom = (div.bottom === "auto") ? "auto" : div.bottom + "px";
                }else if(div.position === "absolute"){
                    div.style.left = ((div.parentNode.offsetWidth / 2) - div.width/2) + "px";
                    div.style.top = ((div.parentNode.offsetHeight / 2) - div.height/2) + "px";
                }
            //
            // Container Div
                container.style.left = "0px";
                container.style.top = "0px";
                container.style.width = div.width + "px";
                container.style.height = div.height + "px";
            //
            // Border Divs
                tmBorder.style.width = (div.width-30 < 0) ? 0+"px" : (div.width-30)+"px";
                mlBorder.style.height = (div.height-120 < 0) ? 0+"px" : (div.height-120)+"px";
                mmBorder.style.width = (div.width-30 < 0) ? 0+"px" : (div.width-30)+"px";
                mmBorder.style.height = (div.height-120 < 0) ? 0+"px" : (div.height-120)+"px";
                mrBorder.style.height = (div.height-120 < 0) ? 0+"px" : (div.height-120)+"px";
                bmBorder.style.width = (div.width-30 < 0) ? 0+"px" : (div.width-30)+"px";
            //
            // Title And Content
                titleBar.style.width = (div.width - 14) + "px";
                titlePane.style.width = (div.width-104 < 0) ? 0+"px" : (div.width-104)+"px";
                contentPane.style.width = (div.width - 30) + "px";
                contentPane.style.height = (div.height - 54) + "px";
                div.setTitle(div.icon,div.title);
                if(typeof div.content === "object"){
                    div.setContent(div.content);
                }
            //
        };
        div.setTitle = function(iconUrl,text){
            div.title = text;
            if(iconUrl !== null){
                div.icon = iconUrl;
                titleIcon.style.backgroundImage = "url("+iconUrl+")";
            }
            for(var x = 0; x < titlePane.childNodes.length; x++){
                titlePane.removeChild(titlePane.childNodes[x]);
            }
            titlePane.appendChild(document.createTextNode(text));
            System.windowmanager.noTextOverflow(titlePane);
            for(var i = 0; i < titleListeners.length; i++){
                titleListeners[i]();
            }
        };
        div.addContent = function(domObject){
            try{
                if(typeof domObject === "object" && domObject.nodeName !== undefined){
                    div.content.push(domObject);
                    contentPane.appendChild(domObject);
                    for(var i = 0; i < contentListeners.length; i++){
                        contentListeners[i]();
                    }
                }else{
                    throw "Lassie";
                }
            }catch(e){}
        };
        div.setContent = function(domObject){
            try{
                if(typeof domObject === "object" && domObject.nodeName !== undefined){
                    for(var x = contentPane.childNodes.length; x > 0; x--){
                        contentPane.removeChild(contentPane.childNodes[x-1]);
                    }
                    div.content.empty();
                    this.addContent(domObject);
                    for(var i = 0; i < contentListeners.length; i++){
                        contentListeners[x]();
                    }
                }else{
                    throw "Lassie";
                }
            }catch(e){}
        };

        construct(configuration);

        return Container(div);

    };

    System.frame = frame;

}
