(function($) {

	$(function() {

		$('span.cremage-flickr').parents('p').addClass('flickr');

		$('.cremage-flickr span').eq(0).show();

		$('#respond').each(function() {
			var $this = $(this);
			$this.hide();
			$this.prev().find('a').click(function() {
				if ( $this.is(':visible') ) {
					$this.slideUp(200);
					$(this).text('Laisser un commentaire ↓');
				} else {
					$this.slideDown(200);
					$('html, body').animate({
						scrollTop: $this.position().top + 'px'
					},{
						duration: 1000,
						complete: function() {
							$('#author').focus();
						}
					});
					$(this).text('↑ Annuler');
				}
			});
		});

		if ( window.location.hash && window.location.hash == '#respond' ) {
			$('.toggle-respond a').trigger( 'click' );
		}

	});

	$(window).load(function() {
		$('.avatar').each(function() {
			var $this = $(this);
			var src = $(this).attr('src');
			var image = new Image;
			image.onload = function() {
				image.onload = null;
				if ( image.width == 1 ) {
					$this.css('border', 'none');
				}
			}
			image.src = src;
		});
	});

})(jQuery);
