var org = {p3k: ({url:"http://news.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss.xml", xml:"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><?xml-stylesheet title=\"XSL_formatting\" type=\"text/xsl\" href=\"/shared/bsp/xsl/rss/nolsol.xsl\"?><rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\"><channel><title>BBC News | Science &amp; Environment | World Edition</title><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/default.stm</link><description>Get the latest BBC Science and Environment News: breaking news, analysis and debate on science and nature in the UK and around the world.</description><language>en-gb</language><lastBuildDate>Tue, 09 Feb 2010 14:38:50 GMT</lastBuildDate><copyright>Copyright: (C) British Broadcasting Corporation, see http://news.bbc.co.uk/2/hi/help/rss/4498287.stm for terms and conditions of reuse</copyright><docs>http://www.bbc.co.uk/syndication/</docs><ttl>15</ttl><image><title>BBC News</title><url>http://news.bbc.co.uk/nol/shared/img/bbc_news_120x60.gif</url><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/default.stm</link></image><item><title>India defers first GM food crop</title><description>India defers the cultivation of what would have been its first genetically modified vegetable crop because of safety concerns.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/south_asia/8506047.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/world/south_asia/8506047.stm</guid><pubDate>Tue, 09 Feb 2010 13:48:04 GMT</pubDate><category>South Asia</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47268000/jpg/_47268158_-14.jpg\"/></item><item><title>Enceladus water story reinforced</title><description>The Cassini probe returns yet more data to back up the idea of a sub-surface sea on Saturn's moon Enceladus.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8495663.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8495663.stm</guid><pubDate>Mon, 08 Feb 2010 17:16:47 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/41424000/jpg/_41424620_enc_nasa_49.jpg\"/></item><item><title>Atom-smasher yields first result </title><description>The spray of subatomic particles from the Large Hadron Collider's record-smashing December experiments has been analysed.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8505203.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8505203.stm</guid><pubDate>Tue, 09 Feb 2010 11:04:19 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47265000/jpg/_47265114_a1420475-spl.h.jpg\"/></item><item><title>Shuttle makes final night flight</title><description>The US space agency (Nasa) has launched its shuttle Endeavour on a mission to the International Space Station (ISS).</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8503690.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8503690.stm</guid><pubDate>Mon, 08 Feb 2010 09:17:24 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47260000/jpg/_47260424_tv008698530.jpg\"/></item><item><title>First film of giant deep-sea fish</title><description>Scientists film the giant serpent-like oarfish in its natural deep-sea habitat for the first time, as well as the rare manefish. </description><link>http://news.bbc.co.uk/go/rss/-/earth/hi/earth_news/newsid_8501000/8501251.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/earth/hi/earth_news/newsid_8501000/8501251.stm</guid><pubDate>Mon, 08 Feb 2010 13:23:07 GMT</pubDate><category>Earth News</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47263000/jpg/_47263206_-21.jpg\"/></item><item><title>Genes reveal 'biological ageing'</title><description>Scientists say they have pinpointed gene variants that might show how fast people's bodies are ageing.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/health/8500761.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/health/8500761.stm</guid><pubDate>Mon, 08 Feb 2010 00:23:34 GMT</pubDate><category>Health</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47250000/jpg/_47250460_g1101075-telomeres-spl.jpg\"/></item><item><title>Dynamic Pluto revealed in images</title><description>Images from the Hubble Space Telescope reveal that the icy dwarf planet Pluto undergoes dramatic seasonal changes.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8498455.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8498455.stm</guid><pubDate>Fri, 05 Feb 2010 12:47:48 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47246000/jpg/_47246199_pluto_nasa_226.jpg\"/></item><item><title>How a quantum physics trick may make smartphones even smarter</title><description>A quantum physics trick is set to give smartphones and hand-held devices pressure-sensitive switches and touchscreens.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8504373.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8504373.stm</guid><pubDate>Tue, 09 Feb 2010 01:04:36 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47262000/jpg/_47262884_qtc_particle_image.jpg\"/></item><item><title>Birds that use their feathers like cats use their whiskers</title><description>Birds may use their feathers for touch - to feel their surroundings just as cats use their whiskers, scientists find.</description><link>http://news.bbc.co.uk/go/rss/-/earth/hi/earth_news/newsid_8500000/8500620.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/earth/hi/earth_news/newsid_8500000/8500620.stm</guid><pubDate>Fri, 05 Feb 2010 17:49:16 GMT</pubDate><category>Earth News</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47252000/jpg/_47252585_jones&amp;seneviratnewhaufromalaska.jpg\"/></item><item><title>Richard Black on what's happening to our shared environment</title><description></description><link>http://www.bbc.co.uk/go/rss/-/blogs/thereporters/richardblack/</link><guid isPermaLink=\"false\">http://www.bbc.co.uk/blogs/thereporters/richardblack/</guid><pubDate>Wed, 09 Dec 2009 16:04:17 GMT</pubDate><category>Americas</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/46887000/jpg/_46887588_000132903-1.jpg\"/></item><item><title>Green pounds</title><description>Eco-towns earmarked for government cash</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/uk_news/politics/8504050.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/uk_politics/8504050.stm</guid><pubDate>Mon, 08 Feb 2010 17:58:53 GMT</pubDate><category>UK Politics</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47263000/jpg/_47263701_007657626-1.jpg\"/></item><item><title>Robo-soldiers</title><description>Can 'well-behaved' robots make the battlefield safer?</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/in_depth/8495946.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/world/8495946.stm</guid><pubDate>Mon, 08 Feb 2010 01:36:36 GMT</pubDate><category>Special Reports</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47249000/jpg/_47249448_robots_eurolandtrial_concrete_getty57621859.jpg\"/></item><item><title>Spaceman</title><description>America ponders the options for a big rocket</description><link>http://www.bbc.co.uk/go/rss/-/blogs/thereporters/jonathanamos/2010/02/a-big-rocket-is-still-a-us-pri.shtml</link><guid isPermaLink=\"false\">http://www.bbc.co.uk/blogs/thereporters/jonathanamos/2010/02/a-big-rocket-is-still-a-us-pri.shtml</guid><pubDate>Sun, 07 Feb 2010 21:03:02 GMT</pubDate><category>Science &amp; Environment</category></item><item><title>In pictures</title><description>The troubles faced by the world's largest amphibian</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8500486.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8500486.stm</guid><pubDate>Sat, 06 Feb 2010 07:54:10 GMT</pubDate><category>Science &amp; Environment</category></item><item><title>Sea drifters </title><description>Colourful images of plankton in the world's oceans</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8498786.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8498786.stm</guid><pubDate>Thu, 04 Feb 2010 15:50:15 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47245000/jpg/_47245163_66x49-slide16.jpg\"/></item><item><title>Computing ace</title><description>The computer that laid the foundations of the internet </description><link>http://news.bbc.co.uk/go/rss/-/2/hi/technology/8498826.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/technology/8498826.stm</guid><pubDate>Fri, 05 Feb 2010 11:15:39 GMT</pubDate><category>Technology</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47245000/jpg/_47245263_ace-npl66.jpg\"/></item><item><title>Copenhagen - the Munich of our times?</title><description>The Copenhagen Climate Accord was a \"failure of historic proportions\" and hardly worth the paper it's printed on.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8490935.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8490935.stm</guid><pubDate>Tue, 02 Feb 2010 16:36:24 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47232000/jpg/_47232120_chamberlain300pa.jpg\"/></item><item><title>We cannot buy Earth more time</title><description>Global economic growth, in its current form, cannot continue if nations are serious about curbing climate change.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8479508.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8479508.stm</guid><pubDate>Tue, 26 Jan 2010 12:14:21 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47180000/jpg/_47180432_headhands300ap.jpg\"/></item><item><title>Warm world will be more fragrant</title><description>Climate change will make the world more fragrant, as warming temperatures make plants release more chemicals, according to a major scientific review.</description><link>http://news.bbc.co.uk/go/rss/-/earth/hi/earth_news/newsid_8503000/8503823.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/earth/hi/earth_news/newsid_8503000/8503823.stm</guid><pubDate>Tue, 09 Feb 2010 09:49:48 GMT</pubDate><category>Earth News</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47262000/jpg/_47262162_000163974-1.jpg\"/></item><item><title>Extraordinary owl preys on sloth</title><description>The first evidence of a sloth that has been killed by a owl.</description><link>http://news.bbc.co.uk/go/rss/-/earth/hi/earth_news/newsid_8486000/8486128.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/earth/hi/earth_news/newsid_8486000/8486128.stm</guid><pubDate>Thu, 04 Feb 2010 12:33:06 GMT</pubDate><category>Earth News</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47240000/jpg/_47240438_picture-9.jpg\"/></item><item><title>Dinosaur footprint haul in China</title><description>Scientists in China say they have discovered more than 3,000 dinosaur footprints, all facing in the same direction.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8502076.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8502076.stm</guid><pubDate>Sat, 06 Feb 2010 15:29:03 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47255000/jpg/_47255199_jex_595855_de27.jpg\"/></item><item><title>Insects migrate in wind highways</title><description>Migrating insects use highways in the sky to speed their journey, according to a study published in Science magazine.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8500619.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8500619.stm</guid><pubDate>Fri, 05 Feb 2010 14:47:33 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47249000/jpg/_47249926_fridaybutterfly2.jpg\"/></item><item><title>Ancient Indian language dies out</title><description>The last speaker of the Bo language in India's Andaman Islands dies at the age of about 85, a leading linguist says.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/south_asia/8498534.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/world/south_asia/8498534.stm</guid><pubDate>Thu, 04 Feb 2010 18:28:19 GMT</pubDate><category>South Asia</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47244000/jpg/_47244344_-1.jpg\"/></item><item><title>Scan unlocks vegetative patients</title><description>Scientists have been able to reach into the mind of a brain-damaged man and communicate with his thoughts. </description><link>http://news.bbc.co.uk/go/rss/-/2/hi/health/8497148.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/health/8497148.stm</guid><pubDate>Wed, 03 Feb 2010 22:00:35 GMT</pubDate><category>Health</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47240000/jpg/_47240377_fergusansweringyes.jpg\"/></item><item><title>Exoplanet gas spotted from Earth</title><description>Astronomers have used a new ground-based technique to study the atmospheres of planets outside our Solar System.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8493674.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8493674.stm</guid><pubDate>Wed, 03 Feb 2010 20:53:34 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47229000/jpg/_47229158_r650335-exoplanet_hd_189733b,_computer_artwork-spl.jpg\"/></item><item><title>Climate scepticism 'on the rise'</title><description>The British public has become increasingly sceptical about climate change, a poll for BBC News suggests.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8500443.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8500443.stm</guid><pubDate>Sun, 07 Feb 2010 12:02:29 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47251000/jpg/_47251460_chimneys226afp_index.jpg\"/></item><item><title>Russia 'dumped waste in Baltic'</title><description>The Russian military dumped nuclear waste into the Baltic Sea in the early 1990s, Swedish media reports say.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/europe/8499762.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/world/europe/8499762.stm</guid><pubDate>Fri, 05 Feb 2010 08:31:27 GMT</pubDate><category>Europe</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47248000/jpg/_47248344_008673556-1.jpg\"/></item><item><title>Embattled climate chief supported</title><description>India gives its full support to embattled climate change chief Rajendra Pachauri, under attack over recent scientific errors.</description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8499702.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8499702.stm</guid><pubDate>Fri, 05 Feb 2010 12:08:51 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47246000/jpg/_47246744_pachauri_ap.jpg\"/></item><item><title>How spider webs capture water</title><description>A new study reveals the structural secrets that allow spider webs to capture water droplets from the air. </description><link>http://news.bbc.co.uk/go/rss/-/2/hi/science/nature/8496559.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/1/hi/sci/tech/8496559.stm</guid><pubDate>Thu, 04 Feb 2010 16:20:13 GMT</pubDate><category>Science &amp; Environment</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47244000/jpg/_47244486_spiders_web_droplets-spl.jpg\"/></item><item><title>Wolverine numbers 'melting away' </title><description>A significant decline in predatory wolverines across North America is linked to melting snowpacks, say researchers. </description><link>http://news.bbc.co.uk/go/rss/-/earth/hi/earth_news/newsid_8494000/8494397.stm</link><guid isPermaLink=\"false\">http://news.bbc.co.uk/earth/hi/earth_news/newsid_8494000/8494397.stm</guid><pubDate>Wed, 03 Feb 2010 10:46:57 GMT</pubDate><category>Earth News</category><media:thumbnail width=\"66\" height=\"49\" url=\"http://newsimg.bbc.co.uk/media/images/47231000/jpg/_47231872_wolverinenplcomp.jpg\"/></item></channel></rss>\n", message:undefined, modified:(new Date(1265728705230)), baseUri:"http://p3k.org/rss/", query:"frameColor=#ffffff&textColor=black&_=1212332015662&titleBarColor=#000066&compact=&fontFace=Arial&align=left&showXmlButton=true&maxItems=6&boxFillColor=white&undefined=&titleBarTextColor=#ffffff&width=150&url=http://news.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss.xml&", param:{textColor:"black", width:"150", align:"left", fontFace:"Arial", url:"http://news.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss.xml", compact:"", frameColor:"#ffffff", showXmlButton:"true", undefined:"", boxFillColor:"white", _:"1212332015662", titleBarColor:"#000066", maxItems:"6", titleBarTextColor:"#ffffff"}, 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();

