var seconds = 3.5;
var imageGroup = new Array( "images/gallery/fabrication.jpg", "images/gallery/kitchens.jpg", "images/gallery/beltguard.jpg", "images/gallery/artistic.jpg");
var thisImage = -1;
var imageTimeout = null;

window.onload = initImages;

function initImages() {
	var div = document.createElement("div");
	div.style.fontWeight = "bold";
	div.style.width = "25px";
	div.style.position = "relative";
	div.style.textAlign = "center";
	div.style.top = "-300px";
	div.style.left = "990px";
	div.style.padding = "1px";
	
	//div.appendChild(createImageButton("<<", "prev"));
	//div.appendChild(document.createElement("br"));
	for (var i=0; i<imageGroup.length; i++) {
		div.appendChild(createImageButton(i+1, i));
		div.appendChild(document.createElement("br"));
	}
	//div.appendChild(createImageButton(">>", "next"));
	
	document.getElementById("page").appendChild(div);
	
	swapImage();
}

function createImageButton(text, index) {
	var a = document.createElement("a");
	a.href = "#nowhere";
	a.rel = "nofollow";
	a.onclick = function() { swapImage(index); return false; };
	a.appendChild(document.createTextNode(text));
	a.style.color = "#FFFFFF";
	a.style.textDecoration = 'none';
	a.style.padding = "0px 4px";
	a.id = "img_" + index;
	return a;
}

function swapImage(index) {
	clearTimeout(imageTimeout);
	
	if (index == null || index == "next") {
		thisImage++;
	} else if (index == "prev") {
		thisImage--;
	} else {
		thisImage = parseInt(index, 10);
	}
	
	if (thisImage < 0) {
		thisImage = imageGroup.length - 1;
	}
	if (thisImage == imageGroup.length) {
		thisImage = 0;
	}
	
	document.getElementById("imageHolder").src = imageGroup[thisImage];
	
	for (var i=0; i<imageGroup.length; i++) {
		var a = document.getElementById("img_" + i);
		if (i == thisImage) {
			a.style.backgroundColor = "#EFEFEF";
			a.style.color = "#11254A";
			a.style.border = "1px solid #003490";
		} else {
			a.style.backgroundColor = "";
			a.style.color = "#FFFFFF";
			a.style.border = "1px solid transparent";
		}
	}
	
	if (index == null) {
		imageTimeout = setTimeout("swapImage()",seconds*1000);
	}
}

