<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <!-- Fetch the current content at the Astronomy Picture of the Day site
       (http://antwrp.gsfc.nasa.gov/apod/astropix.html). Display the lower-res
       version of the image in a div, with the image being allowed 80% width
       (via CSS) and the browser setting the height to maintain aspect ratio.
       Then add the photo-credits info from page just under the image. The
       image is a link to the high-res version, and the applet title is linked
       to the APOD page itself. -->
  <ModulePrefs title="Astronomy Pic of the Day" render_inline="optional"
      author="Randy J. Ray" author_email="randy.j.ray+apod@gmail.com"
      title_url="http://antwrp.gsfc.nasa.gov/apod/astropix.html"
      directory_title="Astronomy Picture of the Day"
      screenshot="http://www.blackperl.com/xml/google/apod/apod-ss.jpg"
      author_location="Campbell, CA" author_affiliation="www.rjray.org" />
  <Content type="html"><![CDATA[
    <div id="apod___MODULE_ID__"></div>
    <script type="text/javascript">
var APOD___MODULE_ID___url = "http://antwrp.gsfc.nasa.gov/apod/astropix.html";
var APOD___MODULE_ID___base = "http://antwrp.gsfc.nasa.gov/apod/";

function APOD___MODULE_ID___init() {
    _IG_FetchContent(APOD___MODULE_ID___url, function(content) {

    var re = /<center>(.*?)<\/center>/g;
    var centerBlocks;
    var htmlText = '<div><p><a href="' +
        APOD___MODULE_ID___url + '">APOD page could not be parsed.</a></p></div>';

    content = content.replace(/\n/g, " ");
    centerBlocks = content.match(re);
    if (centerBlocks != null) {
        // I could have probably done this with the original regexp, but this
        // is a whole lot easier to read.
        var imgLink;
        var imgUrl;
        var result;

        result = centerBlocks[0].match(/href="(image.*?)"/);
        if (result != null) {
            imgLink = result[1];
        }
        result = centerBlocks[0].match(/IMG SRC="(image.*?)"/);
        if (result != null) {
            imgUrl = result[1];
        }
        if ((imgUrl.length > 0) && (imgLink.length > 0)) {
            var creditText = centerBlocks[1].match(/<center>(.*?)<\/center>/);
            htmlText = '<div><div style="padding: 3px; text-align: center">' +
                '<a href="' +
                APOD___MODULE_ID___base + imgLink + '"><img src="' +
                APOD___MODULE_ID___base + imgUrl + '" style="width: 80%" ' +
                'title="Click for full-size image" alt="APOD image" /></a>' +
                '</div><div style="text-align: center">' + creditText[1] +
                '</div>';
        }
    }

    _gel("apod___MODULE_ID__").innerHTML = htmlText; });
}

_IG_RegisterOnloadHandler(APOD___MODULE_ID___init);
    </script>
]]>
  </Content>
</Module>
