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 Image();
  preloadedimages[id][num].src=path+thumbsArray[id][num];
  //alert (path+thumbsArray[id][num]);
}

function showimage(path, id, cnt, num){
  if (!isloaded(preloadedimages[id][num])){
    //alert (path+", "+id+", "+cnt+", "+num);
    timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 50);
    return;
  }
  document.getElementById('img_src_'+id).src=preloadedimages[id][num].src;
  if (++num==cnt)
    num=0;
  loadimage(path, id, num);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 400);
}

function startPreview(id){
  path=thumbsDir[id];
  num=thumbsArray[id].length;
  //alert (path);
  

  if (typeof(preloadedimages[id])=='undefined')
    preloadedimages[id]=new Array();
  loadimage(path, id, 1);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+num+", 1)", 200);
  loadimage(path, id, 0);

  }

function stopPreview(id){
  clearTimeout(timeouts[id]);
  document.getElementById('img_src_'+id).src=preloadedimages[id][0].src;
}

function toggleDisplay (id) {
	if (document.getElementById(id).display == 'none') {
		document.getElementById(id).display = '';
	}
	else {
		document.getElementById(id).display = 'none';
	}
}