+ }
+
+ $( galleries ).each( justify );
+ $( window ).resize( $.debounce( 300, true, function () {
+ $( galleries ).children( 'li' ).each( function () {
+ var imgWidth = $( this ).data( 'imgWidth' ),
+ imgHeight = $( this ).data( 'imgHeight' ),
+ width = $( this ).data( 'width' ),
+ captionWidth = $( this ).data( 'captionWidth' ),
+ $imageElm, imageElm;
+
+ // Restore original sizes so we can arrange the elements as on freshly loaded page
+ $( this ).width( width );
+ $( this ).children( 'div' ).first().width( width );
+ $( this ).children( 'div' ).first().children( 'div.thumb' ).width( imgWidth );
+ $( this ).find( 'div.gallerytextwrapper' ).width( captionWidth );
+
+ $imageElm = $( this ).find( 'img' ).first();
+ imageElm = $imageElm.length ? $imageElm[0] : null;
+ if ( imageElm ) {
+ imageElm.width = imgWidth;
+ imageElm.height = imgHeight;
+ }
+ } );
+ } ) );
+ $( window ).resize( $.debounce( 300, function () {
+ $( galleries ).each( justify );
+ } ) );