 <?xml version="1.0" encoding="UTF-8"?>

<Module>
  <ModulePrefs  
    title="ShadowUnit Gadget" 
    title_url="http://www.shadowunit.org/">
  <Require feature='dynamic-height'/>
  </ModulePrefs>  
  <UserPref name="show_date" display_name="Show Dates?" datatype="bool" default_value="true"/>
  <UserPref name="show_summ" display_name="Show Summaries?" datatype="bool" default_value="true"/>
  <UserPref name="num_entries" display_name="Number of Entries:" default_value="5"/>

  <Content type="html">
  <![CDATA[ 
    <style type="text/css">
    /* Import tabs library style sheet */
    @import url(http://www.shadowunit.org/stylesheets/shadow2.css);

    #content{
      background-color: rgb( 192, 192, 192);    
    }    
    
    </style>
    <div id="shadowgadget">
    </div>     
    <script type="text/javascript">

     // Get userprefs
     var prefs = new _IG_Prefs();
     var showdate = prefs.getBool("show_date");
     var summary = prefs.getBool("show_summ");
     var entries = prefs.getInt("num_entries");
     var w = document.getElementById("shadowgadget").offsetWidth;
       
     // If user wants to display more than 100 entries, display an error
     // and set the value to 100, the max allowed.
     if (entries > 100)
     {
         alert("You cannot display more than 100 entries.");
         entries = 100;
     }

     // Use the _IG_FetchFeedAsJSON() function to retrieve core feed data from
     // the specified URL. Then combine the data with HTML markup for display in
     // the gadget.
     _IG_FetchFeedAsJSON("http://www.shadowunit.org/ShadowFeed.xml",
              function(feed) { 
              if (feed == null){ 
                 alert("There is no data.");
                 return;
              }
     
         // Start building HTML string that will be displayed in gadget.
         var html = "<img src='http://www.shadowunit.org/images/suban.jpg' alt='Shadow Unit' width='"+w+"'></img>";
         html += "<div id='container'>";
         html += "<div id='content'>";
         //html += "<div id='header'></div>";

         // Access the fields in the feed
         html += "<p><strong>" + feed.Title + "</strong>:";
         html += " " + feed.Description + "</p>";
     
          html += "<dl>"
         // Access the data for a given entry
         if (feed.Entry) {
             for (var i = 0; i < feed.Entry.length; i++) {
                 html += "<dt><a target='_blank' href='" + feed.Entry[i].Link + "'>"
                 + feed.Entry[i].Title
                 + "</a></dt><dd>";
                 if (showdate==true)
                 { 
                     // The feed entry Date field contains the timestamp in seconds
                     // since Jan. 1, 1970. To convert it to the milliseconds needed
                     // to initialize the JavaScript Date object with the correct date, 
                     // multiply by 1000.
                     var milliseconds = (feed.Entry[i].Date) * 1000; 
                     var date = new Date(milliseconds); 
                     html += "<strong>"
                     html += date.toLocaleDateString();
                     html += " ";
                     html += date.toLocaleTimeString(); 
                     html += "</strong>";
                 } 
                 if (summary==true) { 
                     html += "<br><em>" + feed.Entry[i].Summary + "</em>";
                 }
                 html += "</dd>";
             }
         }
     html += "</dl>";
     //html += "<div id='footer'></div>";
     html += "</div>";
     html += "</div>";
     _gel("shadowgadget").innerHTML = html;

      // Fix the height
      _IG_AdjustIFrameHeight();
       
     // The rest of the function parameters, which are optional: the number
     // of entries to return, and whether to return summaries.
     }, entries, summary);
    
  </script>

  ]]> 
  </Content>
</Module>
