var kBlogFeed = 'http://tagneto.org/data/dsr/XmlCache?xmlUrl=' + encodeURIComponent('http://tagneto.blogspot.com/atom.xml');

function gId(id)
  {
  return document.getElementById(id);
  }
function altLinkFilter(element, index, array)
  {
  return element._a && element._a.rel && element._a.rel == 'alternate';
  }

function hideEntry(id)
  {
  gId('blogEntry' + id).style.display = 'none';
  gId('show' + id).style.display = 'inline';
  gId('hide' + id).style.display = 'none';
  }

function showEntry(id)
  {
  gId('blogEntry' + id).style.display = 'block';  
  gId('show' + id).style.display = 'none';
  gId('hide' + id).style.display = 'inline';
  }

var entryCounter = 0;

function formatBlogEntry(entry) { var result = new Array(); 
    if (!entry) return '';
    var currentLink = entry.link.filter(altLinkFilter)[0]._a.href;
    var timeStamp = entry.created._v.replace(/T.*/i, '');
    var entryId = entryCounter++;
    var content = entry.content._c ? entry.content._c : entry.content._v;
  result.push('\<');
result.push('div class="blogEntryTitle"\>');
result.push('\<');
result.push('a href="');
if (currentLink != null) result.push(currentLink);
 else result.push('');
result.push('"\>');
if (entry.title._v != null) result.push(entry.title._v);
 else result.push('');
result.push('\<');
result.push('/a\>');
result.push('\<');
result.push('br /\>');
result.push('\<');
result.push('i\>');
if (timeStamp != null) result.push(timeStamp);
 else result.push('');
result.push('\<');
result.push('/i\>');
result.push('&nbsp;&nbsp;&nbsp;\n    ');
result.push('\<');
result.push('span class="showHideButtons"\>');
result.push('\<');
result.push('a id="show');
if (entryId != null) result.push(entryId);
 else result.push('');
result.push('" class="showButton" href="javascript:showEntry(');
if (entryId != null) result.push(entryId);
 else result.push('');
result.push(')"\>');
result.push('Show');
result.push('\<');
result.push('/a\>');
result.push('\<');
result.push('a id="hide');
if (entryId != null) result.push(entryId);
 else result.push('');
result.push('" class="hideButton" href="javascript:hideEntry(');
if (entryId != null) result.push(entryId);
 else result.push('');
result.push(')"\>');
result.push('Hide');
result.push('\<');
result.push('/a\>');
result.push('\<');
result.push('/span\>');
result.push('\<');
result.push('/div\>');
result.push('\<');
result.push('div id="blogEntry');
if (entryId != null) result.push(entryId);
 else result.push('');
result.push('" class="blogEntryContent"\>');
result.push('\<');
result.push('div class="blogEntryText"\>');
if (SDom.serialize(content) != null) result.push(SDom.serialize(content));
 else result.push('');
result.push('\<');
result.push('/div\>');
result.push('\<');
result.push('div class="moreEntryDiv"\>');
result.push('\<');
result.push('a href="');
if (currentLink != null) result.push(currentLink);
 else result.push('');
result.push('"\>');
result.push('more...');
result.push('\<');
result.push('/a\>');
result.push('\<');
result.push('/div\>');
result.push('\<');
result.push('/div\>');
return result.join(''); }

function showBlogSummary(blogText)
  {
  var blogCell = gId('blogCell');
  blogCell.innerHTML = '<div id="blogSummaryHeader">Recent Blog Entries</div><div id="blogSummary">' + blogText + '</div>';
  }

function onOk(xmlString)
  {  
  var domParser = new DOMParser();
  var parsedDoc = domParser.parseFromString(xmlString, 'text/xml');
  Model = SDom.create(parsedDoc, 'feed');

  var result = '';
  if (Model && Model.entry && !Model.entry._sdNode)
    {
    //Limit the number of entries to 8 maximum.
    for (var index = 0; index < Model.entry.length &&  index < 8; index++)
      result += formatBlogEntry(Model.entry[index]);

    showBlogSummary(result);
    }
  }

//If get an error or timeout, just eat it.  Not critical to show the blog stuff.
var blogListener = { 'onLoad': onOk, 'onError': function(status, statusText, response){/*alert(status);*/}, 'onTimeout': function(){/*alert('timeout');*/}, 'timeout': 20 };
window.onload = function()
  {
  Dsr.send(kBlogFeed, blogListener);
  }
