function Gmail() {
    this.init();


    this.cfg = {
        hasSettingsBtn: true,
        title: "Google mail",
        module: "Gmail"
    }


    this.domSettings = [
        { tag: "div", className: "settings_section", 
          childs: [
            { tag: "span", innerHTML: "Mails count: ", className: "settings_label"},
            { tag: "select", id: "news_count", className: "settings_control",
              options: [
                { value:"3", text: "3"},
                { value:"5", text: "5"},
                { value:"8", text: "8"},
                { value:"10", text: "10"},
                { value:"12", text: "12"},
                { value:"15", text: "15"},
                { value:"9999", text: "All"}
              ]
            }, 
            { tag: "input", type: "button", value: " Set ", events: {onclick: "setNewsCount()"}, className: "settings_control"}
          ]
        },
 
        { tag: "div", className: "settings_section",
          childs: [ 
            { tag: "span", innerHTML: "Account: ", className: "settings_label"},
            { tag: "input", id: "select_email", type: "text", size: "15", className: "settings_control"} 
          ]},

        { tag: "div", className: "settings_section",
          childs: [ 
            { tag: "span", innerHTML: "Password: ", className: "settings_label"},
            { tag: "input", id: "select_password", type: "password", size: "15", className: "settings_control"} 
          ]},

        { tag: "div", className: "settings_section", align: "center",
          childs: [ 
            { tag: "input", type: "button", value: " Save ", events: {onclick: "saveProfile()"}} ]}
    ]

    this.domContent = [
        { tag: "div", className: "menu_panel", id: "messages_area", display: false,
          childs: [
            createTableDom([{content: "<img src=\"widgets/gmail/ico.gif\" align=left>", width: "1%"},
                            {content: { tag: "div", id: "mail_total"}, width: "100%"},
                            {content: { tag: "input", type: "checkbox", events: {onclick: "switchMailsContent()"}, id: "switcher"}, width: "100%"}]),
            { tag: "div", id: "mail_list"}
          ]
        },
        { tag: "div", className: "menu_panel", id: "config_note", 
          childs: [
            createTableDom([{content: "<img src=\"widgets/gmail/ico.gif\" align=left>", width: "1%"},
                            {content: "Account not configured, use the Edit button to set your login and password.", width: "100%"}])
          ]
        },
        { tag: "div", className: "menu_panel", id: "msg_no_new_mails", innerHTML: "No new mails.", display: false}

    ]

    this.defaultProfile["title"] = this.cfg.title;
    this.defaultProfile["email"] = "";
    this.defaultProfile["password"] = "";
    this.defaultProfile["newsCount"] = "8";



    this.onBuildInterface = function() {
        this.buildDomModel(this.elements.settings, this.domSettings);
        this.buildDomModel(this.elements.content, this.domContent);

        this.elements.news_count.value = this.profile.newsCount;
        this.elements.select_email.value = this.profile.email;
        this.elements.select_password.value = this.profile.password;

        if(this.profile["email"] != "" && this.profile["password"] != "") {
            hideEl(this.elements.config_note);
        }
        this.setTitle(this.profile.title);
    }


    this.onOpen = function() {
        kernel.processTimer(this.id, 600*1000);
    }


    this.timerHandler = function() {
        this.refresh();
    }


    this.saveProfile = function() {
        this.profile.email = "" + trim(this.elements.select_email.value).split("@gmail.com")[0];
        this.profile.password = trim(this.elements.select_password.value);
        this.save();
        hideEl(this.elements.messages_area);
        this.refresh();
    }


    this.setNewsCount = function() {
        this.profile.newsCount = this.elements.news_count.value;
        this.save();
        this.renderMessages();
    }



    this.refresh = function() {
        hideEl(this.elements.msg_no_new_mails);
        if(this.profile["email"] != "" && this.profile["password"] != "") {
            this.setTitle("Loading ...");
            hideEl(this.elements.config_note);
            xmlRequest.send("https://mail.google.com/mail/feed/atom/", this, "showMail", {login: this.profile.email, password: this.profile.password});
//            xmlRequest.send("http://jaws/tmp/gmail.php", this, "showMail", false, true);
        } else {
            showEl(this.elements.config_note);
        }
    }

    this.showMail = function(response) {
        if(response.responseXML && response.responseXML.documentElement) {
            this.data = XMLParser.xml2hash(response.responseXML.documentElement, "entry");
            if(this.data) {
                this.renderMessages();
                return true;
            } 
        }
        this.setConfigState();
    }


    this.setConfigState = function() {
        this.setTitle(this.profile.title);
        showEl(this.elements.config_note);
        hideEl(this.elements.messages_area);
    }


    this.switchMailsContent = function() {
        if(this.data.items) {
            var count = Math.min(this.data.items.length, this.profile.newsCount);
            for(var i=0; i<count; i++) {
                if(this.elements.switcher.checked) {
                    showEl(this.elements["mail_content" + i]);
                } else {
                    hideEl(this.elements["mail_content" + i]);
                }
            }
        }
    }


    this.renderMessages = function() {
        this.elements.title.innerHTML = '';
        this.buildDomModel(this.elements.title, 
                           createButtonDom(this.profile.title, "openInbox()"));
        if(this.data && this.data.items.length > 0) {
            hideEl(this.elements.msg_no_new_mails);
            hideEl(this.elements.config_note);
            showEl(this.elements.messages_area);
            this.elements.mail_list.innerHTML = '';

            this.elements.mail_total.innerHTML = '<b>Total unread ['+this.data.items.length+']</b>';
            this.elements.switcher.checked = false;


            var count = Math.min(this.data.items.length, this.profile.newsCount);

            for(var i=0; i<count; i++) {
                var from = this.data.items[i].author.name ? this.data.items[i].author.name : this.data.items[i].author.email;
                var subj = this.data.items[i].title ? this.data.items[i].title : "[...]";
                var content = this.data.items[i].summary ? this.data.items[i].summary : "[...]";
                this.buildDomModel(this.elements.mail_list, 
                    { tag: "div", className: "menu_panel",
                      childs: [
                        { tag: "a", sysHref: this.data.items[i].link.href, target: "_blank",
                          innerHTML: "<b>" + from + "</b> - " + subj },
                        { tag: "div", id: "mail_content"+i, className: "note", display: false,
                          innerHTML: content }
                      ]
                    });
            }
        } else {
            showEl(this.elements.msg_no_new_mails);
        }
    }


    this.openInbox = function() {
        window.open("http://mail.google.com/mail");
    }

}
Gmail.prototype = new Widget();