var org = {p3k: ({url:"http://scouts.org.uk/news/rss", xml:"<?xml version=\"1.0\"?>\n\n<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\">\n<channel>\n<language>en</language>\n<title>The Scout Association NewsFeed</title>\n<description>The UK Scout Association's feed of latest news</description>\n<link>http://www.scouts.org.uk/news/rss</link>\n<copyright>Copyright 2008 The Scout Association</copyright>\n<managingEditor>web.team@scout.org.uk (Web Team)</managingEditor>\n<webMaster>web.team@scout.org.uk (Web Team)</webMaster>\n\n<item>\n<title><![CDATA[Scouting opens doors to thrillseekers]]></title>\n<pubDate>Mon, 01 Feb 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[The BBC have launched a campaign to get us off the sofa and out having an adventure, and The Scout Association is getting involved.]]></description>\n<link>http://www.scouts.org.uk/news/269/scouting-opens-doors-to-thrillseekers</link>\n<guid>http://www.scouts.org.uk/news/269/scouting-opens-doors-to-thrillseekers</guid>\n</item>\n\n<item>\n<title><![CDATA[African Queen]]></title>\n<pubDate>Fri, 29 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[A Perthshire Scout is one of eight young people selected for a BBC series which follows them as they learn how to be rangers on an African game reserve. ]]></description>\n<link>http://www.scouts.org.uk/news/268/african-queen</link>\n<guid>http://www.scouts.org.uk/news/268/african-queen</guid>\n</item>\n\n<item>\n<title><![CDATA[Scout response to Haiti disaster gathers pace]]></title>\n<pubDate>Thu, 21 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[Following the devastating earthquake in Port-au-Prince, Scouts from the UK and around the world have been responding through fundraising and action to help the victims.]]></description>\n<link>http://www.scouts.org.uk/news/267/scout-response-to-haiti-disaster-gathers-pace</link>\n<guid>http://www.scouts.org.uk/news/267/scout-response-to-haiti-disaster-gathers-pace</guid>\n</item>\n\n<item>\n<title><![CDATA[Support for Haiti Scouts]]></title>\n<pubDate>Fri, 15 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[Scouts from all over the world are rallying to offer aid and support to their counterparts in Haiti. Donations are flooding in and a bank account and online contribution facility have been set up by the World Scout Bureau. ]]></description>\n<link>http://www.scouts.org.uk/news/266/support-for-haiti-scouts</link>\n<guid>http://www.scouts.org.uk/news/266/support-for-haiti-scouts</guid>\n</item>\n\n<item>\n<title><![CDATA[2,000 Scouts brave cold for rugby showdown]]></title>\n<pubDate>Wed, 13 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[Over 50 Groups in Leicestershire raise Scouting's profile and enjoy a Premiership encounter in freezing conditions, with bands, clowns and plenty of adventure]]></description>\n<link>http://www.scouts.org.uk/news/265/2000-scouts-brave-cold-for-rugby-showdown</link>\n<guid>http://www.scouts.org.uk/news/265/2000-scouts-brave-cold-for-rugby-showdown</guid>\n</item>\n\n<item>\n<title><![CDATA[Winter adventure in the snow]]></title>\n<pubDate>Mon, 11 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[Last weekend 2,500 Scouts from across the UK welcomed in a new year of adventure. The Scouts from as far as Devon and North Wales braved sub zero temperatures and fields of snow to camp at Gilwell Park Activity Centre, the home of Scouting and outdoor adventure.]]></description>\n<link>http://www.scouts.org.uk/news/264/winter-adventure-in-the-snow</link>\n<guid>http://www.scouts.org.uk/news/264/winter-adventure-in-the-snow</guid>\n</item>\n\n<item>\n<title><![CDATA[Schools are closed but 2,500 Scouts enjoy winter adventure]]></title>\n<pubDate>Fri, 08 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[This weekend 2,500 Explorer Scouts from across the UK are welcoming in a new year of adventure.  ]]></description>\n<link>http://www.scouts.org.uk/news/262/schools-are-closed-but-2500-scouts-enjoy-winter-adventure</link>\n<guid>http://www.scouts.org.uk/news/262/schools-are-closed-but-2500-scouts-enjoy-winter-adventure</guid>\n</item>\n\n<item>\n<title><![CDATA[A decade of adventure]]></title>\n<pubDate>Fri, 08 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[It's been a momentous decade for Scouting. As fireworks ushered in a new millennium, and the millennium bug failed to bite, the UK\u2019s Scouts could never have anticipated what the first decade of the 21st century would bring.]]></description>\n<link>http://www.scouts.org.uk/news/261/a-decade-of-adventure</link>\n<guid>http://www.scouts.org.uk/news/261/a-decade-of-adventure</guid>\n</item>\n\n<item>\n<title><![CDATA[Snow rescue efforts boosted by Scout assistance]]></title>\n<pubDate>Wed, 06 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[Scout volunteers in the Midlands have been coming to the aid of local people by providing medicines and emergency supplies as weather conditions worsen. ]]></description>\n<link>http://www.scouts.org.uk/news/259/snow-rescue-efforts-boosted-by-scout-assistance</link>\n<guid>http://www.scouts.org.uk/news/259/snow-rescue-efforts-boosted-by-scout-assistance</guid>\n</item>\n\n<item>\n<title><![CDATA[Top Blue Peter award for young Scouting heroes]]></title>\n<pubDate>Mon, 04 Jan 2010 00:00:00 +0000</pubDate>\n<description><![CDATA[Five young Scouts have been awarded Blue Peter Gold badges in recognition of their inspiring acts of bravery and generosity. ]]></description>\n<link>http://www.scouts.org.uk/news/258/top-blue-peter-award-for-young-scouting-heroes</link>\n<guid>http://www.scouts.org.uk/news/258/top-blue-peter-award-for-young-scouting-heroes</guid>\n</item>\n\n<item>\n<title><![CDATA[Scouts give the greatest gift of all at Christmas ]]></title>\n<pubDate>Sat, 26 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Christmas is a special time for giving and there is nothing greater than giving the gift of life. Twelve young people who courageously put the skills that they learnt in Scouting into dramatic effect have been recognised by The Scout Association.]]></description>\n<link>http://www.scouts.org.uk/news/257/scouts-give-the-greatest-gift-of-all-at-christmas</link>\n<guid>http://www.scouts.org.uk/news/257/scouts-give-the-greatest-gift-of-all-at-christmas</guid>\n</item>\n\n<item>\n<title><![CDATA[A decade of adventure]]></title>\n<pubDate>Thu, 24 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Take a look back at the last ten years of Scouting, with our review in words, pictures and video.]]></description>\n<link>http://www.scouts.org.uk/news/255/a-decade-of-adventure</link>\n<guid>http://www.scouts.org.uk/news/255/a-decade-of-adventure</guid>\n</item>\n\n<item>\n<title><![CDATA[Thank you for your continued support!]]></title>\n<pubDate>Thu, 24 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[2009 was full of many exciting successes and growth stories for Scouting, both locally and nationally. We look forward to even more of this in 2010.]]></description>\n<link>http://www.scouts.org.uk/news/256/thank-you-for-your-continued-support</link>\n<guid>http://www.scouts.org.uk/news/256/thank-you-for-your-continued-support</guid>\n</item>\n\n<item>\n<title><![CDATA[Scout campaigners invited to Copenhagen conference debrief]]></title>\n<pubDate>Wed, 23 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Over 30 members of the Scout Young Campaigners team joined a specially invited audience to hear Secretary of State Ed Miliband and Prime Minister Gordon Brown offer their views on last week\u2019s climate change summit in Copenhagen.]]></description>\n<link>http://www.scouts.org.uk/news/254/scout-campaigners-invited-to-copenhagen-conference-debrief</link>\n<guid>http://www.scouts.org.uk/news/254/scout-campaigners-invited-to-copenhagen-conference-debrief</guid>\n</item>\n\n<item>\n<title><![CDATA[Explorer Scouts are 'life savers']]></title>\n<pubDate>Mon, 14 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Christmas is a time for giving and a group of Scouts from Carlisle have taken that concept to a new level by donating their own blood. ]]></description>\n<link>http://www.scouts.org.uk/news/253/explorer-scouts-are-life-savers</link>\n<guid>http://www.scouts.org.uk/news/253/explorer-scouts-are-life-savers</guid>\n</item>\n\n<item>\n<title><![CDATA[Scouts attend UN Climate Change Conference]]></title>\n<pubDate>Tue, 08 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Monday saw the start of The United Nations Climate Change Conference in Copenhagen. Scouts have joined scientists, environmental activists and members of the general public to put pressure on attending politicians to agree on a way forward to deal with the threat of climate change.]]></description>\n<link>http://www.scouts.org.uk/news/252/scouts-attend-un-climate-change-conference</link>\n<guid>http://www.scouts.org.uk/news/252/scouts-attend-un-climate-change-conference</guid>\n</item>\n\n<item>\n<title><![CDATA[Chief Scout parascends into Who's Who list]]></title>\n<pubDate>Mon, 07 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Chief Scout Bear Grylls has been included in the latest edition of Who\u2019s Who which features the biographies of people of \u2018distinction and influence\u2019.]]></description>\n<link>http://www.scouts.org.uk/news/251/chief-scout-parascends-into-whos-who-list</link>\n<guid>http://www.scouts.org.uk/news/251/chief-scout-parascends-into-whos-who-list</guid>\n</item>\n\n<item>\n<title><![CDATA[Scouting magazine: Youth Editors edition]]></title>\n<pubDate>Wed, 02 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[We handed Scouting magazine over to five Scouts aged 10-18. From interviewing their heroes, to writing about issues that affect young people today, and creating their perfect programme of activities, see how they got on in this short film.]]></description>\n<link>http://www.scouts.org.uk/news/250/scouting-magazine-youth-editors-edition</link>\n<guid>http://www.scouts.org.uk/news/250/scouting-magazine-youth-editors-edition</guid>\n</item>\n\n<item>\n<title><![CDATA[Scouts in record tree planting attempt]]></title>\n<pubDate>Tue, 01 Dec 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Scouts across the UK are preparing to create history by helping to set a new world record this weekend. Participating groups have answered the call to plant more than 653,000 trees in just one hour at multiple sites. ]]></description>\n<link>http://www.scouts.org.uk/news/249/scouts-in-record-tree-planting-attempt</link>\n<guid>http://www.scouts.org.uk/news/249/scouts-in-record-tree-planting-attempt</guid>\n</item>\n\n<item>\n<title><![CDATA[House of Lords recognises Scouts campaign victory]]></title>\n<pubDate>Thu, 26 Nov 2009 00:00:00 +0000</pubDate>\n<description><![CDATA[Tribute has been paid in the House of Lords to the Scouts who successfully campaigned to overturn Ofwat\u2019s plans to introduce a rain tax for community groups.]]></description>\n<link>http://www.scouts.org.uk/news/248/house-of-lords-recognises-scouts-campaign-victory</link>\n<guid>http://www.scouts.org.uk/news/248/house-of-lords-recognises-scouts-campaign-victory</guid>\n</item>\n\n</channel>\n</rss>\n", message:undefined, modified:(new Date(1265723640726)), baseUri:"http://p3k.org/rss/", query:"frameColor=#000000&textColor=black&_=1222260272296&titleBarColor=orange&compact=&fontFace=Verdana&align=&showXmlButton=&maxItems=2&boxFillColor=#99cc00&titleBarTextColor=#000000&width=200&url=http://scouts.org.uk/news/rss&", param:{textColor:"black", width:"200", align:"", fontFace:"Verdana", url:"http://scouts.org.uk/news/rss", compact:"", frameColor:"#000000", showXmlButton:"", boxFillColor:"#99cc00", _:"1222260272296", titleBarColor:"orange", maxItems:"2", titleBarTextColor:"#000000"}, box:"<table class=\"rssBox\" width=\"${width}\" bgcolor=\"${frameColor}\" \n      style=\"table-layout: fixed; overflow: hidden; font-family: ${fontFace};\" \n      align=\"${align}\" cellspacing=\"1\" cellpadding=\"7\" border=\"0\">\n<tr bgcolor=\"${titleBarColor}\">\n<td>\n   ${xmlButton}\n   <strong>${title}</strong>\n   <div>\n      <small style=\"color: ${titleBarTextColor};\">${date}</small>\n   </div>\n</td>\n</tr>\n<tr bgcolor=\"${boxFillColor}\">\n<td class=\"rssBoxContent\" style=\"color: ${textColor};\">\n   ${image}\n   ${items}\n   ${input}\n   <div class=\"rssBoxPromo\" style=\"margin-top: 0px; text-align: left; \n         font: 9px verdana, sans-serif\">\n      RSS box by <a href=\"http://p3k.org/rss\">p3k.org</a>.\n   </div>\n</td>\n</tr>\n</table>\n\n", image:"<a href=\"${link}\"><img src=\"${source}\" width=\"${width}\" height=\"${height}\" \nalt=\"${title}\" title=\"${title}\" align=\"${align}\" valign=\"${valign}\" \nhspace=\"${hspace}\" vspace=\"${vspace}\" border=\"0\" /></a>\n\n", input:"<form method=\"get\" action=\"${link}\">\n${description}\n<input type=\"text\" name=\"${name}\" size=\"15\" /> <input type=\"submit\" \nvalue=\"${title}\" />\n</form>\n\n", item:"<div class=\"rssBoxItemContent\">\n${title}\n${break}\n${description}\n${buttons}\n</div><br />\n\n", date:"${year}-${month}-${day}, ${hours}:${minutes}h\n\n", link:"<a class=\"${class}\" href=\"${link}\" style=\"${style}\">${text}</a>\n", error:"<?xml version=\"1.0\"?>\n<rss version=\"error\">\n   <channel>\n      <title>RSS Box Error</title>\n      <link>${link}</link>\n      <description>This output was automatically generated to report an error \n      that occurred during a request to the JavaScript RSS Box Viewer.</description>\n      <item>\n         <title>Oops, something went wrong...</title>\n         <description>An error occurred while processing the request to the \n         JavaScript RSS Box Viewer.</description>\n      </item>\n      <item>\n         <title>An error message was returned by the server.</title>\n         <description>${message}</description>\n      </item>\n      <item>\n         <description>Most likely, this might have happened because of a \n         non-existent or invalid RSS feed URL. Please check and possibly correct \n         your input, then try again.</description>\n      </item>\n   </channel>\n</rss>\n\n"})};
function debug(str) {
   return document.write('<p><span style="background-color: yellow;">', 
         str, '</span><p>');
}

org.p3k.RssBox = function() {
   var ref;
   var ISOPATTERN = /([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9:]+).*$/;
   
   var data = org.p3k;
   data.defaults = {
      url: "http://blog.p3k.org/rss",
      maxItems: 7,
      width: 200,
      align: "",
      frameColor: "black",
      titleBarColor: "lightblue",
      titleBarTextColor: "black",
      boxFillColor: "white",
      textColor: "black",
      showXmlButton: "",
      compact: ""
   };
   
   var baseUri = data.baseUri;
    
   var getColor = function(str) {
      if (str.length === 6 && parseInt(str, 16) && str.indexOf("#") !== 0) {
         str = "#" + str;
      }
      return str.toLowerCase();
   }

   var value;
   for (var i in data.defaults) {
      value = data.param[i];
      if (!value || value.length === 0) {
         data.param[i] = data.defaults[i];
      } else if (i.indexOf("Color") > 0) {
         data.param[i] = getColor(value);
      }
   }

   // FIXME: Ugly work-around for many boxes using too small width 
   // values because the former version did not show the exact output.
   if (data.param.javascript && data.param.width < 200) {
      data.param.width = 200;
   }
   // Remove obsolete parameters from param and query
   delete data.param.javascript;
   data.query = data.query.replace("javascript=true", "");   

   var NAMESPACES = {
      dc: "http://purl.org/dc/elements/1.1/",
      rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   };

   var getUrl = function(url) {
      url = baseUri + "proxy.r?" + encodeURIComponent(url);
   
      var HttpRequest = function() {
         return (typeof XMLHttpRequest !== "undefined") ?
            new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
      }
   
      var request = new HttpRequest();
      request.open("GET", url, false);
      request.send(null);   
      if (!request.getResponseHeader("Date")) {
         var cached = request;
         var ifModifiedSince = cached.getResponseHeader("Last-Modified") || 
               new Date(0); // January 1, 1970
         request = new HttpRequest();
         request.open("GET", url, false);
         request.setRequestHeader("If-Modified-Since", ifModifiedSince);
         request.send("");
         if (request.status === 304) {
            request = cached; 
         }
      }
      return request;
   }
   
   var getDocument = function(source) {
      if (source) {
         if (document.implementation.createDocument) {
            var parser = new DOMParser();
            var doc = parser.parseFromString(source, "text/xml");
            return doc;
         } else if (window.ActiveXObject) {
            var doc = new ActiveXObject("Microsoft.XMLDOM");
            doc.async = "false";
            doc.loadXML(source);
            return doc;
         }
      }
      return null;
   }
   
   var getError = function() {
      var msg = null, root;
      if (!xml || data.message) {
         msg = data.message || "Unknown error.";
      } else if (xml.parseError && xml.parseError.errorCode) {
         msg = xml.parseError.reason; // IExplore
      } else if (root = xml.documentElement) {
         var errorNode;
         if (root.nodeName === "parsererror") {
            msg = xml.documentElement.textContent; // Mozilla
         } else if ((errorNode = root.childNodes[0]) && 
               errorNode.nodeName === "parsererror") {
            msg = errorNode.textContent; // Safari
         } else if (!/rss|rdf|scriptingNews/i.test(xml.documentElement.nodeName)) {
            msg = "Incompatible data format. Are you sure this is an RSS feed?";
         }
      }
      return msg;
   }
   
   var getNode = function(parent, name, namespace) {
      if (namespace) {
         if (typeof parent.getElementsByTagNameNS === "undefined") {
            var elements = parent.getElementsByTagName(namespace + ":" + name);
         } else {
            var elements = parent.getElementsByTagNameNS(NAMESPACES[namespace], name);
         }
      } else {
         var elements = parent.getElementsByTagName(name);
      }
      if (elements && elements[0]) {
         return elements[0];
      }
      return null;
   }
   
   var getText = function(node) {
      if (node && node.childNodes && node.childNodes.length > 0) {
         return node.childNodes[0].nodeValue || "";
      }
      return "";
   }
   
   var trim = function(str) {
      if (str) {
         return str.replace(/^\s*(\S*)\s*$/, "$1");
      }
      return "";
   }
   
   var padZero = function(n) {
      if (n < 10) {
         return "0" + n
      }
      return n;
   }

   var encodeXml = function(str) {
      if (!str) {
         return "";
      }
      return str.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/&/g, "&amp;");
   }
      
   var render = function(template, param) {
      if (!template || !param) {
         return template;
      }
      template = template.replace(/\$\{([^}]+)\}/g, function() {
         var key = arguments[1];
         return param[key] || "";
      });
      return template;
   }
   
   var renderDate = function(date) {
      if (date.constructor !== Date) {
         var str = String(date);
         var millis = Date.parse(str.replace(ISOPATTERN, "$1/$2/$3 $4"));
         if (millis) {
            date = new Date(millis);
         } else {
            date = new Date;
         }
      }

      return render(data.date, {
         year: date.getFullYear(),
         month: padZero(date.getMonth() + 1),
         day: padZero(date.getDate()),
         hours: padZero(date.getHours()),
         minutes: padZero(date.getMinutes()),
         seconds: padZero(date.getSeconds()),
         timeZone: "" // date.getTimezoneOffset()
      });
   }
   
   var renderButtons = function(enclosure, source) {
      var result = "";
      if (enclosure && enclosure.link) {
         result += render(data.image, {
            source: baseUri + "enclosure.gif",
            title: enclosure.type,
            link: encodeURI(enclosure.link),
            width: 13,
            height: 16
         });
      }
      if (source && source.link) {
         result += render(data.image, {
            source: baseUri + "source.gif",
            title: source.title,
            link: encodeURI(source.link),
            width: 15,
            height: 15
         });
      }
      return result;         
   }
   
   var param = data.param;
   var rss = data.rss = {items: []};
   var xml = getDocument(data.xml);

   rss.error = getError();
   if (rss.error !== null) {
      xml = getDocument(render(data.error, {
         link: baseUri + "?" + encodeXml(data.query),
         message: encodeXml(rss.error)
      }));
      param.compact = 0;
      param.showXmlButton = 1;
   }

   var root = xml.documentElement;
   var type = root.nodeName;

   if (type === "scriptingNews") {
      var channel = getNode(xml, "header");
      rss.format = "Scripting News";
      rss.version = getText(getNode(channel, "scriptingNewsVersion"));
      rss.title = getText(getNode(channel, "channelTitle"));
      rss.description = getText(getNode(channel, "channelDescription"));
      rss.link = getText(getNode(channel, "channelLink"));
      if (ref = getText(getNode(channel, "imageUrl"))) {
         ref = rss.image = {source: ref};
         ref.title = getText(getNode(channel, "imageTitle"));
         ref.link = getText(getNode(channel, "imageLink"));
         ref.width = getText(getNode(channel, "imageWidth"));
         ref.height = getText(getNode(channel, "imageHeight"));
         ref.description = getText(getNode(channel, "imageCaption"));
      }
   } else {
      var channel = getNode(xml, "channel");
      rss.format = "RSS";
      rss.version = (type === "rdf:RDF") ? "1.0" : 
            root.getAttribute("version");
      rss.title = getText(getNode(channel, "title"));
      rss.description = getText(getNode(channel, "description"));
      rss.link = getText(getNode(channel, "link"));
      var image = getNode(xml, "image");
      if (image) {
         ref = rss.image = {};
         ref.source = getText(getNode(image, "url"));
         ref.title = getText(getNode(image, "title"));
         ref.link = getText(getNode(image, "link"));
         ref.width = getText(getNode(image, "width"));
         ref.height = getText(getNode(image, "height"));
         ref.description = getText(getNode(image, "description"));
      }
   }
   
   if (type === "rdf:RDF") {
      rss.date = renderDate(getText(getNode(channel, "date", "dc")) || data.modified);
      rss.rights = getText(getNode(channel, "creator", "dc"));
      var input = getNode(root, "textinput");
      if (input && !getNode(input, "link")) {
         input = root.getElementsByTagName("textinput")[1];
      }
      if (input) {
         ref = rss.input = {};
         ref.link = getText(getNode(input, "link"));
         ref.description = getText(getNode(input, "description"));
         ref.name = getText(getNode(input, "name"));
         ref.title = getText(getNode(input, "title"));
      }
   } else {
      rss.date = renderDate(getText(getNode(channel, "lastBuildDate") || getText(getNode(channel, "pubDate"))) || data.modified);
      rss.rights = getText(getNode(channel, "copyright"));
   }
   
   var item, text, node;
   var items = xml.getElementsByTagName("item");

   for (var i=0; i<Math.min(items.length, param.maxItems); i+=1) {
      item = items[i];

      if (type === "scriptingNews") {
         ref = {title: ""};
         ref.description = getText(getNode(item, "text")).replace(/\n/g, " ");
         ref.link = getText(getNode(item, "link"));
         if (text = trim(getText(getNode(item, "linetext")).replace(/\n/g, " "))) {
            ref.description = ref.description.replace(new RegExp(text), 
                  '<a href="' + getText(getNode(item, "url")) + '">' + text + '</a>');
         }
      } else {
         ref = {
            title: getText(getNode(item, "title")),
            description: getText(getNode(item, "description")),
            link: getText(getNode(item, "link") || getNode(item, "guid"))
         };
     }

     if (node = getNode(item, "source")) {
        ref.source = {
           link: node.getAttribute("url"),
           title: getText(node)
        }
     }
     
     if (node = getNode(item, "enclosure")) {
        ref.enclosure = {
           link: node.getAttribute("url"),
           length: node.getAttribute("length"),
           type: node.getAttribute("type")
        }
     }
     
     if (node = getNode(item, "category")) {
        ref.category = {
           domain: node.getAttribute("domain") || "",
           content: getText(node)
        }
     }
     
     rss.items.push(ref);
   }
   
   var item, items = "";
   for (var i=0; i<rss.items.length; i+=1) {
      item = rss.items[i];
      items += render(data.item, {
         title: new function() {
            var title = (!param.compact ? "<strong>" : "");
            if (item.link) {
               title += render(data.link, {
                  link: encodeURI(item.link),
                  text: item.title,
                  'class': "rssBoxItemTitle"
               });
            } else {
               title += item.title;
            }
            !param.compact && (title += "</strong>");
            return new String(title); // FIXME: Funny, title alone will be rendered as [object]
         }(),
         'break': item.title && item.description ? "<br />" : "",
         description: (!param.compact || !item.title) && item.description,
         buttons: renderButtons(item.enclosure, item.source)
      });
   }
   
   var box = render(data.box, {
      title: rss.link ? render(data.link, {
         link: encodeURI(rss.link),
         text: rss.title,
         'class': "rssBoxTitle",
         style: "color: " + param.titleBarTextColor
      }) : rss.title,
      description: rss.description,
      items: items,

      xmlButton: param.showXmlButton && render(data.image, {
         link: param.url,
         source: baseUri + "rss.png",
         title: rss.format + " " + rss.version,
         width: 16,
         height: 16,
         align: "right",
         hspace: 3
      }),
      
      image: !param.compact && rss.image && render(data.image, {
         link: encodeURI(rss.image.link),
         source: rss.image.source,
         width: rss.image.width,
         height: rss.image.height,
         title: rss.image.title,
         align: "right",
         valign: "baseline",
         hspace: 5,
         vspace: 5
      }),
      
      input: !param.compact && rss.input && render(data.input, {
         link: encodeURI(rss.input.link),
         description: rss.input.description,
         name: rss.input.name,
         title: rss.input.title
      }),
      
      date: rss.date,
      width: param.width,
      frameColor: param.frameColor,
      fontFace: param.fontFace,
      align: param.align,
      titleBarColor: param.titleBarColor,
      titleBarTextColor: param.titleBarTextColor,
      boxFillColor: param.boxFillColor,
      textColor: param.textColor
   });

   if (!window.rssBoxSetup) {
      document.write(box);
   }
   
   return box;
};

org.p3k.RssBox();

