﻿var pipeMedia = "JiEg65gi3BGDOUWjy6ky6g";
//<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/81ub3Ry152k"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/81ub3Ry152k" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>


var rssData;

function pageInit() {
//   pipesInit([pipeMedia]);   // disabled by FAR on location during the race
   initLightbox();
}

function pipesInitDone() {
   initLightbox();
}

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




function showTeamPictures() {
   alert("Please be patient.  We should have the team pictures available within the next 24 hours.");
}

function showRacePictures() {

}

function blogEntry(blogItemId) {
   var blogItem = rssData.items[blogItemId];
   var d = new Date(blogItem.published);
   var blogHtml = "";
   
   if (blogItem.far_flickrLink != null)
   {
      if (blogItem.far_tags.toLowerCase().search("rtnx") > -1 && blogItem.far_tags.toLowerCase().search("2007") > -1)
      {
         blogHtml += "<a href=\"http://farm" + blogItem.farm + ".static.flickr.com/" + blogItem.server + "/" + blogItem.id + "_" + blogItem.secret + ".jpg\"" + "\" rel=\"lightbox\"><img src=\"" + blogItem.far_thumbnail + "\"/></a>" +
            "<p>" + blogItem.title + "</p>";

      }
      else
      {
         //blogHtml += "<h3>" + blogItem.title + "</h3><a href=\"http://farm" + blogItem.farm + ".static.flickr.com/" + blogItem.server + "/" + blogItem.id + "_" + blogItem.secret + ".jpg\"" + "\" rel=\"lightbox\"><img src=\"" + blogItem.far_thumbnail + "\"/></a>";   
      }
         
      
      
   }
   else if (blogItem.far_youTubeLink != null)
   {
      if (blogItem.far_tags.toLowerCase().search("rtnx") > -1 && blogItem.far_tags.toLowerCase().search("2007") > -1)
      {
      //<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/81ub3Ry152k"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/81ub3Ry152k" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
         blogHtml += "<a href=\"" + blogItem.far_youTubeLink + "\"><img src=\"" + blogItem.far_thumbnail + "\"/></a>";   
      }
   }
 
   return blogHtml;
}