

var xmlHttp;
var img_pad = 'img/ajax-loader.gif';
var img_loader = new Image();
img_loader.src = img_pad;

/**
 * functie playGallery()
 * parameters:
 * max = aantal foto's die mogen worden getoond.
 * limit = volgorde foto die moet worden getoond.
 * id = groep waar de foto's toe behoren.
 */
function playGallery(id,limit,max)
{
    xmlHttp=GetXmlHttpObject();
    var min = 0;
    var obj = document.getElementById('fotoslide');
    var obj2 = document.getElementById('controlslide');   
    // is limit lager dan max? optellen, anders opnieuw beginnen
    var nextPic = limit < max ? limit + 1 : 0;
    // is limit hoger dan min ? aftrekken, anders vanaf max aftellen
    var lastPic = limit > min ? limit - 1 : max;

    if(xmlHttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url="carpeta/photo.php";
    url=url+"?id="+id;
    url=url+"&limit="+limit;
    url=url+"&sid="+Math.random();
    
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    //xmlhttp.onreadystatechange=stateChanged;
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState ==4 || xmlHttp.readyState=="complete"){
            obj.innerHTML=xmlHttp.responseText;
            obj2.innerHTML='<a class="title_grijs" style="cursor:pointer" onclick="playGallery('+id+','+lastPic+','+max+');"> < PREVIOUS</a> &nbsp;&nbsp;';
            obj2.innerHTML+= '<a class="title_grijs" style="cursor:pointer" onclick="playGallery('+id+','+nextPic+','+max+');">NEXT > </a>';
        }
        else{
            obj.innerHTML = '<div><img src='+img_loader.src+' /><br /><span style="color:blue;font-weight:bold;"> De afbeelding word geladen..</span>';
        }
    }
}


function GetXmlHttpObject()
{
    if(window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if(window.ActiveXObject){
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}




