galleryObject = [];
i = 0;

buildgallery = function (response) {
	galleryObject = Json.evaluate(response);
	// SET FIRST PICTURE
	var firstpic = galleryObject[0];
	$('picture').src = '_cms/pics/'+firstpic.image;
	$('picture-information').innerHTML = firstpic.caption_nl;
	// ADD ROLLOVER STOP INTERVAL FUNCTION
	$('picture-container').addEvent('mouseenter',
							function () {
								clearInterval(slideshowInterval);
							});
	$('picture-container').addEvent('mouseleave',
							function () {
								slideshowInterval = setInterval('setImage()',3000)
							});
	
	slideshowInterval = setInterval('setImage()',3000);
}

setImage = function () {
	var total = galleryObject.length-1;
	var object = galleryObject[i];
	if(i >= total) {
		i = 0;
	}
	$('picture').src = '_cms/pics/'+object.image;
	$('picture-information').innerHTML = object.caption_nl;
	i++;
}

getgallery = function () {
	var url = "http://www.publicpartners.be/getphoto/";
	var getGallery = new Ajax(url,{onComplete:buildgallery}).request();
}

switchpictures = function () {
	$$('img').each(function(img) {
		if(img.hasClass('thumb')) {
			img.onclick = function () {
				$(img.alt).src = this.src;
			}
		}
	});
}

window.addEvent('domready', function() {
	getgallery();
	switchpictures();
});


