function buildMenu() {
   //Build the album list
   $("#albumlist").html("");

   //Get a list of availible albums
   $.get('getAlbums.php',
         {},
         function(xml) {
            album = $("album", xml).each(function() {
               var albumname = $(this).text();
               var htmlstring = "<p><a href=\"javascript:showAlbum('"+ albumname + "')\">" + albumname + "</a></p>";       
               $("#albumlist").append(htmlstring)
            });
         }
   ); 

   //Print which date the pics we're viewing are from
   $("#month").html(months[currentMonth]);
   $("#year").html(currentYear);

   var today = new Date();
   var thisMonth = months[today.getMonth() + 1];
   var thisYear = y2k(today.getYear());

   //Make a link to the acutal current month/yeaer
   $("#currentmonth").html("<p><a href=\"javascript:gotoCurrentMonth()\">[" + 
         thisMonth + ", " + thisYear + "]</a></p>");
}

function buildLinks(noResults, noTotalResults, album) {
   pages = Math.ceil(noTotalResults / maxImages);
   var html = "";
   //From photostream, show the links to change month and year
   if (album == "default") {
      var prevMonth;
      var nextMonth;
      
      if (currentMonth == 1) {
         prevMonth = 12;
      } else {
         prevMonth = currentMonth -1;
      }
      
      //links for previous time
      $("#prevlinks").html("<a href=\"javascript:prevYear()\">" + (currentYear-1)+"</a>&larr;" +
			   "<a href=\"javascript:prevMonth()\">" + months[prevMonth] + "</a>");

      //calculate links for next in time
      var now = new Date();

      //if next year should be visible
      var nextYear = new Date();
      nextYear.setFullYear(currentYear+1, 0);
      var yearHTML;
      if (nextYear <= now) {
	  yearHTML = "<a href=\"javascript:nextYear()\">" + (currentYear+1) + "</a>";
      } else {
	  yearHTML = (currentYear+1);
      }

      //if next month should be visible
      var nextMonth = new Date();
      if (currentMonth == 12) {
	  nextMonth.setFullYear(currentYear+1, 0);
      } else {
	  //Dates month is 0-indexed, but not ours, so currentMonth instead of currentMonth+1.
	  nextMonth.setFullYear(currentYear, currentMonth);
      }
      var monthHTML;

      if (nextMonth <= now) {
	  monthHTML = "<a href=\"javascript:nextMonth()\">" + months[nextMonth.getMonth()+1] + "</a>";
      } else {
	  monthHTML = months[nextMonth.getMonth()+1];
      }

      $("#nextlinks").html(monthHTML + "&rarr;" + yearHTML);
      

   } else { //in an album, no dates
      $("#prevlinks").html("");
      $("#nextlinks").html("");
   }

   if (currentPage == 1) {
       html += "&larr; ";  
   } else {
      html += "<a href=\"javascript:goPage(" + (currentPage - 1)
	  + ",'" + album + "')\">&larr;</a> ";
   }

   for (i = 1; i <= pages; i++) {
      if (i != currentPage) {
         html += "<a href=\"javascript:goPage(" + i + ", '" + album + "')\">" + (i) + "</a> ";
      } else {
         html += i + " ";
      }

   }

   if (currentPage < (pages)) {
      html += "<a href=\"javascript:goPage(" + (currentPage + 1)
	  + ",'" + album +"')\">&rarr;</a>";
   } else {
       html += "&rarr;"
   }

   document.getElementById("linkstop").innerHTML = html;
}

