<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="GFCTimeElapse" scrolling="true">
    <Require feature="settitle"/>
    <Require feature="dynamic-height"/>
    <Require feature="views" />   
    <Require feature="opensocial-0.7" />   
  </ModulePrefs>
  <Content type="html"><![CDATA[
    <style type="text/css">
      .mytable td {padding: 2px;}
      .mytable tr {padding: 1px;}
      .mytable {border: 1px solid #004400;}
    </style>
     
    <!-- Change to local path for testing -->
    <script src="http://hosting.gmodules.com/ig/gadgets/file/103169497864651487485/SocialNorms.js"></script>
    <script type="text/javascript">
      gadgets.window.setTitle('Time Elapse');
      var impl = {
        render: function(data) {
          var viewer = data.getViewer();
          var allPeople = data.getOwnerFriends().asArray() || [];
          if(viewer) {
            allPeople.push(viewer);
            var viewerData = data.getDataFor(viewer.getId());
            score = scoreOf(viewerData);
            score++;
            SocialNorms.setPersonData('VIEWER', 'Score', score, function() {
              theApp.resendInitialRequest();
            });
          }
        
          var leaders = allPeople.sort(function(friend1, friend2) {
              return scoreOf(data.getDataFor(friend2)) - scoreOf(data.getDataFor(friend1));
          });

          var ownersite = gup('communityId');
          var refers = document.referrer.split('/');
          var domain = 'http://' + refers[2];

          var html = '<table class="mytable" width="100%">';
          html += '<tr><td colspan="2"><b>Time Elapse</b></td></tr>';
          var lmax = leaders.length;
          if (lmax > 10) lmax = 10;
          for (var i = 0; i < lmax; i++) {
            if (scoreOf(data.getDataFor(leaders[i])) > 0) {
              var j = i + 1;
              if (data.getDataFor(leaders[i]) != data.getDataFor(leaders[j])) {
              html += '<tr><td>';
              html += '<img src="' + leaders[i].getField(opensocial.Person.Field.THUMBNAIL_URL) + '" height="36" width="36"></td>';
             html += '<td valign="top"><a href="' + domain + '/canvas.html?site=' + ownersite + '&profileId=' + leaders[i].getId() + '" target="_TOP">';
              html += leaders[i].getDisplayName() + '</a><br />';
              var hrs = scoreOf(data.getDataFor(leaders[i])) / 3600;
              hrs = parseInt(hrs);
              var mins = scoreOf(data.getDataFor(leaders[i])) / 60 - hrs * 60;
              mins = parseInt(mins);
              var secs = scoreOf(data.getDataFor(leaders[i])) - mins * 60 - hrs * 3600;
              if (hrs > 0) {
                html += hrs + ' h ';
              }
              if (mins > 0) {
                html += mins + ' m ';
              }
              html += secs + ' s</td></tr>';
            }
            }
          }
          html += '</table>';

          _gel('highscores').innerHTML = html;
          gadgets.window.adjustHeight();
        }
      }
  
      function scoreOf(data) {
        return data['Score'] ? Number(data['Score']) : 0;
      }

      function gup(name) {
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );
        if (results == null)
          return "";
        else
          return results[1];
      }
  
      SocialNorms.createSocialAppOnLoad(impl, 'OWNER', ['Score']);
    </script>
             
    <div id="highscores" style="margin: 4px">
    </div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {     
var pageTracker = _gat._getTracker("UA-6631483-1");
pageTracker._trackPageview();
} catch(err) {}</script>

<STYLE>
A.at_adv_here_29074, A.at_pow_by_29074 {font-family: Arial,Sans-Serif; font-size: 5px; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; color: #00
0099; text-decoration: none; }
A.at_adv_here_29074:hover, A.at_pow_by_29074:hover { color: #0000FF; text-decoration: underline; }
</STYLE>
<SCRIPT type="text/javascript">
adtoll_see_your_ad_here = 0;
adtoll_your_text = "";
adtoll_show_powered_by = 0;
adtoll_auto_play = "N";
</SCRIPT>
<SCRIPT src="http://adserve.adtoll.com/js/at_ag_29074.js" type="text/javascript"></SCRIPT>

<STYLE>
A.at_adv_here_29195, A.at_pow_by_29195 {font-family: Arial,Sans-Serif; font-size: 10px; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; color: #000099; text-decoration: none; }
A.at_adv_here_29195:hover, A.at_pow_by_29195:hover { color: #0000FF; text-decoration: underline; }
</STYLE>
<SCRIPT type="text/javascript">
adtoll_see_your_ad_here = 0;
adtoll_your_text = "";
adtoll_show_powered_by = 0;
adtoll_auto_play = "";
</SCRIPT>
<SCRIPT src="http://adserve.adtoll.com/js/at_ag_29195.js" type="text/javascript"></SCRIPT>

  ]]>
  </Content>
</Module>
