/*
   Script name  : slideshow
   File Name 	: slideshow.js
   Developed By : Kell
   last Updated : 05-06-10
*/

var image = Math.floor(Math.random()*25); // there should be more than 25
setInterval ( "newSlide(image)", 5000 );  // 5 seconds

function newSlide(image)
{
 myRand = parseInt(Math.random()*999999999999999);
 if ( image == "" || image == 0 || image == undefined ) { image = 1; }
 var url = "../zyzzyx/ajax_server.php?slide="+image+"&"+myRand;  // build the URL of the server script we wish to call
 myRequest.open("GET", url, true);           // ask our XMLHTTPRequest object to open a server connection
 myRequest.onreadystatechange = showSlide;   // prepare a function showSlide() to run when the response has arrived
 myRequest.send(null);                       // and finally send the request
}

function showSlide()
{
 if ( myRequest.readyState == 4 )      // we are only interested in readyState of 4, i.e. "completed"
    {   
     if ( myRequest.status == 200 )    // if server HTTP response is "OK"
        {
         //alert("text: "+myRequest.responseText);
         response    = myRequest.responseText;
         parts       = response.split("|");
         image       = parts[0];
         response    = parts[1];
         iconGraphic = document.getElementById("slideHolder");
         iconGraphic.innerHTML = response;
        }
     else
        {
         // issue an error message for any other HTTP response
         // alert("An error has occurred: " + myRequest.statusText); // best not
        }
    }
}
