function submitform() {
	// form validation
	var error = false;

	if (document.contact.name.value.length<1) {
		$("#contactname").html('<img src="/images/public/alert.gif" width="20" height="16" />');
		error=true;
	}
	if (!validEmail(document.contact.real_email.value)) {
		$("#contactemail").html('<img src="/images/public/alert.gif" width="20" height="16" />');
		error=true;
	}

	if (error) {
		return false;
	}

	return true;

}

function displaySending() {
	$("#contactform").html('<h1>Sending</h1><img src="/images/public/loadingAnimation.gif" /><br /><br />');
	$("#getintouchbutton").css('background-image','none');
}

function postData() {
	$.post("/processform.php", {
		name:document.contact.name.value,
		company:document.contact.company.value,
		type:document.contact.type.selectedIndex,
		town:document.contact.town.value,
		real_email:document.contact.email.value,
		phone:document.contact.phone.value,
		website:document.contact.website.value,
		how:document.contact.how.selectedIndex,
		project_branding:document.contact.project_branding.checked,
		project_design:document.contact.project_design.checked,
		project_redesign:document.contact.project_redesign.checked,
		project_cms:document.contact.project_cms.checked,
		project_ecommerce:document.contact.project_ecommerce.checked,
		project_flash:document.contact.project_flash.checked,
		project_marketing:document.contact.project_marketing.checked,
		project_hosting:document.contact.project_hosting.checked,
		comments:document.contact.comments.value
	}, delayDisplayComplete);
}

function delayDisplayComplete() {
	setTimeout("displayComplete()", 1000);
}

function displayComplete() {
	$("#contactform").html('<h1>Sent. Thank You.</h1>');
	//pageTracker._trackPageview("/contact/step3.html");
	setTimeout("closePanel()", 2000);
}

function closePanel() {
	$("#contactform").slideUp("slow");
	$("#getintouchbutton").css('background-image','url(/images/public/getintouch-sent.gif)');
}

function checkvalid(ref, name) {
	switch (name) {
		case "contactname":
			if (ref.value.length>=1) $("#contactname").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contactname").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
		case "contacttype":
			if (ref.selectedIndex) $("#contacttype").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contacttype").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
		case "contactemail":
			if (validEmail(ref.value)) $("#contactemail").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contactemail").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
		case "contacthow":
			if (ref.selectedIndex) $("#contacthow").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contacthow").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
	}
}

function validEmail(s) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(s) == false) {
		return false;
	} else {
		return true;
	}
}

function toggleContactForm() {
	/*
	if ($("#contactform:first").is(":hidden")) {
		$("#contactform").html($("#contactformframe"));
		$("#contactformframe").show();
		$("#contactform").slideDown("slow");
		$("#getintouchbutton").css('background-image','url(/images/public/closeform.gif)');
		//pageTracker._trackPageview("/contact/step1.html");
	} else {
		$("#getintouchbutton").css('background-image','url(/images/public/getintouch.gif)');
		$("#contactform").slideUp("slow");
	}
	*/
	var $cform = $("#contactform"),
		$cframe = $("#contactformframe");
	if($cform.hasClass('closed'))
	{
		$cform.html($cframe);
		$cform.animate({
			"height": 257
		}, 500, function(){
			$(this).removeClass('closed').addClass('open');
			$cframe.fadeIn();
		});
	}
	else
	{
		$cframe.fadeOut(function(){
			$cform.animate({
				"height": 0
			}, 1000).removeClass('open').addClass('closed');
		});
	}


}

var names = new Array('intro','what','who','why');
function changePanel(id) {
	for (var i=0; i<=3; i++) {
		if (i==id) {
			turnOn('homepage-panel-'+names[i]);
			changeBackgroundImage('homepage-tab-'+names[i], '/images/public/homepage-tabs/'+names[i]+'-on.gif');
		} else {
			turnOff('homepage-panel-'+names[i]);
			changeBackgroundImage('homepage-tab-'+names[i], '/images/public/homepage-tabs/'+names[i]+'-off.gif');
		}
	}
}

function changeBackgroundImage(DivID, Image) {
	document.getElementById(DivID).style.backgroundImage = 'url('+Image+')';
}

// turn off function
function turnOff(DivID) {
	if (document.getElementById) { //gecko(NN6) & IE 5+
		document.getElementById(DivID).style.visibility = "hidden";
		document.getElementById(DivID).style.display = "none";
	} else if (document.all) { // IE 4+
		document.all[DivID].style.visibility = "hidden";
		document.all[DivID].style.display = "none";
	} else if (document.layers) { // NS4+
		document.layers[DivID].visibility = "hide";
		document.layers[DivID].display = "none";
	} else {
		// nothing
	}
}

// turn on function
function turnOn(DivID) {
	if (document.getElementById) { //gecko(NN6) & IE 5+
		document.getElementById(DivID).style.visibility = "visible";
		document.getElementById(DivID).style.display = "block";
	} else if (document.all) { // IE 4+
		document.all[DivID].style.visibility = "visible";
		document.all[DivID].style.display = "block";
	} else if (document.layers) { // NS4+
		document.layers[DivID].visibility = "show";
		document.layers[DivID].display = "block";
	} else {
	}
}


$(document).ready(function(){

	if($('#banner').length){

		var $tabs = $('#banner'), $panels = $('#banner div');

		$tabs.tabs({fx:{opacity: 'toggle'}}).tabs('rotate', 19000, true);

		$panels.hover(
			function(){
				/*$tabs.tabs('pause'); */
			},
			function(){
				/* $tabs.tabs('unpause'); */
			}
		);
	}
})

