<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs  
    title="The Galactic Emporium"
    title_url="http://www.galacticemporium.net/"
    directory_title="The Galactic Emporium - Gadgets Gizmos Games"
    description="The web's first science, space and technology-focused gadget and gaming blog, The Galactic Emporium reviews online video games, SciFi and astronomy products, software, and  science-focused consumer electronics."
    screenshot="http://www.ljmsite.com/google/gadgets/galacticemporium/galacticemporium_screenshot.png"
    thumbnail="http://www.ljmsite.com/google/gadgets/galacticemporium/galacticemporium_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('Galactic Emporium') != -1) ||
	   (title.indexOf('Create Your Own') != -1) ||
           (title.indexOf('Sign Up for Our') != -1)) {
                return true;
        }
        return false;
}

function displayStories__MODULE_ID__(pageHtml) {
        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;
        }

	// Split the html in an array, one entry per array element
	var entries = pageHtml.split('<div class="entry" id="');

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

		// Here we go with the HTML content scrapping... This is not pretty!

		// Find the title
		var title = getSubstring__MODULE_ID__(entries[i], '<h3 class="entry-header">', '</h3>');
		title = getSubstring__MODULE_ID__(title, '>', '<');
		title = title.replace(/"/g, '&quot;');

                // If the option to filter non-stories is on and the post is not a story, skip
                if(__UP_storyfilter__ && storyFilter__MODULE_ID__(title)) {
                        continue;
                }

                // Find the URL of the story image for the thumbnail
		var imageTag = getSubstring__MODULE_ID__(entries[i], '<img ', '>');
		var imageUrl = '';	
		if(imageTag && (imageTag.indexOf('delicious.gif') == -1)) {
                	imageUrl = getSubstring__MODULE_ID__(imageTag, 'src="', '"');
		}
		// Use a default thumbnail instead if no picture has been found
                if(!imageUrl) {
                        imageUrl = 'http://www.ljmsite.com/google/gadgets/dailygalaxy/bestoff.jpg';
                }
                // Get the image cached at Google
		imageUrl = _IG_GetImageUrl(imageUrl);

		// Find the permanent story link
		var link = getSubstring__MODULE_ID__(entries[i], '<a class="permalink" href="', '"');

                storiesHtml += getHtmlOneStory__MODULE_ID__(title, link, imageUrl, imageWidth);
                
                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_FetchContent('http://www.galacticemporium.net/', function (response) {
                if (!response) {
                        _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;
	}, {refreshInterval: 1800}); // Cache for 30 minutes
}

// Wrapper to the fetchStories function which manage the retries
// every 10 seconds in case _IG_FetchContent() 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-2", "/iGoogleGadget/1");
        setTimeout('_IG_Analytics("UA-1189083-1", "/GalacticEmporium/1")', 10000);
        return;
}

_IG_RegisterOnloadHandler(init__MODULE_ID__);

</script>

]]> 
  </Content>
</Module>
