function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function validate_form_contact(){
	var my_form = document.form_contact;
	var error = 0;
	my_form.contact_name.style.backgroundColor='#ffffff';
	my_form.contact_email.style.backgroundColor='#ffffff';
	my_form.contact_message.style.backgroundColor='#ffffff';
	if (my_form.contact_name.value==''){
		my_form.contact_name.style.backgroundColor='#d4dbe2';
		error = 1;
		
	}
	if (!isValidEmailAddress(my_form.contact_email.value)){
		my_form.contact_email.style.backgroundColor='#d4dbe2';
		error = 1;
		
	}
	if (my_form.contact_message.value==''){
		my_form.contact_message.style.backgroundColor='#d4dbe2';
		error = 1;
		
	}
	if (error == 1){
		alert('Please fill in the highlighted fields');
		return false;
	}
	else{
		return true;
	}
}

var home = new Array();
home[0] = ['images/home_01.png','The Strategic Link<br />Supporting your business'];
home[1] = ['images/home_02.png','The Strategic Link<br />Your distribution partner'];
home[2] = ['images/home_03.png','The Strategic Link<br />Investing in the future'];


var nexth = 0;

function start_autoplay(){
	stop_autoplay();
	timerID = setInterval("change_home("+nexth+");",10000);
}

function stop_autoplay(){
	if(typeof(timerID) !== 'undefined'){
		clearInterval(timerID);
	}
}

function change_home(id){
	var elem1 = "home_topcb1";
	var elem2 = "home_topcb2";
	if ($("#home_topcb2").is(":hidden")){
		elem1 = "home_topcb2";
		elem2 = "home_topcb1";
	}
	$("#"+elem2).css({"z-index":30});
	$("#"+elem1).css({"z-index":40});
	$("#"+elem1+' .home_topci').html('<span style="width:980px;height:289px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+home[id][0]+'\');"><img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="'+home[id][0]+'" width="980" height="289" border="0" alt="Chemco" /></span>');
	$("#"+elem1+' .home_topcc').html(home[id][1]);
	var img = new Image();
	var src = home[id][0];
	$(img).load(function () {
		$("#"+elem1).fadeIn(600,function(){
			$("#"+elem2).css({"display":"none"});
			nexth = (id+1<home.length)?id+1:0;
			start_autoplay();
		});
	}).error(function () {

	}).attr('src', src);
}

$(document).ready(function(){
	change_home(nexth);
	start_autoplay();
});