$(function(){

	var 
		speed = 1000,   // animation speed
		fade_to = 0.1;
		$wall = $('#portfolio_primary')
	;

	$wall.masonry({
		columnWidth: 86, 
		// only apply masonry layout to visible elements
		itemSelector: '.box:not(.invis)',
		animate: false,
		animationOptions: {
			duration: speed,
			queue: false
		}
	});

	$('#portfolio_filtering_nav a').click(function(){
		$('#portfolio_filtering_nav a').each(function(index){
			if($(this).hasClass('active')) $(this).removeClass('active');
		});
		var categoryClass = '.' + $(this).attr('class');
		$(this).addClass('active')
		/* use fadeIn()/fadeOut() as opposed to fadeTo() to show/hide bricks */
		
		if(categoryClass=='.all') {
			// show all hidden boxes
			$wall.children().removeClass('faded').fadeTo(speed,1);
		} else {    
			$wall.children().not(categoryClass).not('faded').addClass('faded').fadeTo(speed,fade_to);
			$wall.children(categoryClass).removeClass('faded').fadeTo(speed,1);
		}
		$wall.masonry();

		return false;
	});
	
	$('a.portfolio_modal_box').click(function(e) {
		if($(this).parent().hasClass('faded')) {
			$(this).removeClass('portfolio_modal_box');
			e.preventDefault();
		}
	}); 

/*	
	$wall.infinitescroll({
		navSelector  : "#portfolio_page_nav",    // selector for the paged navigation 
		nextSelector : "#portfolio_page_nav a",    // selector for the NEXT link (to page 2)
		itemSelector : ".box",       // selector for all items you'll retrieve
		loadingImg : '/modules/portfolio/images/loader.gif',
		donetext  : "No more pages to load.",
		debug: true,
		errorCallback: function() { 
			// fade out the error message after 2 seconds
			$('#infscr-loading').animate({opacity: .8},2000).fadeOut('normal');     
		}
	},
		// call masonry as a callback.
		function() { $wall.masonry({ appendedContent: $(this) }); }
	); */
	
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
	    return '<div id="portfolio_content_title"><b>Portfolio Content: '+title+'</b></div>';
	}

	
	$("a.portfolio_modal_box").fancybox({
				'titleShow'		: false,
				'scrolling' : 'no'
			});
	
});
