// JavaScript Document
$(document).ready(function() { 
	collectionGallery();
    
	$(".ngg-gallery-thumbnail a[rel='colorbox']").colorbox({
		maxWidth:"80%",
		maxHeight:"80%",
		transition:"fade",
		opacity:0.8,
		onComplete: function(){
			$(".cboxPhoto").loupe({
				width: 130, // width of magnifier
				height: 130, // height of magnifier
				loupe: 'loupe' // css class for magnifier
			});
		}
	});
	$('div.trunk-shows #primary').jScrollPane();

	
});


function collectionGallery () {
	
	var slidesCount = $(".ngg-galleryoverview .ngg-gallery-thumbnail-box").size();
	var slideWidth = $(".ngg-galleryoverview .ngg-gallery-thumbnail-box").outerWidth(true);
	
	if ( Math.ceil(slidesCount/3) > 4 ) {
		var factor = Math.ceil(slidesCount/3);
	} 
	
	else {
		var factor = 4;
	} 
	
	var sliderWidth = factor * slideWidth;
	
	$(".ngg-galleryoverview").width(sliderWidth);
	
	var current = 0;
	var limit = Math.ceil(slidesCount/8);
	
	$(".btn_right").click(function(){
		
		if (slidesCount > 12) {
		
			if(current < limit-1) {
				current ++;
				var posLeft = 0 - current * (2*slideWidth);
				$(".gallery_slider .ngg-galleryoverview").stop(true,true).animate({"left" : posLeft + "px"}, 600, 'easeOutExpo');	
			}
			
			else {
				var posLeft = 0;
				$(".gallery_slider .ngg-galleryoverview").stop(true,true).animate({"left" : posLeft + "px"}, 600, 'easeOutExpo');	
				current = 0;
			}
		}
		
	});
	
	$(".btn_left").click(function(){
		if(current > 0) {
			current --;
			var posLeft = 0 - current * (2*slideWidth);
			$(".gallery_slider .ngg-galleryoverview").stop(true,true).animate({"left" : posLeft + "px"}, 600, 'easeOutExpo');	
		}
	});
	
	
}

