var preloaded = new Array();

var current_video = -1;
var current_frame = -1;
var current_int = null;

function dim() {
	document.getElementById('dimmer_div').style.display = '';
	document.getElementById('previewbox').style.display = '';
}
function undim() {
	document.getElementById('dimmer_div').style.display = 'none';
	document.getElementById('previewbox').style.display = 'none';
}

function anim_rollon(which) {
	preload_images(which);
	current_video = which;
	current_frame = 0;
	current_int = setInterval("nextframe()", 500);
}

function nextframe() {
	++current_frame;
	if (!anim_frames[current_video][current_frame]) current_frame = 0;
	
	video = document.getElementById('anim_' + current_video);
	video.src = anim_frames[current_video][current_frame];
}

function anim_rollout() {
	video = document.getElementById('anim_' + current_video);
	video.src = anim_frames[current_video][0];
	current_video = -1;
	current_frame = -1;
	clearInterval(current_int);
	current_int = null;
}

function preload_images(which) {
	if (!preloaded[which]) preloaded[which] = new Array();
	
	for (var idx in anim_frames[which]) {
		if (!preloaded[which][idx]) {
			preloaded[which][idx] = new Image();
			preloaded[which][idx].src = anim_frames[which][idx];
		}
	}
}
