jQuery(document).ready(function() {
	
	function portfolio_quicksand() {
		
		var $filter;
		var $container;
		var $containerClone;
		var $filterLink;
		var $filteredItems
		
		$filter = $('.filter li.active a').attr('class');
		
		$filterLink = $('.filter li a');
		
		$container = $('ul.filterable-grid');
		
		$containerClone = $container.clone();
		
		$filterLink.click(function(e) 
		{
			$('.filter li').removeClass('active');
			
			$filter = $(this).attr('class').split(' ');
			
			$(this).parent().addClass('active');
			
			if ($filter == 'all') {
				$filteredItems = $containerClone.find('li'); 
			}
			else {
				$filteredItems = $containerClone.find('li[data-type~=' + $filter + ']'); 
			}
			
			$container.quicksand($filteredItems, 
			{
				duration: 1500,
				easing: 'easeInOutCirc',
				adjustHeight: 'dynamic' 
			});
			
			$container.quicksand($filteredItems, 
				function () { lightbox(); }
			);			
		});
	}
		
	if(jQuery().quicksand) {
		portfolio_quicksand();	
	}
		
	function lightbox() {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed:'fast',
			slideshow:5000,
			theme:'pp_default',
			show_title:false,
			overlay_gallery: false,
			social_tools: false
		});	   	  
				   
	}
	
	if(jQuery().prettyPhoto) {
		lightbox();
	}
	
}); // END OF DOCUMENT