// JavaScript Document
// Original from Digg.com modified by Sean Hayes

// Upcoming Digg callback 
function diggwbu(obj) {
   if (!jQuery) setTimeout(function() { diggwb(obj); }, 200); //hack for IE not loading scripts that are included via document.write until it decides too
   jQuery('#digg-upcoming-container ul').html('');
   if(!obj) {
      jQuery('#digg-upcoming-container ul').html('We were unable to retrieve matching stories from Digg. Please refresh the page to try again.');
   }
   if(!obj.stories || obj.stories.length == 0) {
      jQuery('#digg-upcoming-container ul').html('Currently, there are no recent stories of this type on Digg.');
   }
   if (obj.stories) {
      var html, s;
      for (var i = 0 ; i < obj.stories.length ; i++) {
         s = obj.stories[i];
         if(s.diggs > 10000) {
            s.diggs = Math.floor(s.diggs/1000)+'K+';
         }
         if (s.thumbnail == undefined) {
            html =
                  '<li><a href="' + s.href + '?OTC-widget" class="digg-count">' + s.diggs + ' <span>diggs</span></a>' +
                  '<h3><a href="' + s.href + '?OTC-widget">' +  s.title + '</a></h3>';
         } else {
            html =
                  '<li><a href="' + s.href + '?OTC-widget" class="digg-count">' + s.diggs + ' <span>diggs</span></a>' +
                  
                  '<h3><a href="' + s.href + '?OTC-widget">' +  s.title + '</a></h3>';
         }
         jQuery('#digg-upcoming-container ul').append(html);
      }
   }
}

// Popular Digg callback
function diggwb(obj) {
   if (!jQuery) setTimeout(function() { diggwb(obj); }, 200); //hack for IE not loading scripts that are included via document.write until it decides too
   jQuery('#digg-popular-container ul').html('');

   if(!obj) {
      jQuery('#digg-popular-container ul').html('We were unable to retrieve matching stories from Digg. Please refresh the page to try again.');
   }
   if(!obj.stories || obj.stories.length == 0) {
      jQuery('#digg-popular-container ul').html('Currently, there are no recent stories of this type on Digg.');
   }
   if (obj.stories) {
      var html, s;
      for (var i = 0 ; i < obj.stories.length ; i++) {
         s = obj.stories[i];
         if(s.diggs > 10000) {
            s.diggs = Math.floor(s.diggs/1000)+'K+';
         }
         if (s.thumbnail == undefined) {
            html =
                  '<li><a href="' + s.href + '?OTC-widget" class="digg-count">' + s.diggs + ' <span>diggs</span></a>' +
                  '<h3><a href="' + s.href + '?OTC-widget">' +  s.title + '</a></h3>';
         } else {
            html =
                  '<li><a href="' + s.href + '?OTC-widget" class="digg-count">' + s.diggs + ' <span>diggs</span></a>' +
                  
                  '<h3><a href="' + s.href + '?OTC-widget">' +  s.title + '</a></h3>';
         }
         jQuery('#digg-popular-container ul').append(html);
      }
   }
}
