//GENERIC ADDLOAD EVENT FUNCTION
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
//////////////////////////////////

//Images and alt text - needs to be the same number in each
var images = new Array('http://www.drkivellandpartners.co.uk/stat/image1.jpg','http://www.drkivellandpartners.co.uk/stat/image2.jpg','http://www.drkivellandpartners.co.uk/stat/image3.jpg','http://www.drkivellandpartners.co.uk/stat/image4.jpg','http://www.drkivellandpartners.co.uk/stat/image5.jpg','http://www.drkivellandpartners.co.uk/stat/image6.jpg');

//Store current image number
var currentIndex = 0;

//Delay in milliseconds
var timeOutDelay = 4000;


//Initialise slideshow if the objects exist for it to work
function startSlideshow() {
	if (!document.getElementsByTagName || !document.getElementById || !document.getElementById('slideshow')) {
		return false;
	}
	counter();
}

//Recursive function to loop through images array and call the swapImage function after every timeOutDelay
function counter() { 
	if (currentIndex >= images.length) {
		//Reached the end so go back to beginning
		currentIndex = 0;
	}
	if ( currentIndex == 0 && images.length == 1 ) {
		//Swap first image
		swapImage(0);
	} else {
		//Swap next image
		swapImage(currentIndex++);
		//Start the delay before calling counter again
		window.setTimeout("counter()",timeOutDelay); 
	}		
}	

//function to swap the images src's
function swapImage(index) {
	//Find target image
	var target = document.getElementById('slideshow');
	//Get target images current src
	var currentsrc = 	target.getAttribute('src');
	//Get new src
	var newSrc = images[index];
	//if nextimage is different
	if (currentsrc != newSrc) {
		//Change src to swap image
		target.setAttribute('src',newSrc);
	}
}

//Add onload event to page
addLoadEvent(startSlideshow);

// Change the CLASS or ID of an element. 

function randomBkg(){
	var classes = new Array() //The array of different class names that you are going to switch between.
	classes[0]="right_column";
	classes[1]="right_column2";
	classes[2]="right_column3";
	classes[3]="right_column4";
	classes[4]="right_column5";
	classes[5]="right_column6";
	classes[6]="right_column7";


	upper_limit=6; //The maximum number of things you want to change at random. Should correspond to number of classes above.
	var randomId = Math.round(upper_limit * Math.random());  //The random number generator. Also works on lottery numbers.
	
	if (document.getElementById("right_column")){
		var theElement = document.getElementById("right_column");
		
		/* IF YOU ARE WANTING TO CHANGE A CLASS
		theElement.setAttribute("class", classes[randomId]); // Sets the class for Firefox and the nice browsers...
		theElement.setAttribute("className", classes[randomId]) //Sets the class for nasty ol' IE...*/
		
		/* IF YOU ARE WANTING TO CHANGE AN ID*/
		theElement.setAttribute("id", classes[randomId]); // Sets the id for ALL browsers. IE isn't as fussy about this one.)
	
	}
	else {return false;}
}

addLoadEvent(randomBkg);

//Creates a string containing a time-sensitive welcome greeting, which can be added to the onload event handler

function get_greeting()
{
	var theDate = new Date();
	var theHour = theDate.getHours();
	var greeting_text = "Welcome to";
	
	
		if (theHour < 7)
		{greeting_text = "An EARLY Good Morning and Welcome to";
		return greeting_text;
		}
		if (theHour > 6 && theHour <12)
		{greeting_text = "Good Morning and Welcome to";
		return greeting_text;
		}
		if (theHour > 11 && theHour <18)
		{greeting_text = "Good afternoon and welcome to";
		return greeting_text;
		}
		if (theHour >17)
		{greeting_text = "Good Evening and Welcome to";
		return greeting_text;
		}
}


//Adds the welcome greeting to the homepage

//This creates a "h2" element (change as appropriate) and appends the string from the previous function. 
//The difference with this one, is that a line break "br" is included in the middle, to give you a two-line greeting.

//Reference to "first_para" should be changed to the id of whatever element comes after the greeting.
//This is usually a paragraph, but it could be a picture, I suppose. 

//Reference to "Estate Agents" should be changed to your estate agent of choice... or a slogan of choice. Tis up to you. 

function homepageGreeting() {
	if (document.getElementById("bitmap")) {
		var greeting = document.createElement("h2");
		var greeting_text = document.createTextNode(get_greeting());
		
		greeting.appendChild(greeting_text);
		greeting.setAttribute("class", "firstpara"); // Sets the class for Firefox and the nice browsers...
		greeting.setAttribute("className", "firstpara"); //Sets the class for nasty ol' IE...*/
		
		var greeting_area = document.getElementById("bitmap");
		greeting_area.parentNode.insertBefore(greeting,greeting_area);
	} else {
		return false;
	}
}
addLoadEvent(homepageGreeting);