thumbsDir=new Array();
thumbsArray=new Array();
preloadedimages=new Array();
timeouts=new Array();

function isloaded(img) {
  if (!img.complete)
  	return false;
  if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0)
  	return false;
  return true;
}

function loadimage(path, id, num){
  if (typeof(preloadedimages[id][num])!='undefined')
    return;
  preloadedimages[id][num]=new Array();
  preloadedimages[id][num].src='url('+path+thumbsArray[id][num]+')';
  preloadedimages[id][num].url=path+thumbsArray[id][num];
}

function showimage(path, id, cnt, num){
	document.getElementById('img_src_'+id).style.backgroundImage=preloadedimages[id][num].src;
	if (++num==cnt)
    num=0;
	loadimage(path, id, num);
	timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 500);
}

function startPreview(id){
  path=thumbsDir[id];
  num=thumbsArray[id].length;
  if (typeof(preloadedimages[id])=='undefined')
    preloadedimages[id]=new Array();
  loadimage(path, id, 1);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+num+", 1)", 500);
  loadimage(path, id, 0);
}

function stopPreview(id){
  clearTimeout(timeouts[id]);
  document.getElementById('img_src_'+id).style.backgroundImage=preloadedimages[id][0].src;
}
