$(function () {
    var $container = $('#grid-content');
	$container.imagesLoaded(function () {
		$container.masonry({
			itemSelector: 'div.article',
			columnWidth: 170,
			//isAnimated: !Modernizr.csstransitions
			isAnimatedFromBottom: true	
		});
    });
	$container.infinitescroll({
		navSelector  : '#grid-content .page_nav',
		nextSelector : '#grid-content .page_nav a.next',
		itemSelector : 'div.article',
		loadingText: "<em>Loading more...</em>",
		donetext  : 'All posts have been loaded.',
		loadingImg : '/images/global/scroll_loader.gif',
		debug: false,
		errorCallback: function () { 
			$('#infscr-loading').animate({opacity: 0.8}, 2000).fadeOut('normal');   
		}
	},
    // call Masonry as a callback
		function (newElements) {
			var $newElems = $(newElements);
	// ensure that images load before adding to masonry layout
			$newElems.imagesLoaded(function () {
				$container.masonry('appended', $newElems, true); 
			});
		// Fancybox call on appended items
			$("a.image").fancybox({
				'speedIn'		:	600, 
				'speedOut'		:	200,
				'hideOnContentClick' : true
			});
		// Fancybox youtube video call on appended items
			$("a.youtube").click(function () {
				$.fancybox({
					'padding'		: 0,
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'			: this.title,
					'width'			: 640,
					'height'		: 385,
					'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'			: 'swf',
					'swf'			: {
						'wmode'				: 'transparent',
						'allowfullscreen'	: 'true'
					}
				});
				return false;
			});
		// Fancybox vimeo video call on appended items
			$("a.vimeo").click(function () {
				$.fancybox({
					'padding'		: 0,
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'			: this.title,
					'width'			: 640,
					'height'		: 385,
					'href'			: this.href.replace(new RegExp("([0-9])", "i"), 'moogaloop.swf?clip_id=$1'),
					'type'			: 'swf'
				});
				return false;
			});
	 
		}); 
			
});




