<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs  
    title="The Daily Galaxy"
    title_url="http://www.dailygalaxy.com/"
    directory_title="The Daily Galaxy - News from Planet Earth and Beyond"
    description="Fascinating news and original insights on science, space exploration, technology, climate change, and their reflections in popular culture (film, books, events)."
    screenshot="http://www.ljmsite.com/google/gadgets/dailygalaxy/dailygalaxy_screenshot.png"
    thumbnail="http://www.ljmsite.com/google/gadgets/dailygalaxy/dailygalaxy_thumbnail.png"
    author="Jerome Mouton"
    author_email="igoogle_gadgets@ljmsite.com"
    author_location="Huntsville, AL, USA"
    author_affiliation="LjmSite"
    author_aboutme="Google API gadget and web application developer, tech project manager in globally dispersed team environment, computer geek on call, etc. Come check me out at LjmSite.com and contact me to discuss gadget projects or opportunities."
    author_link="http://www.ljmsite.com/"
    author_photo="http://www.ljmsite.com/google/gadgets/jerome.png"
    singleton="false"
    height="300">
    <Require feature="analytics"/>
    <Require feature="dynamic-height"/>
    <Require feature="setprefs"/>
  </ModulePrefs>
  <UserPref name="nbstories" display_name="Number of stories" datatype="enum" default_value="5">
    <EnumValue value="1"/>
    <EnumValue value="2"/>
    <EnumValue value="3"/>
    <EnumValue value="4"/>
    <EnumValue value="5"/>
    <EnumValue value="6"/>
    <EnumValue value="7"/>
    <EnumValue value="8"/>
    <EnumValue value="9"/>
  </UserPref>
  <UserPref name="fontsize" display_name="Text size" datatype="enum" default_value="14px">
    <EnumValue value="11px" display_value="Small" />
    <EnumValue value="14px" display_value="Medium" />
    <EnumValue value="17px" display_value="Large" />
  </UserPref>
  <UserPref name="storyfilter" display_name="Only stories" datatype="bool" default_value="true"/>
  <Content type="html">  
<![CDATA[

<style type="text/css">
* {
        font-family:Arial,Helvetica,sans-serif;
        text-align:left;
        vertical-align:middle;
        font-size:__UP_fontsize__;
        color:#000000;
        background-color:#ffffff;
}
a {
        color:#0000bb;
        text-align:right;
        text-decoration:none;
        background-color:#ffffff;
}
a:link {
        color:#0000bb;
        text-align:right;
        text-decoration:none;
        background-color:#ffffff;
}
a:visited {
        color:#0000bb;
        text-align:right;
        text-decoration:none;
        background-color:#ffffff;
}
a:hover {
        color:#0000bb;
        text-align:right;
        text-decoration:underline;
        background-color:#ffffff;
}
</style>

<div id="content__MODULE_ID__" />

<script type="text/javascript">

// Global variables to track the success of fetching the feed
var fetchSuccessfull__MODULE_ID__ = false;

function getSubstring__MODULE_ID__(data, pre, post) {
        var val = '';
        var start = data.indexOf(pre);
        if(start != -1) {
                start += pre.length;
                var data2 = data.substring(start);
                var end = data2.indexOf(post);
                if(end != -1) {
                        val = data2.substring(0, end);
                }
        }
        return val;
}

function getWidth__MODULE_ID__() {
        var w;
        if(self.innerHeight) {
                w = self.innerWidth;
        }
        else if(document.documentElement && document.documentElement.clientHeight) {
                w = document.documentElement.clientWidth;
        }
        else if(document.body) {
                w = document.body.clientWidth;
        }
        return w;
}

function getHtmlOneStory__MODULE_ID__(title, url, imageUrl, imageWidth) {
        var storyHtml = '<tr><td><a href="' + url + '" target="_blank">'
                      + '<img src="' + imageUrl + '" border="0" width="' + imageWidth + '" alt="' + title + '" />'
                      + '</a></td><td><a href="' + url + '" target="_blank">' + title + '</a></td></tr>';

        return storyHtml;
}

function storyFilter__MODULE_ID__(title) {
        if((title.indexOf('Daily Galaxy') != -1) ||
	   (title.indexOf('Create Your Own') != -1) ||
           (title.indexOf('Grab the New "Galaxy"') != -1) ||
           (title.indexOf('Announcing "GalaxyExtra!"') != -1) ||
           (title.indexOf('Sign Up for Our') != -1)) {
                return true;
        }
        return false;
}

function displayStories__MODULE_ID__(feed) {
        var storiesHtml = '<table border=0>';

        // Set the thumbnail size to 1/3 of the gadget width, but no bigger than 70 pixels
        var imageWidth = getWidth__MODULE_ID__() / 3;
        if(imageWidth > 70) {
                imageWidth = 70;
        }

        var storyId = 0;
        for(var i = 0; (i < feed.Entry.length) && (storyId < __UP_nbstories__); i++) {

                // If the option to filter non-stories is on and the post is not a story, skip
                if(__UP_storyfilter__ && storyFilter__MODULE_ID__(feed.Entry[i].Title)) {
                        continue;
                }

                // Find the URL of the story image for the thumbnail
                var imageUrl = getSubstring__MODULE_ID__(feed.Entry[i].Summary, 'src="', '"');
                // The 'Best of' posts do not have a good thumbnail, so use a default one instead
                if((imageUrl == '') || feed.Entry[i].Title.indexOf('Best of The Daily Galaxy') != -1) {
                        imageUrl = 'http://www.ljmsite.com/google/gadgets/dailygalaxy/bestoff.jpg';
                }
                // Get the image cached at Google
// 200808015 Disabled the caching as pictures were no longer showing
                //imageUrl = _IG_GetImageUrl(imageUrl);

		var title = feed.Entry[i].Title.replace(/"/g, '&quot;');

                storiesHtml += getHtmlOneStory__MODULE_ID__(title, feed.Entry[i].Link, imageUrl, imageWidth);
                
                /* Story date processing...
                var milliseconds = (feed.Entry[i].Date) * 1000;
                var date = new Date(milliseconds);
                var htmlDate = date.toLocaleDateString();
                htmlDate += " ";
                htmlDate += date.toLocaleTimeString();
                */
                
                storyId++;
        }

        storiesHtml += '</table>';
        _gel("content__MODULE_ID__").innerHTML = storiesHtml;

        // Adjust height but do it again in 5 seconds in case some image are slow to come
        setTimeout('_IG_AdjustIFrameHeight()', 5000);
        _IG_AdjustIFrameHeight();

        return;
}

// Top level fetcher which initiate the assynchronous function
function fetchStories__MODULE_ID__() {
	_IG_FetchFeedAsJSON('http://www.dailygalaxy.com/my_weblog/atom.xml', function (response) {
        //_IG_FetchFeedAsJSON('http://www.dailygalaxy.com/my_weblog/rss.xml', function (response) {
	//_IG_FetchFeedAsJSON('http://www.ljmsite.com/google/gadgets/tests/test_atom_fixed2.xml', function (response) {
                if (response == null || response.Entry == null) {
                        _gel("content__MODULE_ID__").innerHTML = "<i>Error fetching data.<br />Stand by as we retry...</i>";
                }
                else {
                        fetchSuccessfull__MODULE_ID__ = true;
                        displayStories__MODULE_ID__(response);
                }
                return;
        }, __UP_nbstories__ + 5, true);
        //  Specifying the max caching time is not supported yet for Feeds by iGoogle
}

// Wrapper to the fetchStories function which manage the retries
// every 10 seconds in case _IG_FetchFeedAsJSON() fails
function fetchStoriesWrapper__MODULE_ID__() {
        if(!fetchSuccessfull__MODULE_ID__) {
                fetchStories__MODULE_ID__();
                setTimeout('fetchStoriesWrapper__MODULE_ID__()',10000);
        }
        return;
}

function init__MODULE_ID__() {
        _gel("content__MODULE_ID__").innerHTML = "<i>Getting latest stories...</i>";
        fetchStoriesWrapper__MODULE_ID__();
        _IG_Analytics("UA-2959282-1", "/iGoogleGadget/1");
	setTimeout('_IG_Analytics("UA-1189083-1", "/DailyGalaxy/1")', 10000);
        return;
}

_IG_RegisterOnloadHandler(init__MODULE_ID__);

</script>

]]> 
  </Content>
</Module>
