﻿var pipeBlog = "erSr1hEe3BG424IrnkartA";
var pipeSleepmonsters = "sJiB6Rge3BGyhkPwEpPZnA";

var rssData;

function pageInit() {
   pipesInit([pipeBlog]);   
}

function pipesInitDone() {
   initLightbox();
}

function pipesInit(pipes) {
   for (var i=0; i<pipes.length; i++) {
      var requestId = pipesrpc.run(pipes[i], null, function(data) {
         rssData = data.value;
         if (rssData.items.length > 0) {
            // Set the first entry in the blog area
            blogEntry(0)
            // Set the list of headlines in the headline area
            blogHeadlines(rssData.items);
         }
      })
      //console.debug(requestId);
      pipesInitDone();
   }
}


function blogEntry(blogItemId) {
   
   var blogItem = rssData.items[blogItemId];
   document.getElementById("blogHeadline").innerHTML = blogItem.title;
   var blogHtml = "<h3>" + blogItem.published + " by " + blogItem.author.name + "</h3>" + "<p>" + scrubHTML(blogItem.description) + "</p>";   
   document.getElementById("blog").innerHTML = blogHtml;
}

function scrubHTML(html) {
   return html;
}


function blogHeadlines(blogItems) {
   var blogHeadlines = "";
   for (var i=0; i<blogItems.length; i++) {
      blogHeadlines += "<a onclick=\"blogEntry(" + i + ");\">" + blogItems[i].title + "</a><br/><br/>";
   }
   document.getElementById("blogHeadlines").innerHTML = blogHeadlines;
   
}
  

