var interval = 6; // delay between rotating images (in seconds)
interval *= 1000;

image_list_group_a = new Array();
image_list_group_a[0] = new imageItem("images/simple_no_cost_1.jpg");
image_list_group_a[1] = new imageItem("images/simple_no_cost_2.jpg");
image_list_group_a[2] = new imageItem("images/simple_no_cost_3.jpg");
var number_of_image_group_a = image_list_group_a.length;

image_list_group_b = new Array();
image_list_group_b[0] = new imageItem("images/conduct_energy_audit_1.jpg");
image_list_group_b[1] = new imageItem("images/conduct_energy_audit_2.jpg");
image_list_group_b[2] = new imageItem("images/conduct_energy_audit_3.jpg");
var number_of_image_group_b = image_list_group_b.length;

image_list_group_c = new Array();
image_list_group_c[0] = new imageItem("images/long_term_investments_1.jpg");
image_list_group_c[1] = new imageItem("images/long_term_investments_2.jpg");
image_list_group_c[2] = new imageItem("images/long_term_investments_3.jpg");
var number_of_image_group_c = image_list_group_c.length;


function imageItem(image_location) {
	this.image_item = new Image();
	this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj) {
	return(imageObj.image_item.src)
}

function generate(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}


function getNextImage() {
	image_index_group_a = generate(0, number_of_image_group_a-1);
	image_index_group_b = generate(0, number_of_image_group_b-1);
	image_index_group_c = generate(0, number_of_image_group_c-1);

	new_image_group = new Array();
	new_image_group[0] = get_ImageItemLocation(image_list_group_a[image_index_group_a]);
	new_image_group[1] = get_ImageItemLocation(image_list_group_b[image_index_group_b]);
	new_image_group[2] = get_ImageItemLocation(image_list_group_c[image_index_group_c]);
	return(new_image_group);
}

function rotateImage(placeA,placeB,placeC) {
	new_image = new Array();
	new_image = getNextImage();
	
	//alert('DEBUG:'+'\n new_image[0]='+new_image[0]+'\n new_image[1]='+new_image[1]+'\n new_image[2]='+new_image[2]);

    document.getElementById(placeA).src = new_image[0];
    document.getElementById(placeB).src = new_image[1];
    document.getElementById(placeC).src = new_image[2];

/*	document[placeA].src = new_image[0];
	document[placeB].src = new_image[1];
	document[placeC].src = new_image[2];
*/
	var recur_call = "rotateImage('"+placeA+"','"+placeB+"','"+placeC+"')";
	setTimeout(recur_call, interval);
}






