<?xml version="1.0" encoding="UTF-8" ?> 
<Module>

<ModulePrefs title="StockHouse" description="Keep up to date with StockHouse Editorials and SH@TheBell content." author="Ann-Marie Fleming" author_email="ann-marie.fleming@stockgroup.com" author_affiliation="StockGroup Inc." author_location="Vancouver, BC" screenshot="/widgets/igoogle/images/shscreen.png" thumbnail="/widgets/igoogle/images/shthumb.png" height="250" scrolling="false" singleton="false" title_url="http://www.stockhouse.com/shfn/thebell.asp">

  <Require feature="dynamic-height" /> 
  <Require feature="setprefs" /> 
  <Require feature="tabs" />
  <Require feature="analytics"/>
  </ModulePrefs>
  <UserPref name="feed1" display_name="feed 1" datatype="string" default_value="http://feed.stockhouse.com/?ge" /> 
  <UserPref name="feed2" display_name="feed 2" datatype="string" default_value="http://feed.stockhouse.com/?gb" /> 
  <UserPref name="entries" display_name="# of Entries" datatype="enum" default_value="10">
  <EnumValue value="3" /> 
  <EnumValue value="4" /> 
  <EnumValue value="5" /> 
  <EnumValue value="6" /> 
  </UserPref>
  <UserPref name="summaries" display_name="Summaries" datatype="enum" default_value="100">
  <EnumValue value="0" display_value="None" /> 
  <EnumValue value="100" display_value="Short" /> 
  <EnumValue value="300" display_value="Long" /> 
  </UserPref>
  <UserPref name="selectedTab" datatype="hidden" /> 
  <Content type="html">
  <![CDATA[ 
  <style type="text/css">
  /* Import tabs library style sheet */
  @import url(css/tablib.css);

  .statusLabel {
    font-size:12px;
    font-style:italic;
    padding-top:10px;
    text-align:center;
  }
  .feedHeader {
    padding-top:5px;
    font-size:12px;
  }
  .feedList {
    font-size:12px;
    margin:5px 0px 0px 0px;
    padding:0px 3px 5px 3px;
    border-top: 1px solid #aaaaaa;
    border-bottom: 1px solid #aaaaaa;
  }
  .feedList li {
    margin-top:5px;
    padding:0px;
  }
  .feedList div.entrySummary {
    font-size:11px;
  }
  .feedlist div.entryTimestamp {
    font-size:10px;
    font-style:italic;
    color:#676767;
  }
  </style>

  <script>
  // Global variables
  var prefs = new _IG_Prefs(__MODULE_ID__);
  var tabs = new _IG_Tabs(__MODULE_ID__);

  /**
   * Initialize tabs when page loads.
   * Create tab for each userpref only if userpref is not empty.
   */
  function init() {
    var f1 = _trim(prefs.getString("feed1"));
    var f2 = _trim(prefs.getString("feed2"));

    if (f1 != "") {
      tabs.addDynamicTab("SH Editorial", callbackGenerator(f1));
    }
    if (f2 != "") {
      tabs.addDynamicTab("SH@TheBell", callbackGenerator(f2));
    }

  };

  /**
   * Creates a function that calls the tab's callback function
   * and passes along an additional variable from the calling environment.
   */
  function callbackGenerator(feedUrl) {
    return function(tabId) {
      callbackTab(tabId, feedUrl);
    }
  }

  /**
   * Fetches an Atom or RSS feed and generates content inside the
   * selected tab's content container.  This function is called whenever
   * a tab is selected.
   */
  function callbackTab(tabId, feedUrl) {
    var summaries = prefs.getInt("summaries");
    var entries = prefs.getInt("entries");
    var container = _gel(tabId);

    // Display loading message before fetching feed.
    container.innerHTML = '<div class="statusLabel">Loading...</div>';

    // Fetch feed and return it as a JSON object.
    // Callback function is defined within local scope.
    _IG_FetchFeedAsJSON(
      feedUrl,
      function(feed) {
        if (typeof feed == "undefined" || typeof feed.Entry == "undefined") {
          container.innerHTML = '<div class="statusLabel">Invalid feed URL:<br>' + feedUrl + '</div>';
        } else {
          // Fetch feed successful.  Generate HTML content from returned JSON object.
          var html = new Array();

          // Create feed header containing title and description.
          html.push('<div class="feedHeader">');
          html.push('<b>' + _hesc(feed.Title) + '</b><br>');
          html.push(_hesc(feed.Description));
          html.push('</div>');

          // Iterate through each feed entry and generate list of content.
          html.push('<ul class="feedList">');
          for (var n = 0; n < feed.Entry.length; n++) {
            var entry = feed.Entry[n];
            html.push('<li>');
            html.push('<a target="_top" href="' + entry.Link + '">' + _hesc(entry.Title) + '</a>');
            if (typeof entry.Summary != "undefined" && entry.Summary != "") {
              html.push('<div class="entrySummary">' + _hesc(entry.Summary.substr(0, summaries)) + ' ...</div>');
            }
            if (!isNaN(entry.Date)) {
              html.push('<div class="entryTimestamp">' + new Date(entry.Date * 1000).toLocaleString() + '</div>');
            }
            html.push('</li>');
          }
          html.push('</ul>');
          container.innerHTML = html.join("");
        }

        // Resize iframe height to fit content.
        _IG_AdjustIFrameHeight();
      },
      entries,
      (summaries > 0)
    );
  }

  // Set onload event handler to call init()
  _IG_RegisterOnloadHandler(init);
  </script>
  
<script>
  _IG_Analytics("UA-1512590-13", "/Editorials and SH@TheBell");
</script>

  ]]> 
  </Content>
  </Module>