
function startSlideshowInWindow()
{
  window.open( "pages/improvedSlideshow.html", "slideshow_window", "width=850,height=600,resizable=no,toolbar=no" );
}

/*************************************/

function Photos()
{
  var photos = new Array();
  var currentIndex = 0;
  
  this.add = function( aPhoto )
  {
    photos[ photos.length ] = aPhoto;
  }
    
  this.currentUrl = function()
  {
      return photos[ currentIndex ].url;
  }
  
  this.currentCaption = function()
  {
      return photos[ currentIndex ].caption;
  }
  
  this.advanceAndPreLoad = function()
  {
    if ( currentIndex == photos.length - 1 )
      currentIndex = 0;
    else
      currentIndex++; 
  
    new Image().src = this.currentUrl();  
  }
}

////////////////////////////////////////

function Photo( url, caption )
{
  this.url = url;
  this.caption = caption;
}

////////////////////////////////////////

function Slideshow()
{
  var photos = new Photos();
  var timeoutPeriod = 5000;
  
  this.addPhoto = function( src, caption )
  {
    photos.add( new Photo( src, caption ) );
  }
  
  this.getTimeout = function()
  {
    return timeoutPeriod;
  }
  
  this.faster = function()
  {
    timeoutPeriod -= 1000;
    
    if (timeoutPeriod < 1000 )
      timeoutPeriod = 1000;
  }
  
  this.slower = function()
  {
    timeoutPeriod += 1000;
    
    if (timeoutPeriod > 10000 )
      timeoutPeriod = 10000;
  }
  
  this.start = function() 
  { 
    //this.rescaleImage();  
    this.showCurrentPhoto();       
  }
  
  this.setTimeoutAndCaption = function()
  {    
    window.setTimeout( "slideshow.start()", timeoutPeriod );    
    this.write( photos.currentCaption() );
    photos.advanceAndPreLoad();        
  }
  
  /******** private functions *********/
  
  this.write = function( text )
  {
    caption().firstChild.nodeValue = text;
  }
  
  this.rescaleImage = function() 
  {  
    displayedImage().height = window.innerHeight * 0.8;
    displayedImage().width = displayedImage.height * 1.33;
  }
  
  this.showCurrentPhoto = function()
  {  
    displayedImage().src = photos.currentUrl();
  }

  var caption = function()
  {
    return document.getElementById( "caption" );
  }

  var displayedImage = function()
  {
    return document.getElementById( "displayedImage" );
  }
}



