		var currentimg = -1;
		
		var max = 0;
		
		jQuery(document).ready(function() {
	
			var pic = [];
	
			$('.gallink').each(function(index) {
				
				$(this).click(function(){
					var nr = $(this).attr('galleryid');
					displayPic(nr);
				
				});
				
				var content = $(this).attr('rel');
				pic.push (content);
		
			});
		
			max = pic.length-1;
			afbeeldingen = pic;
			
			
	
		});
		
		$('.photobox').html('<p>Choose a picture from the left side or press \"Play\" to start a slideshow.</p>');
		
		function displayPic(nr){
			//show image
			currentimg = nr;
			var plaatje = afbeeldingen[nr];
			
			$('.photobox').fadeOut(300,function() {
				$('.photobox').html('<img src=http://webapp.new-art.nl/image.php?image=/content/img/gallery/' + plaatje + '.jpg>');
				$('.photobox').fadeIn(500);
			});
		}
		
		function switchImg(direction){
			
			if (direction == 'prev') {
			
				if(currentimg == 0) {
					currentimg=max;
				} else {
					currentimg--;
				}
				
				displayPic(currentimg);
			
			}
			
			if (direction == 'next') {
			
				if(currentimg == max) {
					currentimg=0;
				} else {
					currentimg++;
				}
				
				displayPic(currentimg);
			
			}
			
		}
		
		function togglePlay(state) {
		
		
			if(state == 'play') {
			
				switchImg("next");
			
				toggle = setInterval('switchImg("next")', 4000);
			
			}
			
			if(state == 'stop') {
				
				clearInterval(toggle);
			}
		
		}
		
		$(window).load(function() {
			switchImg("next");
		});
