function Desktop() {

    this.init();

    this.cfg = {
        hasSizeBtn: false,
        hasCloseBtn: false,
        hasRefreshBtn: false,
        hasSettingsBtn: false,
        hasDrag: false,
        hasOnCloseConfirm: false,
        isSystem: true,
        title: "Jaws desktop",
        module: "desktop"
    }

    this.panelsCount = 3;
    this.defaultProfile["panels"] = [];

    this.domModel = [
        { tag: "table", className: "sys_table", width: "100%", id: "tray",
          childs: [
            { tag: "tr",
              childs: [
                { tag: "td"/*, width: "100px"*/, style: {paddingLeft: "8px", verticalAlign: "top"},
                  childs: [createButtonDom("Add stuff", "switchMenu()", "widgets/menu/ico.gif")] },
/*                { tag: "td", align: "center",
                  childs: [
                    { tag: "div", id: "main_title", style: {paddingTop: "10px"} }
                  ]
                },
*/
                { tag: "td", width: "270px", style: {verticalAlign: "top", textAlign: "right"},
                  childs: [
                    createButtonDom("Show All", "showAll()"), 
                    { tag: "span", innerHTML: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
                    createButtonDom("Hide All", "hideAll()"),
                    { tag: "span", innerHTML: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
                    createButtonDom("Page settings", "showPage(\"settings\")", theme.icons.settings), 
                    { tag: "span", innerHTML: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
                    { tag: "span", id: "authButton" },
                  ] 
                }
              ]
            }
          ]
        },

        { tag: "table", className: "sys_table", width: "100%", id: "tray",
          childs: [
            { tag: "tr",
              childs: [
                { tag: "td", align: "center",
                  childs: [
                    { tag: "div", id: "main_title", style: {paddingTop: "10px"} }
                  ]
                },
		]}]},


        { tag: "table", className: "sys_table", width: "100%", 
          childs: [
            { tag: "tr",
              childs: [
                { tag: "td", id: "pager", width: "100%", className: "desktop_column", align: "center", style: {padding: "0px"}}
              ]
            }
          ]
        },
	{ tag: "div", style: {display: "block", width: "100%", textAlign: "center"}, childs: [
        { tag: "div",  className: "footer",
	  innerHTML :'lOOnstart BETA&nbsp;|',//&nbsp;<a href="#">About</a>&nbsp;|&nbsp;<a href="#">Feedback</a>&nbsp;|&nbsp;<a href="#">Privacy Policy</a>&nbsp;|&nbsp;<a href="#">Terms of Sevice</a>&nbsp;|&nbsp;<a href="#">Blog</a>'}
	  childs: [
	    createButtonDom("About", "showInfo('about')"),
	    { tag: "div", style: {display: "inline"}, innerHTML: "&nbsp;|&nbsp;"},
	    createButtonDom("Feedback", "showInfo('feedback')"),
	    { tag: "div", style: {display: "inline"}, innerHTML: "&nbsp;|&nbsp;"},
	    createButtonDom("Privacy Policy", "showInfo('pp')"),
	    { tag: "div", style: {display: "inline"}, innerHTML: "&nbsp;|&nbsp;"},
	    createButtonDom("Terms Of Service", "showInfo('tos')")	    
	  ]}
	]}
    ]

 
    this.domModelPanels = [
        { tag: "table", width: "100%", 
          style: {margin: "0px", padding: "0px"},
          childs: {
            tag: "tr", 
            childs: [
              {tag: "td", id: "panel0", width: "33%", className: "desktop_column", style: {paddingBottom: "50px"}},
              {tag: "td", id: "panel1", width: "33%", className: "desktop_column", style: {paddingBottom: "50px"}},
              {tag: "td", id: "panel2", width: "33%", className: "desktop_column", style: {paddingBottom: "50px"}}
            ]
          }
        },
        { tag: "div", id: "area", className: "area", name: "area", display: false},
		
        { tag: "div",  id: "footer", style: {diplay: "block" },
	  inngerHTML :'lOOnstart BETA&nbsp;|&nbsp;<a href="#">About</a>&nbsp;|&nbsp;<a href="#">Feedback</a>&nbsp;|&nbsp;<a href="#">Privacy Policy</a>&nbsp;|&nbsp;<a href="#">Terms of Sevice</a>&nbsp;|&nbsp;<a href="#">Blog</a>'
	}

    ]

    this.getSignature = function() {
        return SYSWIDGET_WKEY+1;
    }


    ////////////////////////////
    // Main menu


    this.isMenuShow = false;

    this.switchMenu = function() {
        if(this.isMenuShow) {
            menu.hide();
        } else {
            menu.show();
        } 
    }



    ////////////////////////////
    // Pager
    this.pages = new Array();
    this.visiblePages = new Array();
    this.activePageName = null;
    this.previosPageName = null;

    this.getPageId = function(name) {
        return "page"+name;
    }

    this.addPage = function(name, title) {
        this.buildDomModel(this.elements.pager,
                           {tag: "div", id: this.getPageId(name), display: false, style: {width: "100%", height: "100%"}});
	this.pages.push(this.getPageId(name));
        return this.elements[this.getPageId(name)];
    }


    this.showPage = function(name) {
        if(this.activePage == name) return;
        if(this.activePage) {
	    l=this.visiblePages.length;
	    for(i=0;i<l;i++) {
	    	tmp = this.visiblePages.shift();
		if(tmp!=name) this.visiblePages.push(tmp);
		hideEl(this.elements[this.getPageId(tmp)]);
	    }
       }                                    
        showEl(this.elements[this.getPageId(name)]);
	this.visiblePages.push(name);
        this.activePage = name;
    }

    this.closeCurrentPage = function() {
        if(this.activePage) {
            hideEl(this.elements[this.getPageId(this.activePage)]);
	    this.visiblePages.pop();
        }                                               
        if(this.visiblePages.length) {
	    this.activePage=this.visiblePages[this.visiblePages.length-1];
            showEl(this.elements[this.getPageId(this.activePage)]);
        }
   }



    ///////////////////////////
    // System
    this.buildWindow = function(parent) {
        this.buildDomModel(parent, this.domModel);
    }


    this.buildInterface = function() {
        var panels = this.addPage('panels', "Panels");
        this.buildDomModel(panels, this.domModelPanels);
        this.showPage('panels');
    }


    //////////////////////////////
    // Panels
    this.getPanel = function(n) {
        return this.elements["panel"+n];
    }


    this.getTinyPanel = function() {
        var p = 0;
        var minh = 100000;
        for(i=this.panelsCount-1; i>=0; i--) {
            var h = 0;
            panel = this.getPanel(i);
            for(j=0; j<panel.childNodes.length; j++) {
                h += panel.childNodes[j].offsetHeight;
            }

            if(h <= minh) {
                minh = h;
                p = i;
            }
        }
        return this.getPanel(p);
    }


    ////////////////////////////////
    // Drag and drop
    this.getBelongPanel = function(pos) {
        for(i=0; i<this.panelsCount; i++) {
            if(isPosInObj(pos, this.getPanel(i))) {
                return this.getPanel(i);
            }
        }
        return null;
    }


    this.getWindowAtPos = function(panel, pos) {
        for(i=0; i<panel.childNodes.length; i++) {
            if(isPosInObj(pos, panel.childNodes[i])) {
                return panel.childNodes[i];
            }
        }
        return null;
    }


    this.startArea = function(el) {
        with(this.elements) {
            area.style.position = 'static';
            el.parentNode.insertBefore(area, el);
            area.style.height = el.offsetHeight + "px";
            area.style.display = 'block';
        }
    }


    this.stopArea = function() {
        with(this.elements) {
            area.style.height = 0;
            area.style.display = 'none';
            area.parentNode.removeChild(area);
        }
    }


    this.processArea = function(pos) {
        p = this.getBelongPanel(pos);
        if(p) { 
            if(p.hasChildNodes()) {
                w = this.getWindowAtPos(p, pos);
                if(w) {
                    if(w.name != 'area') {
                        this.elements.area.parentNode.removeChild(this.elements.area);
                        w = this.getWindowAtPos(p, pos);
                        p.insertBefore(this.elements.area, w);
                    }
                } else {
                    this.elements.area.parentNode.removeChild(this.elements.area);
                    p.appendChild(this.elements.area);
                }
            } else {
                this.elements.area.parentNode.removeChild(this.elements.area);
                p.appendChild(this.elements.area);
            }
        }
    }


    this.putWindow = function(pos) {
        panel = this.getBelongPanel(mpos);        

        if(panel) {
            drag.el.parentNode.removeChild(drag.el); 
            panel.insertBefore(drag.el, this.elements.area);
        }
    }



    this.showAll = function() {
        for(i in kernel.widgets) {
            if(kernel.widgets[i] && 
               !kernel.widgets[i].cfg.isSystem && 
               kernel.widgets[i].cfg.hasSizeBtn) {
                kernel.widgets[i].show();
            }
        }
    }


    this.hideAll = function() {
        for(i in kernel.widgets) {
            if(kernel.widgets[i] && 
               !kernel.widgets[i].cfg.isSystem && 
               kernel.widgets[i].cfg.hasSizeBtn) {
                kernel.widgets[i].hide();
            }
        }
    }




    this.wakeUp = function() {
        for(i in this.profile.windows) {
            kernel.runWidget(this.profile.windows[i].module, 
                             this.getPanel(this.profile.windows[i].panel),
                             this.profile.windows[i].id);
        }
    }



    this.savePanels = function() {
        this.profile.windows = [];
        var n = 0;
        for(var p=0; p<this.panelsCount; p++) {
            for(i=0; i<this.getPanel(p).childNodes.length; i++) {
                var wid = this.getPanel(p).childNodes[i].wid;
                if(wid) {
                    this.profile.windows.push({module: kernel.getWidget(wid).cfg.module, id:wid, panel: p});
                }
            }
        }
        this.save();
    }

    
    this.showInfo = function(page) {
	if(infoPage.show(page))
	    desktop.showPage("info");
    }
}

Desktop.prototype = new Widget();
