// JavaScript Document

$(document).ready(function(){
	
	// Zorg dat de alt-description ook onder de afbeelding word weergegeven, alleen op single
	if ( $("#alt").length ) {
		$("#alt").html($("#headimg > img").attr("alt")); 
	};
	
	// Zorg ervoor dat de titel wordt weergegeven zodra je over een thumbnail hovert
	$(".flipper li").hover(
		function () {
			var id = $(this).attr('id'); 
			$('#'+id+' img').slideUp();
		}, function () {
			var id = $(this).attr('id'); 
			$('#'+id+' img').slideDown();
		}
	);	
	
	// Toon afbeeldingen van Flickr in Colorbox
	$(".slickr-flickr-gallery a").colorbox({maxWidth:'90%', maxHeight:'90%', close:"" }); 
	
	// Toon afbeeldingen in Wordpress Gallery in Colorbox
	$(".gallery a").colorbox({maxWidth:'90%', maxHeight:'90%', close:"" }); 
	
	// Toon links met class 'Colorbox' in Colorbox
	$("a[rel='colorbox']").colorbox({maxWidth:'90%', maxHeight:'90%', current:"", previous:"", next:"", close:"" }); 

	// Laat de sidebar oplichten als je eroverheen beweegt met de muis
	$(".post .sidebar").fadeTo(0, 0.16);
	$(".post .sidebar").hover(
		function () {
			$(this).fadeTo(750, 1);
		}, function () {
			$(this).fadeTo(2500, 0.16);
		}
	);
	
	// Laat de tweets 1 voor 1 zien
	numberOfTweets = $(".tweets li").length-1; // global
	currentTweet = 1; // global
	setInterval(function() { changeTweet(currentTweet); }, 7000);
	
	function changeTweet() {
						
		if (currentTweet == numberOfTweets) {
			
			$(".tweets ul").animate( { top: '0px', }, 500);
			currentTweet = 1;

		} else { 
		
			$(".tweets ul").animate( { top: '-=64px', }, 2000);
			currentTweet++;
		
		}
		
		//console.log(currentTweet);
		//console.log(numberOfTweets);
	
	}
	
	
	// Toont de details bij een Module
	function openDetails(id) {
						
		$("#details-"+id).slideDown();
				
	}
	

	// Dummy Slideshow
	function slideSwitch() {
		
		var $active = $('#dummy-visuals-slideshow IMG.active');
	
		if ( $active.length == 0 ) $active = $('#dummy-visuals-slideshow IMG:last');
		
		console.log($active);
	
		// use this to pull the images in the order they appear in the markup
		var $next =  $active.next().length ? $active.next()
			: $('#dummy-visuals-slideshow IMG:first');
	
		// uncomment the 3 lines below to pull the images in random order
		//var $sibs  = $active.siblings();
		//var rndNum = Math.floor(Math.random() * $sibs.length );
		//var $next  = $( $sibs[ rndNum ] );
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 2500, function() {
				$active.removeClass('active last-active');
			});
	}
	setInterval(function() { slideSwitch(); }, 5000);	


	
	
});
