/////////////////////////////////////////////////////////////////
//toevoegen aan custom.js
/////////////////////////////////////////////////////////////////
$(document).ready(function() {
	$('.gallery').thumbSlide({
		thumbWidth: 94,
		thumbMargin: 25,
		wrapperWidth: 564, 
		thumbsVisible: 6,
		animationSpeed: 500, 
		nextSelector: 'img.gallery-next',
		prevSelector: 'img.gallery-prev'
	});
});

//////////////////////////////////////////////////////////////////////////////////
//toevoegen aan custom.js of desgewenst in jquery.thumbSlide.js (+ zsetting.conf)
//////////////////////////////////////////////////////////////////////////////////
(function($){  
	$.fn.thumbSlide = function(options) {  
	  
		var defaults = {  
			wrapperWidth: 470,  
			animationSpeed: 500,
			nextSelector: 'img.gallery-next',
			prevSelector: 'img.gallery-prev'
		};  
		var options = $.extend(defaults, options);  
		  
		return this.each(function() {  
			obj = $(this); 
			setupSlideBehavior(obj);
		});  
		
		function setupSlideBehavior(el){
			var b_next = $(el.find(options.nextSelector));
			var b_prev = $(el.find(options.prevSelector));
			var list = $(el.find('ul'));
			b_next.click(function(event){ event.preventDefault(); slideLeft(list); return false; })
			b_prev.click(function(event){ event.preventDefault(); slideRight(list); return false; })
		}
		function slideRight(list){
			var oldPos = parseInt(list.css('margin-left').replace('px','').replace('auto',0));
			oldPos += options.wrapperWidth;
			if(oldPos > 0) oldPos = 0;
			list.animate({ marginLeft:oldPos }, options.animationSpeed, function(){});
		}
		function slideLeft(list){
			//calculate width
			var last = $(list.find("li:last-child"));
			var width = last.position().left + last.width() - parseInt(list.css('margin-left').replace('px','').replace('auto',0));

			var oldPos = parseInt(list.css('margin-left').replace('px','').replace('auto',0));
			oldPos -= options.wrapperWidth;
			if(oldPos < -width + 940) oldPos = -width + 940;
			list.animate({ marginLeft:oldPos }, options.animationSpeed, function(){});
		}
	};  
})(jQuery);
