//*************************************************
// albumsController.js
//
//Summary: Handles the Ajax to show a list
//         of available albums
//
//Author:      Jeff Buhr
//
//Created:     28 Apr 08
//Summary of Modifications:
//       none
//*************************************************


// albums class
function albumsController(display,baseDir) {

   // constants
   this.NORMAL_STATE = 4;

   // Class Member Vars
   this.display = display;
   this.baseDir = baseDir;
   this.http = getHTTPObject();
   this.imageArray;
   this.currentImage = 0;
   
   // Ajax call to albums into memory/the DOM
   this.loadAlbums = function() {

      // now get the album list
      var url= this.baseDir + "getAlbumList.php?&time=";
      url += new Date().getTime(); // prevents browser loading from cache

      // try to make the request
      try {
         // send the request
         this.http.open('GET', url, true); 
         this.http.onreadystatechange = this.handleHttpGetAlbumNames;
         this.http.send(null);
      }
      catch (e) {
         ;
      }

      return;
   }

   // Call back function for handling the loadAlbums ajax
   this.handleHttpGetAlbumNames = function() {

      // if there hasn't been any errors
      if (picGallery.display.albums.http.readyState == picGallery.display.albums.NORMAL_STATE) {
         // split by the divider | 
         var results = picGallery.display.albums.http.responseText.split('|');

         if (results[0] == 'true') {

            // add album list if successful
            picGallery.display.updateAlbumList(results);
         }
         else {
            picGallery.display.showError("Unable to get album list. " + results[1]);
         }
      }

      return;
   }
}




