var xmlHttp;
var arrContent;
var arrFile;
var intLoop;
var intMax;
// retrieves the XMLHttpRequest object


function createXmlHttpRequestObject()
{
    // will store the reference to the XMLHttpRequest object
    var xmlHttp;
    // if running Internet Explorer
    if(window.ActiveXObject)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp = false;
        }
    }
    // if running Mozilla or other browsers
    else
    {
        try
        {
            xmlHttp = new XMLHttpRequest();
        }
        catch (e)
        {
            xmlHttp = false;
        }
    }
    // return the created object or display an error message
    if (!xmlHttp)
        alert("Error creating the XMLHttpRequest object.");
    else
        return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object
function funcProcessSlideShow(intCatID)
{
    var intCode = null; var strEmail = "";  var strComments = "";

    xmlHttp = createXmlHttpRequestObject();
    // proceed only if the xmlHttp object isn't busy
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
    {
        // retrieve the name typed by the user on the form
        //name = encodeURIComponent(document.getElementById("myName").value);
        // execute the quickstart.php page from the server

        xmlHttp.open("GET", "getSlideShow.php?catID=" + intCatID, true);
        // define the method to handle server responses
        xmlHttp.onreadystatechange = handleServerResponse;
        // make the server request
        xmlHttp.send(null);
    }
    else
    {
        // if the connection is busy, try again after one second
        setTimeout('funcProcess()', 1000);
    }


}

// executed automatically when a message is received from the server
function handleServerResponse()
{
    // move forward only if the transaction has completed
    if (xmlHttp.readyState == 4)
    {
        // status of 200 indicates the transaction completed successfully
        if (xmlHttp.status == 200)
        {
            parseResults();
        }
        // a HTTP status different than 200 signals an error
        else
        {
            alert("There was a problem accessing the server: " + xmlHttp.statusText);
        }
    }
}


function parseResults() {
    var results = xmlHttp.responseXML;
    var strInfo = "";
    var picture = results.getElementsByTagName("Picture");
    var intCount = picture.length;
    arrContent = Array(intCount);
    arrName = Array(intCount);
    intMax = intCount - 1;

    for (intRow = 0; intRow < intCount; intRow++)
    {
        arrContent[intRow] = picture[intRow].getElementsByTagName("Title")[0].firstChild.nodeValue;
        arrName[intRow] = picture[intRow].getElementsByTagName("File")[0].firstChild.nodeValue;

        if (intRow > 0)
        {
            strInfo +=",'gallery/images/large/" + arrName[intRow] + "'";
        }
        else
        {
            strInfo = "'gallery/images/large/" + arrName[intRow] + "'";
        }
    }

    MM_preloadImages(strInfo);

    intLoop =0;
    funcStartSlide();
}


function funcStartSlide()
{
    //divContent
    //mainPicture
    strFile = arrName[intLoop];
    strContent = arrContent[intLoop];

    var strPic = "<img src='../gallery/images/large/" + strFile +"' />";

    document.getElementById("divContent").innerHTML = strContent;
    document.getElementById("divPicture").innerHTML = strPic;

    if (intLoop < intMax)
    {
        setTimeout('funcStartSlide()', 5000);
        intLoop++;
    }
}


function funcStopSlide()
{
    intLoop = 0;
    intMax = 0;
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}