// INIT WHEN READY ----------------------------------------------------------------------------------
$(document).ready(function() {
	

	// POSTCARDS ----------------------------------------------------
	(function($) {
		// current being shown
		// interval
		var current, interval;
		// get all postcards
		var postcards = $('img.postcard');
		// set default state
		postcards.hide();
		// choose random team member
		current = Math.floor(Math.random()*postcards.length);
		// and show it
		$(postcards[current]).show();
		// setup timer
		interval = setTimeout(update, 6000);
		
		// update function
		function update() {
			// clear interval
			clearTimeout(interval);
			// fade out current
			$(postcards[current]).stop().fadeOut('swing');
			// get next
			current<postcards.length-1 ? ++current : current=0;
			// fade in new
			$(postcards[current]).stop().fadeIn('swing');
			// set timeout
			interval = setTimeout(update, 6000);
		}
	})(jQuery);
	
	
	
	
	// TEAM MEMBERS -------------------------------------------------
	(function($) {
		// current teammember being shown
		// interval
		var current, interval;
		// get all teammembers
		var team = $('#bottomContent div.teammembers');
		// set default state
		team.hide();
		// choose random team member
		current = Math.floor(Math.random()*team.length);
		// and show it
		$(team[current]).show();
		// setup timer
		interval = setTimeout(update, 6000);
		
		// update function
		function update() {
			// clear interval
			clearTimeout(interval);
			// fade out current
			$(team[current]).stop().fadeOut('swing');
			// get next
			current<team.length-1 ? ++current : current=0;
			// fade in new
			$(team[current]).stop().fadeIn('swing');
			// set timeout
			interval = setTimeout(update, 6000);
		}
	})(jQuery);
	
	
	
	
	// FANCYBOX -----------------------------------------------------
	// for a gallery of images (if any exist)
	if($("a[rel=gallery]").length>0) {
		$("a[rel=gallery]").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'overlayColor'		: '#000',
			'overlayOpacity'	: 0.75,
			'titlePosition' 	: 'inside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return (title.length ? title : '')+'<br /><span class="lightgray" style="font-size:9px;font-weight:normal;">Foto ' + (currentIndex + 1) + ' van ' + currentArray.length+'</span>';
			}
		});
	}
	
	
	
	
	
});
