// JavaScript Document

// ---------------- Define preload function ----------------
var preloaded = new Array();
function preload_images() {
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
};

// ---------------- Define insert image variable for loop function ----------------
var change_image_num = 0;

// ---------------- Intialise images array ----------------
var images = 'images/loopimages/lincoln_cathedral.jpg,images/loopimages/sankt_augustin_retail_park.jpg,images/loopimages/simons_hq.jpg,images/loopimages/valentine_park.jpg,images/loopimages/the_junxion_lincoln.jpg,images/loopimages/the_glass_mill.jpg';
var images_array = images.split(",");
var image_num = 0;
while (image_num < images_array.length) {
	preload_images(images_array[image_num]);
	image_num+=1;
}

// ---------------- Intialise straplines array ----------------
var straplines = 'East Midlands Specialists,Retail Agents,Business Space Agents,Investment Agents,Development Advisors,Building Surveyors';
var straplines_array = straplines.split(",");

// ---------------- Define insert image function ----------------
function insertimage() {
	if (!document.getElementById) return false;
	if (!document.getElementById("project_image")) return false;
	var imagediv = document.getElementById("project_image");
	var straplinediv = document.getElementById("project_description");
	imagediv.innerHTML = '<img src=\"http://www.bankslong.com/'+images_array[change_image_num]+'\" alt="image" />';
	straplinediv.innerHTML = '<p>'+straplines_array[change_image_num]+'</p>';
	if (change_image_num < (images_array.length - 1)) {
		setTimeout("insertimage()",6000);
		change_image_num+=1;
	} else {
		change_image_num = 0;
		setTimeout("insertimage()",6000);
	}
}

function loop() {insertimage();}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(loop);