var start = 0;
var photoTimeOutId = 0;
var preload = Array();
var preloadf = Array();

function rollPhotosPreload(n, path)
{
 for(i=1;i<=n;i++)
 {
  preload.push(new Image());
  preload[i-1].src = path + "thumbs/" + i + ".jpg";
 }
 
 for(i=1;i<=n;i++)
 {
  preloadf.push(new Image());
  preloadf[i-1].src = path + i + ".jpg";
 }
}

function loadPhotos(colls, rows, width, height, astyle, divstyle, n, path)
{
 if(!photoTimeOutId)
 {
  $('div#Photos').hover(function(){window.clearTimeout(photoTimeOutId);}, function(){photoTimeOutId = window.setTimeout("loadPhotos(" + colls + ", " + rows + ", " + width + ", " + height + ", '" + astyle + "', \"" + divstyle + "\", " + n + ", '" + path + "')", 2000);}).css('width', (colls*(width+5))+'px').css(divstyle);
  rollPhotosPreload(n, path);
 }

 if(!start) start = colls+1;

 var html = "";
 var cnt = 0;
 for(i=0;i < colls*rows & (i+start) <= n ;i++)
 {
  cnt++;
  html = html + '<a style="width:' + width + 'px;height:' + height + 'px;' + astyle + '" href="' + path + (start + i) + '.jpg" rel="facebox"><img src="' + path + 'thumbs/' + (start + i) + '.jpg" alt="" height="' + height + '" width="' + width + '" /></a>'
 }
 start = start + colls > n ? 1 : start + colls;
 if(cnt < colls*rows)
 {
  for(i=0;i<colls*rows-cnt;i++)
  {
   html = html + '<a style="width:' + width + 'px;height:' + height + 'px;' + astyle + '" href="' + path + (1 + i) + '.jpg" rel="facebox"><img src="' + path + 'thumbs/' + (1 + i) + '.jpg" alt="" height="' + height + '" width="' + width + '" /></a>'
  }
 }
 photoTimeOutId = window.setTimeout("loadPhotos(" + colls + ", " + rows + ", " + width + ", " + height + ", '" + astyle + "', \"" + divstyle + "\", " + n + ", '" + path + "')", 2000);
 $("div#Photos").html(html);
 $('a[rel*=facebox]').facebox();
}

