 // Copyright 2009 Google Inc.  All Rights Reserved.

/**
 * @fileoverview Javascript file to display press podium listings.
 * Requires use of Spreadsheets feed wrapper (http://www.google.com/js/feed.js).
 *
 * @author dave carlsson
 */

/**
 * Namespace for press website.
 * @type {Object}
 */
var press = press || {};

/**
 * HTML DIV to hold generated HTML content.
 * @const
 * @type {string}
 */
press.PODIUM_CONTAINER_ID = 'gp-podium-container';

/**
 * Text to display on the HTML page for links to video content.
 * @const
 * @type {string}
 */
press.VIDEO_LINK_TEXT = 'Video';

/**
 * Text to display on the HTML page for links to transcripts.
 * @const
 * @type {string}
 */
press.TRANSCRIPT_LINK_TEXT = 'Transcript';

/**
 * The ATOM feed URI for the Spreadsheet that holds the data to be converted
 * to an HTML object to display to the user.
 * This is parsed in press.createHTMLObject.
 * @type {string}
 */
press.feedUrl = 'http://spreadsheets.google.com/feeds/list/' +
    'te-jpzya0K4aXyOD_mAGpFg/od6/public/basic';

/**
 * Takes the content of a Spreadsheet and produces HTML content from the data.
 * @param {Object} feedData The content of the Spreadsheets feed, parsed by
 *     the feed wrapper.
 */
press.createHTMLContent = function(feedData) {
  var htmlContent = '';

  for (var i = 0, row; row = feedData[i]; i++) {
    if (i % 2 === 0) {
      htmlContent += '<div class="gp-podium-event-container ' +
          'gp-podium-event-container-alternate">';
    } else {
      htmlContent += '<div class="gp-podium-event-container">';
    }

    htmlContent += '<h4><span class="gp-podium-date">' + row['date'] +
        '</span>; <span class="gp-podium-event-title">' + row['rowTitle'] +
        '</span>; <span class="gp-podium-location">' + row['location'] +
        '</span></h4>' +
        '<p><span class="gp-podium-description">' + row['description'] +
        '</span><span class="gp-podium-presenter"> (' + row['presenter'] +
        ')</span></p>';

    if (row['videolink']) {
      htmlContent += '<span class="gp-podium-video"><a href="' +
          row['videolink'] + '">' + press.VIDEO_LINK_TEXT + '</a></span>';
    }

    if (row['transcriptlink']) {
      htmlContent += ' <span class="gp-podium-video"><a href="' +
          row['transcriptlink'] + '">' + press.TRANSCRIPT_LINK_TEXT +
          '</a></span>';
    }

    htmlContent += '</div>';
  }

  document.getElementById(press.PODIUM_CONTAINER_ID).innerHTML = htmlContent;
}
