var GalleryScript = 'ajax/GetGalleryImages.php';
var RowsPerPage = 4;
var Start = 0;
var Direction = '';

function DisplayNextImages()
{
	Direction = 'right';
	Start += 4;
	options = {
				 parameters:     	'start=' + Start + '&rows=' + RowsPerPage + '&rand=' + Math.random(),
				 method:         	'get', 
				 onSuccess:     	DoRotateImagesLeft
	};

	new Ajax.Request(GalleryScript, options);

}

var AtTheEnd = false;
function DoRotateImagesLeft(response)
{
    eval('var RVAL=' + response.responseText);
    
    FirstImageDisplayed = false;
    LastImageDisplayed = false;
    if(RVAL.Rows.length > 0)
    {
	var i;
	$('images').innerHTML = '';
	for(i=0;i<RVAL.Rows.length;i++)
	{
	    if(i==0)
		FirstImageDisplayed = RVAL.Rows[i].visible == 1;
	    div = document.createElement("div");
	    a = document.createElement("a");
	    a.id = 'a'+i;
	    a.href = '/gallery/' + RVAL.Rows[i].image;
	    a.rel = 'lightbox[galerie]';
	    img = document.createElement("img");
	    img.id = 'img'+i;
	    img.src = '/gallery/' + RVAL.Rows[i].thumb;
	    img.align = 'center';
	    img.vspace = 5;
	    img.hspace = 3;
	    img.border = 0;
	    a.appendChild(img);
	    div.appendChild(a);
	    div.style.cssFloat = 'left';
	    div.style.width = '145px';
	    div.style.display = (RVAL.Rows[i].visible == '0' ? 'none' : 'inline');
	    $('images').appendChild(div);

	    if(i == RVAL.Rows.length -1)
		LastImageDisplayed = RVAL.Rows[i].visible == 1;
	}
    }

    if(Direction == 'right' && LastImageDisplayed)
        AtTheEnd = true;
        
        
    if(AtTheEnd)
	Start -=4;
    
	
}

function DoRotateImagesRight()
{

}

function DisplayPrevImages()
{
        AtTheEnd = false;
	Direction = 'left';

	if(Start < 0)
	    Start = 0;

	options = {
				 parameters:     	'start=' + Start + '&rows=' + RowsPerPage + '&rand=' + Math.random(),
				 method:         	'get', 
				 onSuccess:     	DoRotateImagesLeft
	};

	new Ajax.Request(GalleryScript, options);

	if(Start > 0)
    	    Start -= 4;


}
