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, cnt, num){
  if (typeof(preloadedimages[id][num])!='undefined')
	return;
  next_pic = (num% cnt) + 1;	
  pic = new Image();
  pic.src = path+"br"+next_pic+".jpg";
  preloadedimages[id][num]= pic;
}

function showimage(path, id, cnt, num){
  if (!isloaded(preloadedimages[id][num])){
	timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 10);
	return;
  }
  document.getElementById('pic'+id).src=preloadedimages[id][num].src;
  
  if(++num==cnt) 
	num = 0;
  loadimage(path, id,cnt, num);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+num+")", 500);
}

function startPreview(id, cnt, start){
//alert(id);
  ind= start -1;
  path="http://static.brazzers.com/scenes/" + id + "/";
  
  if (typeof(preloadedimages[id])=='undefined')
	preloadedimages[id]=new Array();
  loadimage(path, id, cnt, ind);
  timeouts[id]=setTimeout("showimage('"+path+"', "+id+", "+cnt+", "+ind+")", 0);
}

function stopPreview(id, start){
  clearTimeout(timeouts[id]);
  if (typeof(preloadedimages[id][start-1])=='undefined') {
	ind = start +1;
	pic = new Image();
	pic.src = path+"br"+ind+".jpg";
	preloadedimages[id][start-1]= pic;
  } else {
	pic = preloadedimages[id][start-1];
  }
  document.getElementById('pic'+id).src=pic.src;
}



