var maximages = 6; 
var speed = 50; 

var intime;
var outime;
var incount = 0;
var outcount = maximages-1;
var pic = new Array(maximages); 
// the first item should be 0, then numbered through 1 less than your maximages

//pic[0] = "door0.jpg";
//pic[1] = "door1.jpg";
//pic[2] = "door2.jpg";
//pic[3] = "door3.jpg";
//pic[4] = "door4.jpg";
//pic[5] = "door5.jpg";

//for (var i = 0; i < maximages; i++) {
//eval('pic' + i + ' = new Image();');
//eval('pic' + i + '.src = pic[i];'); 
//}
function open_img() {
clearTimeout(outime);
document.images['pic'].src = pic[incount];
if (incount != maximages-1) {
incount++;
intime = setTimeout('open_img()', speed);
}
else {
clearTimeout(intime);
incount = 0;
   }
}
function close_img() {
clearTimeout(intime);
document.images['pic'].src = pic[outcount];
if (outcount != 0) {
outcount--;
outime = setTimeout('close_img()', speed);
}
else {
clearTimeout(outime);
outcount = maximages-1;
   }
}