var org = {p3k: ({url:"http://news.thomasnet.com/conewsxml/10043514", xml:"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<!-- generator=\"FeedCreator 1.7.1\" -->\n<rss version=\"2.0\">\n    <channel>\n        <title>RSS Feed for Rexnord Corp.</title>\n        <description>ThomasNet News is a service of ThomasNet.com</description>\n        <link>http://news.thomasnet.com</link>\n        <lastBuildDate>Sun, 05 Sep 2010 22:38:58 -0400</lastBuildDate>\n        <generator>FeedCreator 1.7.1</generator>\n        <image>\n            <url>http://news.thomasnet.com/images/header/TN_News_footer.gif</url>\n            <title>Powered by ThomasNet News</title>\n            <link>http://news.thomasnet.com</link>\n            <width>129</width>\n            <height>38</height>\n        </image>\n        <item>\n            <title>Shaft-Mounted Drives feature simple drive removal.</title>\n            <link>http://news.thomasnet.com/fullstory/Shaft-Mounted-Drives-feature-simple-drive-removal-535260</link>\n            <description>\nSeries 5000 Falk(TM) Quadrive&amp;#174; shaft-mounted drives handle all types of bulk material and are protected by ductile iron, or fabricated steel housings. Eleven drive sizes are available, ranging from 1.0-6.5 in. bushing bores with power ratings up to 300 hp. Each size offers carburization, ground gearing, taper roller bearings, and high temperature Viton seals. Falk(TM) TA Taper&amp;#174; bushing enables damage-free, fast, drive removal.\n&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-power-transmission' target='_blank''&gt;Mechanical Power Transmission&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/shaft-mounted-drives-24401408-1.html' target='_blank''&gt;Shaft Mounted Drives&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Mon, 03 Dec 2007 07:42:17 -0400</pubDate>\n        </item>\n        <item>\n            <title>\nRexnord to be Acquired by Apollo Management for $1.825 Billion\n </title>\n            <link>http://news.thomasnet.com/companystory/Rexnord-to-be-Acquired-by-Apollo-Management-for-1-825-Billion-486052</link>\n            <description>\n \n \nMilwaukee, WI-May 25, 2006\n\nRexnord Corporation, a leading manufacturer of precision motion technology products, today announced that an affiliate of the private equity firm, Apollo Management, has signed an agreement to purchase RBS Global, Inc., the corporate parent of Rexnord, for $1.825 billion from private equity firm The Carlyle Group and management. The transaction is subject to government approvals and other customary conditions and is expected to close in the third calendar ...</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Wed, 31 May 2006 08:03:17 -0400</pubDate>\n        </item>\n        <item>\n            <title>Side-Flexing Chains stay flat and level on curves.</title>\n            <link>http://news.thomasnet.com/fullstory/Side-Flexing-Chains-stay-flat-and-level-on-curves-469820</link>\n            <description>\nLPC&amp;#174; 1050 and LPC&amp;#174; 1055 TableTop&amp;#174; chains have low pin centerline design (LPC) that eliminates product tippage on multi-strand conveyors, without need for magnetic corner tracks. Pitch length and top plate thickness resist chipping and breaking via LPC corner retention technology, and chains can be lifted up anywhere in carry track for cleaning and maintenance. Offered in 0.34 and 0.50 in. flight thicknesses, chains come in PS(TM) wear-resistant material as well as HP(TM).\n&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/material-handling-storage' target='_blank''&gt;Material Handling and Storage&lt;/a&gt; Sponsored by:  &lt;a target='_blank' href='http://news.thomasnet.com/redir.html?lnty=rssad&amp;spclid=3473&amp;prid=469820&amp;cat=1424&amp;goto=http%3A%2F%2Fwww.reidsupply.com%2FCad.aspx'&gt;Reid Supply - FREE CAD Drawings of Tens-of-Thousands of Parts!&lt;/a&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-components-assemblies' target='_blank''&gt;Mechanical Components and Assemblies&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/flat-link-chains-13272208-1.html' target='_blank''&gt;Flat Link Chains&lt;/a&gt;  |  &lt;a href='http://www.thomasnet.com/products/conveyor-chains-13231204-1.html' target='_blank''&gt;Conveyor Chains&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Fri, 25 Nov 2005 07:07:25 -0400</pubDate>\n        </item>\n        <item>\n            <title>Gear Reducers offer hollow shaft mounting option.</title>\n            <link>http://news.thomasnet.com/fullstory/Gear-Reducers-offer-hollow-shaft-mounting-option-468751</link>\n            <description>\nOffering alternative to traditional helical shaft mounted reducers, Shaft Mounted Planetgear&amp;#174; Reducers feature modular design and interchangeable components. Self-aligning gear train has at least 6 teeth in contact per reduction to share load equally. Integral to low speed shaft, Hydro Advantage facilitates removal of reducer. Shaft mount configuration is available on Orion, Titan, Jupiter and Hercules sizes, with output torque ranging from 280,000-2,900,000 lb-in.\n&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-power-transmission' target='_blank''&gt;Mechanical Power Transmission&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/gear-reducers-66562802-1.html' target='_blank''&gt;Gear Reducers&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Mon, 31 Oct 2005 07:05:21 -0400</pubDate>\n        </item>\n        <item>\n            <title>Conveyor Chains suit tire industry applications.</title>\n            <link>http://news.thomasnet.com/fullstory/Conveyor-Chains-suit-tire-industry-applications-456293</link>\n            <description>For conveying and accumulating tires, 2.5 in. pitch MatTop&amp;#174; LBP3003 chain is constructed with accumulating rollers spaced on 1.5 in. increments along width. Tires can be conveyed through 90&amp;#176; transfer points with MatTop&amp;#174; LBP3004 chain. Elongated rollers, perpendicular to direction of travel, form uniform roller bed for tires to move across. Staggered 1.5 in. rollers are spaced on diagonal distance of 1.5 in. to provide stable handling for tires of all sizes.&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/material-handling-storage' target='_blank''&gt;Material Handling and Storage&lt;/a&gt; Sponsored by:  &lt;a target='_blank' href='http://news.thomasnet.com/redir.html?lnty=rssad&amp;spclid=3473&amp;prid=456293&amp;cat=1424&amp;goto=http%3A%2F%2Fwww.reidsupply.com%2FCad.aspx'&gt;Reid Supply - FREE CAD Drawings of Tens-of-Thousands of Parts!&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/conveyor-chains-13231204-1.html' target='_blank''&gt;Conveyor Chains&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Thu, 07 Oct 2004 08:06:49 -0400</pubDate>\n        </item>\n        <item>\n            <title>Rectifiers offer options for armature-actuated brakes.</title>\n            <link>http://news.thomasnet.com/fullstory/Rectifiers-offer-options-for-armature-actuated-brakes-16184</link>\n            <description>Stearns&amp;#174; AAB Rectifiers include Quick Set and Quick Set/Release features. Quick Set provides quicker coil turn-off where rectifier AC input leads are wired permanently and directly to input terminals of AC motor line. Quick Set/Release model provides same function and also energizes coil to reduce armature attraction time. Optional proving switch monitors current wave form of brake coil and signals when brake is released via light, buzzer or other alarm device.&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/electronic-components-devices' target='_blank''&gt;Electronic Components and Devices&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/rectifiers-66471608-1.html' target='_blank''&gt;Rectifiers&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Wed, 13 Nov 2002 07:45:39 -0400</pubDate>\n        </item>\n        <item>\n            <title>Disc Brake features NEMA 4/IP-55 moisture protection.</title>\n            <link>http://news.thomasnet.com/fullstory/Disc-Brake-features-NEMA-4-IP-55-moisture-protection-13509</link>\n            <description>Stearns&amp;#174; 87,300 Series solenoid-actuated, hazardous location disc brake is offered in 7 sizes with torque ratings from 10&amp;#226;\ufffd&amp;quot;105 lb-ft. Motor- and foot-mounted versions are available with NEMA 4, 7, and 9 enclosure protection. Cast-iron enclosure features O-ring seals between housing and endplate, as well as endplate and motor. Class H coil insulation and built-in thermal protector prevent brake surface temperature from exceeding specified limits for hazardous locations.&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-power-transmission' target='_blank''&gt;Mechanical Power Transmission&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/disc-brakes-7780604-1.html' target='_blank''&gt;Disc Brakes&lt;/a&gt;  |  &lt;a href='http://www.thomasnet.com/products/electromechanical-brakes-7782501-1.html' target='_blank''&gt;Electromechanical Brakes&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Thu, 22 Aug 2002 08:31:29 -0400</pubDate>\n        </item>\n        <item>\n            <title>Electric Brakes are offered with steel housing.</title>\n            <link>http://news.thomasnet.com/fullstory/Electric-Brakes-are-offered-with-steel-housing-12361</link>\n            <description>Series 320 dyamic disc brakes come in 3 sizes. Size 1.2 has static torque rating of 3 lbs-in. and is available with mounting bolt circle of 2.5 or 2.62 in. Size 1.8 has static torque of 7 or 15 lb-in, and comes with 2.125 in. bolt circle as well as 3.5 in. bolt circle, with or without 2.5 in. register for 42C frame motors. Size 2.8, with 35 lb-in. static torque, is available with 3.5 in. bolt circle. Armature-actuated brake design is direct-acting, with 2 moving parts.&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-power-transmission' target='_blank''&gt;Mechanical Power Transmission&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/disc-brakes-7780604-1.html' target='_blank''&gt;Disc Brakes&lt;/a&gt;  |  &lt;a href='http://www.thomasnet.com/products/electromechanical-brakes-7782501-1.html' target='_blank''&gt;Electromechanical Brakes&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Wed, 24 Jul 2002 09:04:41 -0400</pubDate>\n        </item>\n        <item>\n            <title>Electric Disc Brakes never require adjustments.</title>\n            <link>http://news.thomasnet.com/fullstory/Electric-Disc-Brakes-never-require-adjustments-6872</link>\n            <description>Stearns 321 Series consists of 6 totally-enclosed, non-ventilated, armature-actuated electric disc brakes. They are available with static torque ratings of 3, 5, 7, 15, 35 and 50 lb-in. Brakes are designed for service in dirty or contaminated environments to decelerate or hold inertial loads when voltage to brake coil is disconnected. They are available in versions that will operate on 12, 24, 48, 90 and 180 VDC as well as 230 VAC.&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-power-transmission' target='_blank''&gt;Mechanical Power Transmission&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/disc-brakes-7780604-1.html' target='_blank''&gt;Disc Brakes&lt;/a&gt;  |  &lt;a href='http://www.thomasnet.com/products/electric-brakes-7781404-1.html' target='_blank''&gt;Electric Brakes&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Tue, 12 Feb 2002 07:54:51 -0400</pubDate>\n        </item>\n        <item>\n            <title>Metric Chain fits conveyor lines globally.</title>\n            <link>http://news.thomasnet.com/fullstory/Metric-Chain-fits-conveyor-lines-globally-6044</link>\n            <description>Metric 7705 MatTop metric chain is available in both molded-to-width (84.0 mm) and assembled-to-width (85.0 mm increments) constructions. Sprocket pockets are on 85.0 mm centers. Both versions have same chain height, share same sprockets, and are identifiable by orange TwistLock plugs.\n\n&lt;br&gt;&lt;br&gt;&lt;b&gt;This story is related to the following:&lt;/b&gt;&lt;br&gt;&lt;a href='http://news.thomasnet.com/news/mechanical-components-assemblies' target='_blank''&gt;Mechanical Components and Assemblies&lt;/a&gt;&lt;br&gt;&lt;br&gt;Search for suppliers of: &lt;a href='http://www.thomasnet.com/products/metric-chains-13310271-1.html' target='_blank''&gt;Metric Chains&lt;/a&gt;&lt;br&gt;</description>\n            <author>info@productnews.com (ThomasNet News)</author>\n            <pubDate>Fri, 11 Jan 2002 08:49:49 -0400</pubDate>\n        </item>\n    </channel>\n</rss>\n", message:undefined, modified:(new Date(1283740739061)), baseUri:"http://p3k.org/rss/", query:"textColor=#000000&align=&width=500&fontFace=&url=http://news.thomasnet.com/conewsxml/10043514&compact=&frameColor=black&showXmlButton=&setup=true&boxFillColor=white&_=1266198398777&titleBarColor=orange&maxItems=7&titleBarTextColor=black&", param:{textColor:"#000000", width:"500", align:"", fontFace:"", url:"http://news.thomasnet.com/conewsxml/10043514", frameColor:"black", compact:"", showXmlButton:"", setup:"true", boxFillColor:"white", _:"1266198398777", titleBarColor:"orange", maxItems:"7", titleBarTextColor:"black"}, 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();

