<?xml version="1.0" encoding="UTF-8"?>
<!-- Video Feed - Version 1.0 - By T.N.Satish (tnsatish AT tnsatish DOT com)
	http://www.tnsatish.com/softwares/gadgets/videofeed.xml -->
<Module>
	<ModulePrefs title="Videos" directory_title="Videos" description="Watch Videos in the blogger. Customize the video size and number of videos. " author="T.N.Satish" author_email="tnsatish@tnsatish.com" author_affiliation="Loksatta, Open Source, ISKCON, Mangalagiri" author_location="Hyderabad, India" screenshot="http://www.tnsatish.com/softwares/gadgets/videofeed.png" height="250" scrolling="false" singleton="false">
  <Require feature="dynamic-height"/>
  <Require feature="setprefs"/>
  <Require feature="analytics"/>
</ModulePrefs>
<UserPref name="feed" display_name="Feed URL" datatype="string" default_value=""/>
<UserPref name="width" display_name="Video Width" datatype="string" default_value="212"/>
<UserPref name="height" display_name="Video Height" datatype="string" default_value="172"/>
<UserPref name="entries" display_name="# of Entries" datatype="enum" default_value="1">
  <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"/>
  <EnumValue value="10"/>
  <EnumValue value="11"/>
  <EnumValue value="12"/>
</UserPref>
<UserPref name="morevideos" display_name="Display Text at Bottom" datatype="string" default_value="More Videos"/>
<UserPref name="morevideoslink" display_name="URL for the above text" datatype="string" default_value=""/>
<Content type="html"><![CDATA[
  <style type="text/css">
  .statusLabel {
    font-size: 0.75em;
    font-style: italic;
    padding-top: 10px;
    text-align: center;
  }

  .feedList {
    font-size: 0.7em;
    margin: 0px;
    padding: 0px 0px 5px 0px;
    border-bottom: 1px solid #aaaaaa;
  }
  .feedList li {
    margin-top: 5px;
    padding: 3px 3px 0px 3px;
    border-top: 1px solid #aaaaaa;
  }
  .normaltext {
    font-size: 0.75em;
    text-align: center;
  }
  </style>

  <div id="content_div"></div>
  <script>
  // Global variables
  var prefs = new _IG_Prefs(__MODULE_ID__);
  var container = document.getElementById('content_div');

  /**
   * Initialize tabs when page loads.
   * Create tab for each userpref only if userpref is not empty.
   */
  function init() {
  	var feed = _trim(prefs.getString("feed"));
	if(feed != "") {
		populateFeed(feed);
	} else {
		container.innerHTML = '<div class="statusLabel">No feed found...</div>';
	}
  };

  /**
   * 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 populateFeed(feedUrl) {
    var entries = prefs.getInt("entries");
    var width = prefs.getInt("width");
    var height = prefs.getInt("height");
    var morevideos = _trim(prefs.getString("morevideos"));
    var morevideoslink = _trim(prefs.getString("morevideoslink"));

    // 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.
          // Create feed header containing title and description.
          var html = new Array();
          // 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="_blank" href="' + entry.Link + '"><b>' + _hesc(entry.Title) + '</b></a>');
	    if (typeof entry.Summary != "undefined" && entry.Summary != "") {
	      var vh = entry.Summary;
	      vh = vh.replace(/width="[0-9]*"/g, 'width="' + width + '"');
	      vh = vh.replace(/height="[0-9]*"/g, 'height="' + height + '"');

              var summary = document.createElement("div");
              summary.innerHTML = vh;
              html.push('<div class="entrySummary">');
              html.push(summary.innerHTML);
              html.push('</div>');
            }
            html.push('</li>');
          }
          html.push('</ul><br>');
	  html.push('<div class="normaltext">');
	  html.push('<a target="_blank" href="' + morevideoslink + '"><b>' + morevideos + '</b></a>');
	  html.push('</div>');
          container.innerHTML = html.join("");
        }

        // Resize iframe height to fit content.
        _IG_AdjustIFrameHeight();
      },
      entries,
      true
    );
  }

  // Set onload event handler to call init()
  _IG_RegisterOnloadHandler(init);
  _IG_Analytics("UA-3416025-12", "/videofeed");
  </script>
]]>
</Content>
</Module>


