
function swap_pic(pic_id) {
	document.getElementById('big_pic').src='../uploads/products/range_'+ pic_id + '_large.jpg';
}

function selected_pic(oSelect) {
	swap_pic(oSelect.options[oSelect.selectedIndex].value);
}

function clicked_pic(pic_id) {
	// change the select to the correct item
	oSelect = document.getElementById('pic_select');
	for(var i=0; i<= oSelect.options.length-1; i++) {
		if(oSelect.options[i].value == pic_id) {
			swap_pic(pic_id);
			oSelect.selectedIndex = i;
		}
	}
	scroll(0,0);
}

function validateEmail(email_address) {
	if (/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
		return true;
	}
	return false;
}

function verifyContactForm() {

	var onErrorAlert		= true;
	var onErrorMessage	= true;
	var errorMessages		= new Array();
	var focused					= false;
	var formObj					= document.contactForm;

	if (formObj.name.value == '') {
		errorMessages.push('Please enter your name');
		if(!focused){
			formObj.name.focus();
			focused = true;
		}
	}

	if (!validateEmail(formObj.email.value)) {
		errorMessages.push('Please enter a valid email address');
		if(!focused){
			formObj.email.focus();
			focused = true;
		}
	}
	
	if (formObj.address.value == '') {
		errorMessages.push('Please enter your address');
		if(!focused){
			formObj.address.focus();
			focused = true;
		}
	}
	
	if (formObj.postcode.value == '') {
		errorMessages.push('Please enter your postcode');
		if(!focused){
			formObj.postcode.focus();
			focused = true;
		}
	} 
	
	if (formObj.telephone.value == '') {
		errorMessages.push('Please enter your telephone number');
		if(!focused){
			formObj.telephone.focus();
			focused = true;
		}
	}

	if (formObj.comments.value == '') {
		errorMessages.push('Please enter your comments');
		if(!focused){
			formObj.comments.focus();
			focused = true;
		}
	}

	if(errorMessages.length != 0){
		if(onErrorAlert){
				alert(errorMessages[0]);
		}
		if(onErrorMessage){
				oErrorDiv = document.getElementById("error_messages");
				oErrorDiv.innerHTML = "There was a problem with the information you supplied:<br />";
				for(var i=0; i<errorMessages.length; i++){
					oErrorDiv.innerHTML += "<li>" + errorMessages[i] + "</li>";
				}
				oErrorDiv.style.display = "block";
		}
		return false;

	} else {
		// copy the recipients email address to the hidden field
		// so that it can be seen in the body of the email
		// as well as in the senders field
		formObj.Email.value = formObj.h_fromemail.value;
		return true;
	}

}

var image_nav = new Array();
image_nav[0] = "http://www.decrofloor.com/pics/nav_home2.gif";
image_nav[1] = "http://www.decrofloor.com/pics/nav_gallery2.gif";
image_nav[2] = "http://www.decrofloor.com/pics/nav_products2.gif";
image_nav[3] = "http://www.decrofloor.com/pics/nav_clients2.gif";
image_nav[4] = "http://www.decrofloor.com/pics/nav_findus2.gif";
image_nav[5] = "http://www.decrofloor.com/pics/nav_contact2.gif";

var image_anim = new Array();
image_anim[0] = "http://www.decrofloor.com/pics/leftpic_01.jpg";
image_anim[3] = "http://www.decrofloor.com/pics/leftpic_05.jpg"; // g
image_anim[2] = "http://www.decrofloor.com/pics/leftpic_03.jpg";
image_anim[1] = "http://www.decrofloor.com/pics/leftpic_04.jpg"; // g
image_anim[4] = "http://www.decrofloor.com/pics/leftpic_02.jpg";
image_anim[5] = "http://www.decrofloor.com/pics/leftpic_07.jpg"; // g
image_anim[6] = "http://www.decrofloor.com/pics/leftpic_06.jpg";

function preload_image_array(image_array) {
	// image pre-loader
	if (document.images) {
		preload_image_object = new Image();
		var i = 0;
		// var str = '';
		for(i=0; i<=image_array.length-1; i++) {
			// str += image_array[i] + "\n";
			preload_image_object.src = image_array[i];
		}
	}
	// alert(str);
}


var anim_count = 0;
var anim_image = null;
var anim_delay = 2000;

function animate_image(){
	var next_image = (anim_count % (image_anim.length-1) ) + 1;
	// dont swap on the first run
	if(anim_image == null) {
		// dom not quite loaded on page load
		anim_image = document.getElementById('animation');
	}
	anim_image.src = image_anim[next_image];
	anim_count++;
	setTimeout("animate_image()",anim_delay);
}


function init() {
	// preload navigation images
	preload_image_array(image_nav);
	// preload animation images
	preload_image_array(image_anim);
}

window.onload = init();



