var frame1 = Math.floor(Math.random() * 10);
var pictures = new Array(10);
pictures[0] = new Image();
pictures[0].src = "idx1.jpg";
pictures[1] = new Image();
pictures[1].src = "idx2.jpg";
pictures[2] = new Image();
pictures[2].src = "idx3.jpg";
pictures[3] = new Image();
pictures[3].src = "idx4.jpg";
pictures[4] = new Image();
pictures[4].src = "idx5.jpg";
pictures[5] = new Image();
pictures[5].src = "idx6.jpg";
pictures[6] = new Image();
pictures[6].src = "idx7.jpg";
pictures[7] = new Image();
pictures[7].src = "idx8.jpg";
pictures[8] = new Image();
pictures[8].src = "idx9.jpg";
pictures[9] = new Image();
pictures[9].src = "idx10.jpg";

var csteps = 25;
var TimeToFade = 300.0;
var curState = TimeToFade;
var speed = TimeToFade/csteps;
var opVal = 0;
var topdiv = 1;
var oldIm = '' ;
var newIm = '' ;
start_animate();


function start_animate()
{
	curState = TimeToFade;
	if (topdiv == 1) {		// d1 visible, fade in d2
		newIm = document.getElementById('indexpic2');
		document.picInDiv2.src = pictures[frame1].src;
		oldIm = document.getElementById('indexpic1') ;
		
	}
	else {
		newIm = document.getElementById('indexpic1');
		document.picInDiv1.src = pictures[frame1].src;
		oldIm = document.getElementById('indexpic2') ;
	}
	fadeIn();
	oldIm.style.zIndex = 10;
	newIm.style.zIndex = 20;
	setTimeout("oldIm.style.opacity = 0;", 4500);
	setTimeout("oldIm.style.filter = 'alpha(opacity = 0)';", 4500);
	frame1 = Math.floor(Math.random() * 10);
	topdiv = topdiv == 1 ? 0 : 1 ;
	setTimeout("start_animate()", 4500);
}

function fadeIn(){
	curState = curState - speed;
	opVal = curState / TimeToFade;
	opVal = 1 - opVal;
	if (curState > 0) {
		newIm.style.opacity = opVal;
		newIm.style.filter = 'alpha(opacity = ' + (opVal * 100) + ')';
		setTimeout('fadeIn()', speed);
	}
	else {
		newIm.style.opacity = 1;
		newIm.style.filter = 'alpha(opacity = 100)';
	}
}

