<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs
    title="WiredBerries"
    title_url="http://www.wiredberries.com/"
    directory_title="WiredBerries - The Daily Network for Healthy Living"
    description="WiredBerries, the network for healthy living, offers up-to-the-minute daily advice on food, nutrition, fitness, natural beauty, diet, and women's health and wellness."
    author="WiredBerries"
    author_email="igoogle_gadgets@ljmsite.com"
    author_location="Huntsville, AL, USA"
    author_affiliation="None"
    screenshot="http://www.ljmsite.com/google/gadgets/wiredberries/wiredberries_screenshot.png"
    thumbnail="http://www.ljmsite.com/google/gadgets/wiredberries/wiredberries_thumbnail.png"
    height="250">
    <Require feature="analytics"/>
    <Require feature="dynamic-height"/>
    <Require feature="setprefs"/>
    <Require feature="minimessage"/>
  </ModulePrefs>
  <UserPref name="beauty"  display_name="Natural Beauty"       datatype="bool" default_value="true"/>
  <UserPref name="dating"  display_name="Dating Life"          datatype="hidden" default_value="false"/>
  <UserPref name="radio"   display_name="Radio"                datatype="bool" default_value="true"/>
  <UserPref name="flash"   display_name="Flash!"               datatype="bool" default_value="true"/>
  <UserPref name="food"    display_name="Food &amp; Nutrition" datatype="bool" default_value="true"/>
  <UserPref name="fitness" display_name="Fitness"              datatype="bool" default_value="true"/>
  <UserPref name="organic" display_name="Organic Living"       datatype="bool" default_value="true"/>
  <Content type="html">  
<![CDATA[

<style type="text/css">
* {
        font-family:Arial,Helvetica,sans-serif;
        font-weight:bold;
        text-align:left;
        vertical-align:middle;
        font-size:13;
        color:#000000;
        background-color:#dad2c3;
}

a.title, a.title:link, a.title:visited {
        color:#1772a5;
        text-decoration:none;
}

a.title:hover {
        color:#1772a5;
        text-decoration:underline;
}

a.category, a.category:link, a.category:visited, a.category:hover {
        color:#514246;
        font-size:10;
        text-decoration:none;
}


img {
        border: solid 1px #514246;
}

</style>

<div id="content__MODULE_ID__" />

<script type="text/javascript">

// Global variables to track the success of data fetching
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__(storyTitle, storyURL, imageURL, imageWidth, categoryTitle, categoryURL) {
        var storyHtml = '<tr><td><a href="' + storyURL + '" target="_blank">'
                      + '<img src="' + imageURL + '" width="' + imageWidth + '" alt="' + storyTitle + '" /></a></td>'
                      + '<td><a href="' + categoryURL + '" target="_blank" class="category">' + categoryTitle + '</a>'
                      + '<br/><a href="' + storyURL + '" target="_blank" class="title">' + storyTitle + '</a>'
                      + '</td></tr>';

        return storyHtml;
}

function displayStories__MODULE_ID__(pageHtml) {
        var storiesHtml = '<table border=0>';
        var prefs = new _IG_Prefs();

        // 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 story list in an array, one entry per array element
        var entries = pageHtml.split('\n');

        for(var i = 0; i < entries.length - 1; i++) {
                // Separate each fields in the data feed
                var fields     = entries[i].split('#@|');
                var category      = fields[0];
                var categoryTitle = fields[1];
                var categoryURL   = fields[2];
                var storyTitle    = fields[3];
                var storyURL      = fields[4];
                var imageURL      = _IG_GetImageUrl(fields[5]);

                if(prefs.getBool(category)) {
                        storiesHtml += getHtmlOneStory__MODULE_ID__(storyTitle, storyURL, imageURL, imageWidth, categoryTitle, categoryURL);
                }
        }

        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);
	setTimeout('_IG_AdjustIFrameHeight()', 10000);
        _IG_AdjustIFrameHeight();

        return;
}

// Top level fetcher which initiate the assynchronous function
function fetchStories__MODULE_ID__() {
        //_IG_FetchContent('http://www.ljmsite.com/google/gadgets/wiredberries/stories.lst', function (response) {
        _IG_FetchContent('http://gadgets.ljmsite.com/wiredberries/stories.lst', 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-3145497-1", "/WiredBerries-iGoogleGadget/1");
        setTimeout('_IG_Analytics("UA-1189083-1", "/WiredBerries/1")', 10000);
        return;
}

_IG_RegisterOnloadHandler(init__MODULE_ID__);

</script>

]]> 
  </Content>
</Module>
