/* 
 * JavaScript Document
 * Author Martyn Clark
 * portwebsolutions.co.uk
 * 
 * Loads images into an array
 * and allows the user to click
 * through the images with added captions.
 *
 */
var currImg = 0;
var captionText = new Array("This is before Restorations began there work on this building.", 
							"During the various stages of reconstuction.", "The completed project with very happy customers.", 
							"Kitchen being made ready for a complete refit.", "completed with another happy customer", "Outside garden landscaping undertaken.", "The results of a striped and repolished floor.");
function initLinks() {
	if(document.getElementById || document.createTextNode) {
		document.getElementById("caption").innerHTML = captionText[0];
		document.getElementById("Previous"). onclick = Previous;
		document.getElementById("Next"). onclick = Next;
	}
	return false;
}


function Previous() {
	newSlide(-1);
	return false;
}


function Next() {
	newSlide(1);
	return false;
}
function newSlide(direction) {
	var imgCrt = captionText.length;
	if(document.getElementById) {
	currImg = currImg + direction;
	if(currImg < 0 ) {
		currImg = imgCrt -1;
	}
	if(currImg == imgCrt) {
		currImg = 0;
	}
	document.getElementById("slide").src = "images/slide" + currImg + ".jpg";
	document.getElementById("caption").innerHTML = captionText[currImg];
	}
	return false;
}
/*
 * Function for adding events on window.onload event
 */
function addLoadEvent(func) {
	var oldonLoad = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonLoad();
			func();
		}
	}
}
addLoadEvent(initLinks);

/*
 * Cross-browser event handler
 */
function addEvent(element, eventType, calledFunction, useCapture) {
	if(element.addEventListener) {
		element.addEventListener(eventType, calledFunction, useCapture);
		return true;
	} else {
		return false;
	}
}
		