$(document).ready(function() {

//$("#accordion").accordion("option", "autoHeight", false);//no
$(".accordion").accordion({ autoHeight: false, collapsible: true });



$('.typeofconsort').hover(function() {
        $(this).addClass('chosentypeofconsort');
      }, function() {
        $(this).removeClass('chosentypeofconsort');
      });

$('#ancient').click(function(){
  window.location = "ancient.php";
}); 


//this needs to be a toggle
$('.accordion').hide();//hide the accordians
//$('#first').click(function(){//when you click the heading it shows the accordian div
//$('#2009autumn').show();
//});
 

$('#first').toggle(function() {//2009 autumn
$('#2009autumn').fadeIn(500);
}, function() {
$('#2009autumn').fadeOut(500);
});

$('#second').toggle(function() {//2009 summer
$('#2009summer').fadeIn(500);
}, function() {
$('#2009summer').fadeOut(500);
});

$('#third').toggle(function() {//forum
$('#forum').fadeIn(500);
}, function() {
$('#forum').fadeOut(500);
});

$('#fourth').toggle(function() {
$('#2008summer').fadeIn(500);
}, function() {
$('#2008summer').fadeOut(500);
});

$('#fifth').toggle(function() {
$('#2008spring').fadeIn(500);
}, function() {
$('#2008spring').fadeOut(500);
});

$('#sixth').toggle(function() {
$('#2007spring').fadeIn(500);
}, function() {
$('#2007spring').fadeOut(500);
});

$('#seventh').toggle(function() {
$('#2006summer').fadeIn(500);
}, function() {
$('#2006summer').fadeOut(500);
});

$('#eighth').toggle(function() {
$('#2006spring').fadeIn(500);
}, function() {
$('#2006spring').fadeOut(500);
});

$('#nineth').toggle(function() {
$('#2005summer').fadeIn(500);
}, function() {
$('#2005summer').fadeOut(500);
});

$('#tenth').toggle(function() {
$('#2005spring').fadeIn(500);
}, function() {
$('#2005spring').fadeOut(500);
});

$('#eleventh').toggle(function() {
$('#2004concert').fadeIn(500);
}, function() {
$('#2004concert').fadeOut(500);
});

$('#twelfth').toggle(function() {
$('#2003concert').fadeIn(500);
}, function() {
$('#2003concert').fadeOut(500);
});

$("div.clickable").click( //this makes divs clickable (including any images in them), specify the url in the page , in the <div> tag. 
function()
{
    window.location = $(this).attr("url");
});




//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 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 ((message == "") || (message == "Your message")) {  
			$("#message_error").fadeIn(500);  
			$("#message").focus();  
			 return false;  
			} 
			if (spam !="CONSORT"){
			$("#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 + '&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
