$(document).ready(function() {
 //******************************************LWO**********LWO********************************************
 //$(function() {  

//$('#coin-slider').coinslider({ width: 604, height: 401, navigation: true, delay: 7000, effect: 'straight', sDelay: 10, hoverPause: true  });
//$('#news').innerfade({ animationtype: 'slide', speed: 750, timeout: 2000, type: 'random', containerheight: '1em' }); 

$('#portfolio').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '345px' });







//$('.fade').innerfade({ speed: 'slow', timeout: 1000, type: 'sequence', containerheight: '1.5em' });

$("div.clickable").click( //this makes divs clickable (including any images in them), specify the url in the page , in the <div> tag. (in gallery.php for example)
function()
{
    window.location = $(this).attr("url");
});


//toggle
$('#influences').hide();//hide it first
$('#interests').hide();//hide it first

$('#target1').toggle(function() {
  $('#influences').fadeIn(500);
}, function() {
 $('#influences').fadeOut(500);
});

$('#target2').toggle(function() {
  $('#interests').fadeIn(500);
}, function() {
 $('#interests').fadeOut(500);
});
//end toggle


$('.box').mouseover(function() { //when mouse over the box div change the border
 $(this).removeClass("box").addClass("boxhighlight");
});

$('.box').mouseleave(function() { //when mouse leaves set it back again
 $(this).removeClass("boxhighlight").addClass("box");
 });


//for contact form
 $('.error').hide(); //hide error messages in contact form and mailing list form
 $('#successmessage').hide(); //hide success message


$('.text-input').focus(function() {//when focus on a field change the class to focus
$(this).removeClass('text-input').addClass('focus');
});

$('.text-input').blur(function() {//when moving away change the class back
 $(this).removeClass('focus').addClass('text-input');
});

//clearing fields just once
var inputs = document.getElementsByTagName("input");
	for (var i = 0 ; i < inputs.length ; i++ ) {
		 if (inputs[i].type=="text"||inputs[i].type=="textarea") {
			inputs[i].onfocus = function() {
			if(this.value==this.defaultValue) this.value = '';
			}
			inputs[i].onblur = function() {
			if(this.value=='') this.value = this.defaultValue;
			}
		}
	}
//end clear fields

//am using the above clear field code to clear fields just once not the commented out code below

//$("#message").val("Your message"); //set text area prompt
//  $("#message").val(""); //clear field//clear comment prompt on focus, have done this in the html with //onFocus="this.value=''; this.onfocus=null;"
//$('#message').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
  //$("#message").val(""); //clear field
//});

//$("#name").val("Your name"); //set input area prompt
//$('#name').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
  //$("#name").val(""); //clear field
//});

//$("#email").val("Your email"); //set input area prompt
//$('#email').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
  //$("#email").val(""); //clear field
//});

$('#submit').click(function() {
var name = $("#name").val();  //variables from the contact form
	var email = $("#email").val();  
	var subject = $("#subject").val();  

	var message = $("#message").val();  
	var spam = $("#spam").val();  
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	
            if ((name == "") || (name == "Your name")) {  
			$("#name_error").fadeIn(500);  
			$("#name").focus();  
			 return false;  
			}  
/*
			 if ((email == "") || (email == "Your email")) {  
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			}
	*/

			if (!email.match(emailExp)){		//if email is not valid
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			} 
			
			if ((subject == "") || (subject == "Subject")) {  
			$("#subject_error").fadeIn(500);  
			$("#subject").focus();  
			 return false;  
			}  



			 if ((message == "") || (message == "Your message")) {  
			$("#message_error").fadeIn(500);  
			$("#message").focus();  
			 return false;  
			} 
			if (spam !="LWO"){
			$("#spam_error").fadeIn(500);  
			$("#spam").focus();  
			 return false;  
			}


		
	/*		if ((spam !="fodip") && (spam !="FODIP")){  // AND needed here if you want 2 negative conditions		
			$("#spam_error").fadeIn(500);  
			$("#spam").focus();  
			 return false;  
			}*/  
					

document.getElementById('submit').disabled=true; //disable the button
var t=setTimeout("document.getElementById('submit').disabled=false", 5000);// re-enable the button after 5 seconds			


var dataString = 'name='+ name +'&email='+ email + '&subject= '+ subject + '&message='+ message;
$.ajax({
		type: "POST",
		url: "processlwomail.php", 
		data: dataString,
		cache: false,
		success: function(html){

//$('#seeall').replaceWith(html);

$('#successmessage').fadeIn(1000);

$('.text-input').focus(function() { //if you focus on a field again the success message goes as do the errors
$("#successmessage").fadeOut(1000);
$('.error').hide();
});

//$("#placement").append(html);// is the placement
//$("#fromphp").fadeIn("slow");// comes from the php //have to hide it first for fade to work!!
//$('#newcomment').fadeOut(2000);
//$('#newcomment').empty(); //empty the div other wise any new comments are seen again

		}//html function
});//ajax
return false;

});//click function

 });//doc ready









// });//close doc ready

