	$(function() {	
	
		// -------------------
		// BANNER on home page
		// -------------------
		
		// rotate the pictures of each box
		rotatePics(1, '#sista');
		rotatePics(1, '#cosic');
		rotatePics(1, '#docarch');
		rotatePics(1, '#ibbt');
		
		rotatePics(1, '#jobopportunities');
		
		// -------------------
		// COLORBOX on home page & in the picture archive
		// -------------------
		
		// array that will hold all the different lightboxes
		var lightboxes = [];
		
		// find all the links with the class 'in_the_picture'
		$("a[class='in_the_picture']").each( function() {
			var rel = $(this).attr('rel');
	
			if(jQuery.inArray(rel, lightboxes) < 0) {
				lightboxes.push(rel);
			}
		});
		
		jQuery.each( lightboxes, function(index, value) {
			$("a[rel='"+value+"']").colorbox();
		});
		
		// -------------------
		// COLORBOX on people page
		// -------------------
		
		// colorbox effect on the image on the people page (underneath Academic staff)
		$("a[rel='colorbox']").colorbox();
		
		
		  $('.evdescr').hide();
	
		  $('.toggle_events_detail').toggle(function() {
				$('.evdescr').slideDown();
			} ,
			function() {
				$('.evdescr').slideUp();
			});
	} );

	function rotatePics(currentPhoto, currentBox) {
		// get the total number of photos of the current box
		var numberOfPhotos = $(currentBox +' img').length;
		// make sure that the currentPhoto is not higher then the total number of photos
		currentPhoto = currentPhoto % numberOfPhotos;
		
		// get the current image and fade it out
		$(currentBox + ' img').eq(currentPhoto).fadeOut('slow', 'linear', function() {
			// callback function tot take care of the setup for the next fade
			
			// re-order the z-index
			$(currentBox + ' img').each(function(i) {
			  $(this).css(
				'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
			  );
			});
			
			// the just faded out picture is at the bottom of the pile, so it's save to show it again
			$(this).show();
			// run the rotatePics function again (with the next photo) after a delay of 7 seconds
			setTimeout(function() {rotatePics(++currentPhoto, currentBox);}, 7000);
	  });
	}
	
	
	// GOOGLE ANALYTICS
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-12056551-5']);
	_gaq.push(['_trackPageview']);

	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
