function RssReader() {
    this.init();

    this.cfg = {
        hasSizeBtn: false,
        hasRefreshBtn: false,
        hasSettingsBtn: false,
        hasDrag: false,
        hasProfile: false,
        title: "Feed Reader",
        module: "RssReader"
    }

    this.domContent = {
        tag: "table", width: "100%",
        childs: [
          { tag: "tr",
            childs: [
              { tag: "td", width: "30%",
                childs: createTableDom([{ content: createButtonDom("Read&All", "readAll()", "widgets/rssreader/img/folder_open.gif"), width: "50px"},
                                        { content: createButtonDom("Unread&All", "unReadAll()", "widgets/rssreader/img/folder_close.gif"), width: "50px"}])
              },
              { tag: "td", 
                childs: [{ tag: "div", id: "channelTitle"}]
              }
            ]
          },
          { tag: "tr",
            childs: [
              { tag: "td", width: "30%",
                childs: [
                  { tag: "div", id: "menu", className: "listBox", style: {width: "auto", height: "350px"}}
                ]
              },
              { tag: "td",
                childs: [
                  { tag: "div", id: "view", className: "listBox", style: {width: "auto", height: "350px"}}
                ]
              }
            ]
          }
        ]
    }

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

    this.channelLastRefresh = null;

    this.onBuildInterface = function() {
        this.buildDomModel(this.elements.content, this.domContent);
        this.setTitle(this.cfg.title);
    }


    this.buildChannel = function() {
//        this.elements.channelTitle.innerHTML = "<h1><a target=\"_blank\" href=\""+this.data.LINK+"\">"+this.data.title+"</a></h1>";
        this.elements.channelTitle.innerHTML = "<h1>"+this.data.title+"</h1>";
        this.elements.menu.innerHTML = "";
        this.elements.view.innerHTML = "";
        for(i in this.data.items) {
            this.buildDomModel(this.elements.menu, 
                               [{ tag: "div", className: "menu_panel",
                                  childs: [
                                    { tag: "a", 
                                      innerHTML: this.data.items[i].title.wordWrap(38),
                                      id: "menuItem"+i,
                                      href: "void", 
                                      events: {onclick: "readFeed("+i+")"}, 
                                      className: "listItem" + (this.data.items[i].isRead ? "visited" : "") }
                                  ]
                                },
                                { tag: "hr", width: "100%"}
                               ]);
        }
    }


    
    this.readFeed = function(feedId) {
        this.elements.view.innerHTML = "";
        this.buildDomModel(this.elements.view, 
                           [ { tag: "div", className: "menu_panel", align: "right",
                               childs: [ createTableDom([{content: createButtonDom(false, "readFeed("+(feedId-1)+")", "widgets/rssreader/img/previous.gif", "readPrev"), width: "1%"},
                                                         {content: createButtonDom(false, "readFeed("+(feedId+1)+")", "widgets/rssreader/img/next.gif", "readNext"), width: "1%"}], "1%")
                                       ]
                             },

                             { tag: "hr", width: "100%"},

                             { tag: "div", className: "menu_panel",
                               innerHTML: "<h1>"+this.data.items[feedId].title+"</H1>"+
                                          "<p><a href='"+this.data.items[feedId]["link"]+"' target=_blank>"+this.data.items[feedId]["link"]+"</a>"/*+
                                          "<p>"+(this.data.items[feedId].description ? (this.data.items[feedId].description.p ? this.data.items[feedId].description.p : this.data.items[feedId].description ): "" )*/
                             }
                           ]);

	var descObj = this.data.items[feedId].description;
	var descHTML = "";
	if(descObj.childNodes)
	{
		ln = descObj.childNodes.length;
		for(i=0;i<ln;i++)
			descHTML += descObj.childNodes[i].nodeValue;
	}
	
	this.elements.view.childNodes[2].appendChild(document.createElement("div"));
	this.elements.view.childNodes[2].lastChild.innerHTML=descHTML;
        if(!this.data.items[feedId-1]) {
            hideEl(this.elements.readPrev);
        }
        if(!this.data.items[feedId+1]) {
            hideEl(this.elements.readNext);
        }
        this.data.items[feedId].isRead = true;
        this.elements['menuItem'+feedId].className = "listItemVisited";
    }

  
    this.readAll = function() {
        for(i in this.data.items) {
            this.data.items[i].isRead = true;
        }
        this.buildChannel();
    }


    this.unReadAll = function() {
        for(i in this.data.items) {
            this.data.items[i].isRead = false;
        }
        this.buildChannel();
    }


    this.openChannel = function(widgetId, feedId) {
        this.data = kernel.getWidget(widgetId).data;
        this.widgetId = widgetId;
        this.buildChannel();
        this.elements.icon.src = kernel.getWidget(widgetId).elements.icon.src;
        desktop.showPage('rssreader');
        this.readFeed(feedId);
    }


    this.close = function() {
        if(this.widgetId) {
            if(this.channelLastRefresh == kernel.getWidget(this.widgetId).lastRefresh) {
                kernel.getWidget(this.widgetId).data = this.data;
            }
        }
        desktop.closeCurrentPage();
    }
 
}
function xml2String(thexml){
	if(thexml.xml){
		// MSIE
		xmlString = thexml.xml;
	}else{
		// Gecko
		xmlString = (new XMLSerializer).serializeToString(thexml);
	}
	return xmlString;
}
RssReader.prototype = new Widget();
