var mostrecent_album_base_url = 'http://' + window.location.host;
var mostrecent_album_xmlhttp = null;
var mostrecent_album_timer = 0;
var mostrecent_album_index = 0;
var mostrecent_album_firsttime = 1;
var mostrecent_album_play = 0;       // Are we currently playing slideshow? (0=no,1=yes).
var mostrecent_album_slides = new Array();

function MostRecent_Album_PausePlay()
{
  if ( document.getElementById )
  {
    if ( mostrecent_album_play == 0 )
    {
      // Slideshow is in pause mode. Change play button to pause button,
      // then start the slideshow.
      var myurl = mostrecent_album_base_url + '/images/blue_pause.png';
      document.getElementById('mostrecent_album_playpause').src = myurl;
      document.getElementById('mostrecent_album_playpause').alt = 'Pause Slideshow';
      mostrecent_album_play = 1;
      MostRecent_Album_Run();
    }
    else
    {
      // Slideshow is running. Stop the slideshow timer,
      // then change the pause button to play button.
      clearTimeout(mostrecent_album_timer);
      mostrecent_album_timer = 0;
      var myurl = mostrecent_album_base_url + '/images/blue_play.png';
      document.getElementById('mostrecent_album_playpause').src = myurl;
      document.getElementById('mostrecent_album_playpause').alt = 'Play Slideshow';
      mostrecent_album_play = 0;
    }
  }
}

function MostRecent_Album_Run()
{
  var tmp;

  if ( document.getElementById )
  {
    if ( mostrecent_album_firsttime == 0 )
    {
      var tmp = 'mostrecent_album_page' + (mostrecent_album_index + 1);
      document.getElementById(tmp).style.border = "solid 1px #FFFFFF";
      mostrecent_album_index++;

      if ( mostrecent_album_index > 4 )
        mostrecent_album_index = 0;
    }

    var myData = new Array();
    myData = mostrecent_album_slides[mostrecent_album_index].split("\t");
    document.getElementById('mostrecent_album_img').width = myData[1];
    document.getElementById('mostrecent_album_img').height = myData[2];
    document.getElementById('mostrecent_album_img').src = myData[0];
    tmp = '<a href=\"' + mostrecent_album_base_url;
    tmp += '/photos.php?id=';
    tmp += myData[8] + '\">';
    tmp += myData[3];
    tmp += '</a>';
    document.getElementById('mostrecent_album_title').innerHTML = tmp;
    document.getElementById('mostrecent_album_desc').innerHTML = myData[4];
    document.getElementById('mostrecent_album_place').innerHTML = myData[5];
    tmp = 'Album Date: ' + myData[6] + '<br>';
    tmp += 'Posted Date: ' + myData[7];
    document.getElementById('mostrecent_album_dates').innerHTML = tmp;

    tmp = 'mostrecent_album_page' + (mostrecent_album_index + 1);
    document.getElementById(tmp).style.border = "solid 1px #336699";
    mostrecent_album_firsttime = 0;

    mostrecent_album_timer = setTimeout('MostRecent_Album_Run()', 5000);
  }
}

function MostRecent_Album_GetXMLHttpRequest()
{
  if ( window.XMLHttpRequest ) 
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new window.XMLHttpRequest;
  }
  else 
  {
    try 
    {
      return new ActiveXObject("Microsoft.XMLHTTP");
      /* xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0"); */
    }
    catch(ex) 
    {
      return null;
    }
  }
}

function MostRecent_Album_Handler()
{
  var ndx;

  if ( mostrecent_album_xmlhttp.readyState == 4 /* complete */ ) 
  {
    if ( mostrecent_album_xmlhttp.status == 200 )
    {
      var temp_str = mostrecent_album_xmlhttp.responseText;
      mostrecent_album_slides = temp_str.split("|");
      MostRecent_Album_PausePlay();
    }
    else
    {
      window.alert("slideshow_xmlhttp.status = " + slideshow_xmlhttp.status);
    }
  }
}

function MostRecent_Album()
{
  mostrecent_album_xmlhttp = MostRecent_Album_GetXMLHttpRequest();

  if ( mostrecent_album_xmlhttp != null ) 
  {
    var myurl = mostrecent_album_base_url + '/code/photos/mostrecent_album1_data.php';
    mostrecent_album_xmlhttp.open("GET", myurl, true);
    mostrecent_album_xmlhttp.onreadystatechange = MostRecent_Album_Handler;
    mostrecent_album_xmlhttp.send();
  }
  else 
  {
    window.alert("AJAX (XMLHTTP) not supported.");
  }
}

