var mLastCheck =  1;

function mInit()
{
	mLastCheck = $( '#structure' ).width();
	$( window ).trigger('resize');
	//console.log( $( '#structure' ).width() );
	var pics;
	$( '.post .contenu' ).each( function(){
		pics = $( this ).find( 'img' ).not( '.metrics' );
		if( pics.length == 0 ) $( this ).addClass( 'nopic' );
		else
		{
			pics.each( function(){
				$( this ).addClass( 'picture' );
				w = $( this ).width();
				//console.log('w == ', w );
				$( this ).load(function() {
					$( this ).fadeIn( 'slow', function(){ console.log( 'end loading image' ); } );
					if( $( this ).width() < 900 ) placeMe( $( this ), $( this ).width() );
				});
			});
			pics.first().insertBefore( $( 'h1', $( this ) ) );
			pics.not( ':first' ).addClass( 'content' );
		}
		$( '.prepareFadeIn' ).removeClass( 'prepareFadeIn' );
	});
	$(window).resize(function(){
		var sW = $( '#structure' ).width();
		if( mLastCheck != sW )
		{
			mLastCheck = sW;
			//console.log( '\n###REPLACEMENT###\n\t\t', mLastCheck );
			$( 'img.picture' ).each( function(){
				placeMe( $( this ), $( this ).width() );
			});
		}
	});

}

function placeMe( cible, w )
{
	//console.log( 'retaille de ', cible.attr( 'src' ), ' w/ w == ', w);
	//mLastCheck < 1200 && w > 600 ? 600 : ( w < 600 ? 600 - w : 900 - w );
	//mrg = Math.floor( ( 900 - w ) / 2 );
	
	if( ( mLastCheck < 1200 && w >= 600 ) == false )
	{
		mrg = Math.floor( ( mLastCheck < 1200 && w < 600 ? 600 - w : 900 - w ) / 2 );
	}
	else mrg = 0;	
	
	cible.css(  { 'margin-left' : mrg, 'margin-right' : mrg } );
	//console.log( 'mrg == ', mrg, '\n***' );
}

