// Save this as banner.js
// change the image paths in the image_list array
// change the anchors in the anchor_list array<!-- Begin
var interval = 5; // delay between rotating images (in seconds)
interval *= 1000;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("banners/banner_HWM_new_small.jpg");
image_list[image_index++] = new imageItem("banners/chiltern_2.jpg");
image_list[image_index++] = new imageItem("banners/autosport_des.gif");
image_list[image_index++] = new imageItem("banners/trinity_banner.gif");
image_list[image_index++] = new imageItem("banners/cummings.gif");
image_list[image_index++] = new imageItem("banners/rikki_banner.jpg");
image_list[image_index++] = new imageItem("banners/advert.jpg");
image_list[image_index++] = new imageItem("banners/steel_wings.jpg");
image_list[image_index++] = new imageItem("banners/r2.jpg");
image_list[image_index++] = new imageItem("banners/holt.jpg");
var anchor_index = 0;
anchor_list = new Array();
anchor_list[anchor_index++] = "http://www.hwmastonmartin.co.uk/parts/aston-martin-parts.asp ";
anchor_list[anchor_index++] = "http://www.db7centre.co.uk";
anchor_list[anchor_index++] = "http://www.autosportdesigns.com";
anchor_list[anchor_index++] = "http://www.trinityastonmartin.co.uk";
anchor_list[anchor_index++] = "http://www.cummingsofbodmin.co.uk/stock-astonmartin.htm";
anchor_list[anchor_index++] = "http://www.rikkicann.com";
anchor_list[anchor_index++] = "http://www.astonmartins.com/advertise.htm";
anchor_list[anchor_index++] = "http://www.steelwings.com";
anchor_list[anchor_index++] = "http://www.runnymedemotorcompany.com/";
anchor_list[anchor_index++] = "http://www.astonmartins.com/holt/index.html";
var number_of_image = image_list.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) {
	//image_index = generate(0, number_of_image-1);
	var new_image = get_ImageItemLocation(image_list[image_index]);
	return(new_image);
}

function rotateImage(place,anchor) {
var index=0;
index = generate(0, number_of_image-1);
	var new_image = getNextImage(index);
	document[place].src = new_image;
	document.anchors[0].href = anchor_list[index];
	//alert ( index);
	var recur_call = "rotateImage('" + place + "','" + anchor +"')";
	setTimeout(recur_call, interval);
}
//  End -->

