/**
 * 
 */
var fbp = {};

fbp.PHOTOS_DIV = 'fbPhotos';

/**
 * @param {String} queryType The type of query to be done - either 'all'
 *     for querying all videos, or the name of a standard feed.
 * @param {String} searchTerm The search term(s) to use for querying as the
 *     'vq' query parameter value
 * @param {Number} page The 1-based page of results to return.
 */
fbp.listVideos = function(queryType, searchTerm, page) {
  ytvbp.previousSearchTerm = searchTerm; 
  ytvbp.previousQueryType = queryType; 
  var maxResults = ytvbp.MAX_RESULTS_LIST;
  var startIndex =  (((page - 1) * ytvbp.MAX_RESULTS_LIST) + 1);
  ytvbp.presentFeed(queryType, maxResults, startIndex, searchTerm);
  ytvbp.updateNavigation(page);
};

/**
 * @param {String} filePath The path to which the request should be sent
 * @param {String} params The URL encoded POST params
 * @param {String} resultDivName The name of the DIV used to hold the results
 */
fbp.sendRequest = function(filePath, params, resultDivName) {
var resultDiv = document.getElementById(resultDivName);

new Ajax.Request(filePath,
  {
	parameters: params,
    method:'post',
	onCreate: function() {
		resultDiv.innerHTML = '<b>Loading...</b>';
	},
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      resultDiv.innerHTML = response;
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
}

/**
 * @param {String} videoId The ID of the YouTube video to show
 */
fbp.viewAlbum = function(aid) {
  var params = 'query=show_album&aid=' + aid;
  var filePath = '../Photos/photos.php';
  fbp.sendRequest(filePath, params, fbp.PHOTOS_DIV);
}

/**
 * @param {String} queryType The name of a standard video feed or 'all'
 * @param {Number} maxResults The maximum number of videos to list
 * @param {Number} startIndex The first video to include in the list
 * @param {String} searchTerm The search terms to pass to the specified feed
 */
fbp.listAlbums = function(){
  var params = 'query=list_albums';
  var filePath = '../Photos/photos.php';
  fbp.sendRequest(filePath, params, fbp.PHOTOS_DIV);
}
