//preload images
mpRes1 = new Image(166, 166);
mpRes1.src = "/images/mainpage/wd_mp_photo_residential01.jpg";

mpRes2 = new Image(166, 166);
mpRes2.src = "/images/mainpage/wd_mp_photo_residential02.jpg";

//mpSec1 = new Image(166, 166);
//mpSec1.src = "/images/mainpage/wd_mp_photo_sectional01.jpg";

mpSec2 = new Image(166, 166);
mpSec2.src = "/images/mainpage/wd_mp_photo_sectional02.jpg";        

//mpRol1 = new Image(166, 166);
//mpRol1.src = "/images/mainpage/wd_mp_photo_rolling01.jpg";

mpRol2 = new Image(166, 166);
mpRol2.src = "/images/mainpage/wd_mp_photo_sectional03.jpg";          

//setup targets to rotate
target1 = new Array();
target1[0] = mpRes1.src;
target1[1] = mpRes2.src;
target1[2] = "mpRes";

target2 = new Array();
//target2[0] = mpSec1.src;
//target2[1] = mpSec2.src;
//target2[2] = "mpSec";
target2[0] = mpSec2.src;
target2[1] = "mpSec";


target3 = new Array();
//target3[0] = mpRol1.src;
//target3[1] = mpRol2.src;
//target3[2] = "mpRol";
target3[0] = mpRol2.src;
target3[1] = "mpRol";

targets = new Array();
targets[0] = target1;
targets[1] = target2;
targets[2] = target3;

targetsLEN = new Array();
targetsLEN[0] = (target1.length-2);
targetsLEN[1] = (target2.length-2);
targetsLEN[2] = (target3.length-2);

//speed of rotation
var pause = 700 ;

//figure out which random image to display for each target
var numberOfTargets = (targets.length-1);
var targetINDEX = Math.round(Math.random() * numberOfTargets);
var imageINDEX = Math.round(Math.random() * targetsLEN[targetINDEX]);
var target = targets[targetINDEX];
var place = target[targetsLEN[targetINDEX]+1];
var pic = target[imageINDEX];

function display() {
  targetINDEX = Math.round(Math.random() * numberOfTargets);
  imageINDEX = Math.round(Math.random() * targetsLEN[targetINDEX]);
  target = targets[targetINDEX];
  place = target[targetsLEN[targetINDEX]+1];
  pic = target[imageINDEX];
  window.document.images[place].src=pic;
}

function startDisplay()  {
  window.setInterval('display()', pause);
}