/* Author:

 */

$(document).ready(function() {
});

jQuery(function() {
	if($("#twitter").length > 0) {
		//TWITTER
		$(function() {
			$("#twitter").tweet({
				join_text : "auto",
				username : "clementvalla",
				avatar_size : 0,
				count : 15,
				loading_text : "loading tweets...",
				template : "{text}"
			});
		});
	}

	var $container = $('#main');

	$container.imagesLoaded(function() {
		$container.masonry({
			itemSelector : '#main .post',
			columnWidth : 50
		});
	});
	//run masonry when window is resized
	$(window).resize(function() {
		$container.masonry({
			itemSelector : '#main .post',
			columnWidth : 50
		});
	});

	$container.infinitescroll({
		navSelector : 'div.navigation', // selector for the paged navigation
		nextSelector : 'div.nav-previous a', // selector for the NEXT link (to page 2)
		itemSelector : '#main .post', // selector for all items you'll retrieve
		donetext : 'No more pages to load.',
		loadingImg : 'http://i.imgur.com/6RMhx.gif',
		debug : false,
		errorCallback : function() {
			// fade out the error message after 2 seconds
			$('#infscr-loading').animate({
				opacity : .8
			}, 2000).fadeOut('normal');
		}
	},
	// call Masonry as a callback
	function(newElements) {
		var $newElems = $(newElements);
		$newElems.css('opacity', 0);
		// ensure that images load before adding to masonry layout
		$newElems.imagesLoaded(function() {
			$container.masonry('appended', $newElems, true);
			$newElems.animate({
				opacity : 1
			}, 1000);
		});
	});
});

