Index: /trunk/include/category_cats.inc.php
===================================================================
--- /trunk/include/category_cats.inc.php	(revision 20160)
+++ /trunk/include/category_cats.inc.php	(revision 20161)
@@ -388,4 +388,5 @@
   $tpl_thumbnails_var_selection = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var_selection);
   $template->assign( array(
+    'maxRequests' =>$conf['maxRequests'],
     'category_thumbnails' => $tpl_thumbnails_var_selection,
     'derivative_params' => $derivative_params,
Index: /trunk/include/category_default.inc.php
===================================================================
--- /trunk/include/category_default.inc.php	(revision 20160)
+++ /trunk/include/category_default.inc.php	(revision 20161)
@@ -154,4 +154,5 @@
 $template->assign( array(
   'derivative_params' => trigger_event('get_index_derivative_params', ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) ) ),
+  'maxRequests' =>$conf['maxRequests'],
   'SHOW_THUMBNAIL_CAPTION' =>$conf['show_thumbnail_caption'],
     ) );
Index: /trunk/include/config_default.inc.php
===================================================================
--- /trunk/include/config_default.inc.php	(revision 20160)
+++ /trunk/include/config_default.inc.php	(revision 20161)
@@ -770,3 +770,6 @@
 // 'small', 'medium' or 'large'
 $conf['derivative_default_size'] = 'medium';
+
+//Maximum Ajax requests at once, for thumbnails on-the-fly generation
+$conf['maxRequests']=3;
 ?>
Index: /trunk/themes/default/template/index.tpl
===================================================================
--- /trunk/themes/default/template/index.tpl	(revision 20160)
+++ /trunk/themes/default/template/index.tpl	(revision 20161)
@@ -172,6 +172,7 @@
 
 {if !empty($THUMBNAILS)}
+<div class="loader" style="display: none; position: fixed; right: 0;bottom: 0;"><img src="{$ROOT_URL}{$themeconf.img_dir}/ajax_loader.gif"></div>
 <ul class="thumbnails" id="thumbnails">
-{$THUMBNAILS}
+  {$THUMBNAILS}
 </ul>
 {/if}
Index: /trunk/themes/default/template/mainpage_categories.tpl
===================================================================
--- /trunk/themes/default/template/mainpage_categories.tpl	(revision 20160)
+++ /trunk/themes/default/template/mainpage_categories.tpl	(revision 20161)
@@ -8,16 +8,53 @@
 }
 {/html_style}{/strip}
+<div class="loader" style="display: none; position: fixed; right: 0;bottom: 0;"><img src="{$ROOT_URL}{$themeconf.img_dir}/ajax_loader.gif"></div>
 <ul class="thumbnailCategories">
 {foreach from=$category_thumbnails item=cat name=cat_loop}
 {assign var=derivative value=$pwg->derivative($derivative_params, $cat.representative.src_image)}
-{if !$derivative->is_cached()}
+{if !$derivative->is_cached() and !$js_loaded}
 {combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js' load='footer'}
-{combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'}
+{*combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'*}
+{footer_script}{literal}
+var thumbnails_queue = jQuery.manageAjax.create('queued', {
+  queue: true,  
+  cacheResponse: false,
+  maxRequests: {/literal}{$maxRequests}{literal},
+  preventDoubleRequests: false
+});
+
+function add_thumbnail_to_queue(img, loop) {
+  thumbnails_queue.add({
+    type: 'GET', 
+    url: img.data('src'), 
+    data: { ajaxload: 'true' },
+    dataType: 'json',
+    beforeSend: function(){jQuery('.loader').show()},
+    success: function(result) {
+      img.attr('src', result.url);
+      jQuery('.loader').hide();
+    },
+    error: function() {
+      if (loop < 3)
+        add_thumbnail_to_queue(img, ++loop); // Retry 3 times
+      img.attr('src', {/literal}"{$ROOT_URL}{$themeconf.icon_dir}/errors_small.png"{literal});
+      jQuery('.loader').hide();
+    }
+  }); 
+}
+
+function pwg_ajax_thumbnails_loader() {
+  jQuery('img[data-src]').each(function() {
+    add_thumbnail_to_queue(jQuery(this), 0);
+  });
+}
+jQuery(document).ready(pwg_ajax_thumbnails_loader);
+{/literal}{/footer_script}
+{assign var=js_loaded value=true}
 {/if}
-	<li class="{if $smarty.foreach.cat_loop.index is odd}odd{else}even{/if}">
+  <li class="{if $smarty.foreach.cat_loop.index is odd}odd{else}even{/if}">
 		<div class="thumbnailCategory">
 			<div class="illustration">
 			<a href="{$cat.URL}">
-				<img {if $derivative->is_cached()}src="{$derivative->get_url()}"{else}src="{$ROOT_URL}{$themeconf.img_dir}/ajax-loader-small.gif" data-src="{$derivative->get_url()}"{/if} alt="{$cat.TN_ALT}" title="{$cat.NAME|@replace:'"':' '|@strip_tags:false} - {'display this album'|@translate}">
+				<img {if $derivative->is_cached()}src="{$derivative->get_url()}"{else}src="{$ROOT_URL}{$themeconf.icon_dir}/img_small.png" data-src="{$derivative->get_url()}"{/if} alt="{$cat.TN_ALT}" title="{$cat.NAME|@replace:'"':' '|@strip_tags:false} - {'display this album'|@translate}">
 			</a>
 			</div>
Index: /trunk/themes/default/template/thumbnails.tpl
===================================================================
--- /trunk/themes/default/template/thumbnails.tpl	(revision 20160)
+++ /trunk/themes/default/template/thumbnails.tpl	(revision 20161)
@@ -24,7 +24,43 @@
 {foreach from=$thumbnails item=thumbnail}
 {assign var=derivative value=$pwg->derivative($derivative_params, $thumbnail.src_image)}
-{if !$derivative->is_cached()}
+{if !$derivative->is_cached() and !$js_loaded}
 {combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js' load='footer'}
-{combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'}
+{*combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'*}
+{footer_script}{literal}
+var thumbnails_queue = jQuery.manageAjax.create('queued', {
+  queue: true,  
+  cacheResponse: false,
+  maxRequests: {/literal}{$maxRequests}{literal},
+  preventDoubleRequests: false
+});
+
+function add_thumbnail_to_queue(img, loop) {
+  thumbnails_queue.add({
+    type: 'GET', 
+    url: img.data('src'), 
+    data: { ajaxload: 'true' },
+    dataType: 'json',
+    beforeSend: function(){jQuery('.loader').show()},
+    success: function(result) {
+      img.attr('src', result.url);
+      jQuery('.loader').hide();
+    },
+    error: function() {
+      if (loop < 3)
+        add_thumbnail_to_queue(img, ++loop); // Retry 3 times
+      img.attr('src', {/literal}"{$ROOT_URL}{$themeconf.icon_dir}/errors_small.png"{literal});
+      jQuery('.loader').hide();
+    }
+  }); 
+}
+
+function pwg_ajax_thumbnails_loader() {
+  jQuery('img[data-src]').each(function() {
+    add_thumbnail_to_queue(jQuery(this), 0);
+  });
+}
+jQuery(document).ready(pwg_ajax_thumbnails_loader);
+{/literal}{/footer_script}
+{assign var=js_loaded value=true}
 {/if}
 <li>
@@ -32,5 +68,5 @@
 		<span class="wrap2">
 		<a href="{$thumbnail.URL}">
-			<img class="thumbnail" {if $derivative->is_cached()}src="{$derivative->get_url()}"{else}src="{$ROOT_URL}{$themeconf.img_dir}/ajax-loader-small.gif" data-src="{$derivative->get_url()}"{/if} alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
+			<img class="thumbnail" {if $derivative->is_cached()}src="{$derivative->get_url()}"{else}src="{$ROOT_URL}{$themeconf.icon_dir}/img_small.png" data-src="{$derivative->get_url()}"{/if} alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
 		</a>
 		</span>
Index: /trunk/themes/default/themeconf.inc.php
===================================================================
--- /trunk/themes/default/themeconf.inc.php	(revision 20160)
+++ /trunk/themes/default/themeconf.inc.php	(revision 20161)
@@ -4,4 +4,5 @@
   'icon_dir'      => 'themes/default/icon',
   'img_dir'      => 'themes/default/images',
+  'loading_img'      => 'themes/default/images/359_s.png',
   'mime_icon_dir' => 'themes/default/icon/mimetypes/',
   'local_head'    => 'local_head.tpl',
