$(document).ready(function() {

	// Add a class to the last elements
	
	$('.archive li:nth-child(5n)').addClass('last'); 
	$('.section:last').addClass('last');
	

	// -------------------------------------------------------------


	// Make imgs into slideshow with cycle plugin
	// On each click, set the caption to the img alt
	
	$('.gallery').each(function() {
	
		var p = this.parentNode;
	
		$(this).cycle({
			fx:			'fade',
			speed: 		350,
			timeout: 	0,
			next:		$('.next-image', p),
			before: 	onBefore
		});
	
		function onBefore() { 
		    $('.meta .caption', p) .html(this.alt); 
		
		};
	
	
	});


	// -------------------------------------------------------------


	// Hide the next image button if there's only one

	var count = $('.gallery').children().size(); 

	if (count == 1) {
		$('.next-image').hide();
	}


	// -------------------------------------------------------------


	// Set the gallery div to be the same height as the first child image
	// @TODO - How to do this for each .gallery?

	
	$(window).load(function() {
	
		var height = $('.gallery img').height();
	
		// alert("Image loaded!"); // @DEBUG
	
		$('.gallery').height(height);
		
	});
	

	// -------------------------------------------------------------

		
	// Search options toggle

	// $('#search #options').hide();
	// $("#search #toggle").click(function(event){
	//      
	//  		$('#search #options').toggle();
	// 
	//       	return false;
	// 
	//     });

	
	// -------------------------------------------------------------
	
	
	// Functions for smooth scrolling to next project
	
	// $('.project').each(function(i) {
	// 
	// 	$(this).attr('id', 'p' + i);
	// 	
	// });	
	// 
	// $('.next-project').each(function(i) {
	// 
	// 	$(this).attr('href', '#p' + (i + 1) );
	// 	
	// });
	// 
	// $('.next-project:last').hide();
	// 
	// 	
	// $.localScroll({
	// 	
	// 	offset:-60,
	// 	duration:1200
	// 
	// });

		
});