$(function(){	
	//=================================//
	//FRONTPAGE REVEALS
	if ($('.homepage_diaries').length > 0) {
		$('.homepage_diaries').masonry();
	
		$('span.reveal_arrow').toggleClass('active');
		$('.col_350 .entry_container_350 .reveal_content').show();
		
		$('a.reveal').click(function(){
			if($(this).hasClass('current')){
					$(this).parent().siblings('.reveal_content').slideUp('slow',function() {  
					$(this).removeClass('current');
					});
					$(this).find('span.reveal_arrow').removeClass('active');				
			} else {
					$(this).parent().siblings('.reveal_content').slideToggle('slow',function() {  
					$(this).toggleClass('current');  
					});
				$(this).find('span.reveal_arrow').toggleClass('active');			
				return false;
			}
			return false; 
		});
	}	
	//FRONTPAGE REVEALS END
		
	//=================================
	//LIGHTBOX
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	//"LIGHTBOX" END

	//VOLUNTEER ROLES
	if ($('.roleMore').length > 0) {
		$('.roleMore').click(function(){
			var $_this = $(this);
			if($_this.text() === "More Information"){
				$_this.text("Close");
				$_this.parent().prev().slideDown('slow');	
			} else {
				$_this.text("More Information");
				$_this.parent().prev().slideUp('slow');
			}
			return false;
		});
	}	
	//END VOLUNTEER ROLES

	//=================================	
	//NEWSLETTER FORM VALIDATION BEGIN
	if ($('#newsletter_form').length > 0) {
		$('.validation').hide();
		$('#newsletter_form').validate({
			rules: {
				newsletter_name: {
					required: true,
					minlength: 2
				}
			},
			messages: {
			    newsletter_name: {
			    	required: "Please specify your name",
			    	minlength: "Please enter 2 or more characters"
			    },
			    newsletter_email: {
					required: "We need your email address to send you the newsletter.",
					email: "We need your full email address please."
				}
			},
			submitHandler: function() {
				$('#newsletter_form').ajaxSubmit({
					url: 'http://www.thebivouac.co.uk/index.php/newsletter/functions',
					success: function() {
	                    $('.col_535').html("<h2 class='contact_result'>Thanks for signing up!<br />We'll get a newsletter to you straight away.</h2>").hide().fadeIn(1500);
	                }
	               	
	           	});
			}
		}); 
	}
	//=================================//	
	//NEWSLETTER FORM VALIDATION END
	
	
	//CONTACT FORM VALIDATION BEGIN
	if ($('#contact_form').length > 0) {
		$('#contact_form').validate({
			rules: {
				contact_name: {
					required: true,
					minlength: 2
				},
				contact_subject: {
					required: true
				},
				contact_question: {
					required: true,
					minlength: 5
				}
			},
			messages: {
			    contact_name: {
			    	required: "Please specify your name",
			    	minlength: "Please enter 2 or more characters"
			    },
			    contact_email: {
					required: "We need your email address to send you a reply.",
					email: "We need your full email address please."
				},
				contact_subject: {
					required: "Please enter a subject"
				},
				contact_question: {
					required: "Please enter your question or query",
					minlength: "Please enter 5 or more characters"
				}
			},
			submitHandler: function() {
				$('#contact_form').ajaxSubmit({
					url: 'http://www.thebivouac.co.uk/scripts/formtoemail.php',
					success: function (data) {
	                    $('.comment_form').html("<h2 class='contact_result'>" + data + "</h2>").hide().fadeIn(1500);
	                }
	               	
	           	});
			}
		}); 
	}
	// CONTACT FORM VALIDATION END	
	
	//VOLUNTEER FORM VALIDATION BEGIN
	if ($('#volunteerForm').length > 0) {
		$('#volunteerForm').validate({
			rules: {
				fname: {
					required: true,
					minlength: 2
				},
				lname: {
					required: true,
					minlength: 2
				},
				email: {
					required: true
				},
				age: {
					required: true
				}, 
				city: {
					required: true,
					minlength: 2
				}
			},
			messages: {
			    fname: {
			    	required: "Please specify your first name",
			    	minlength: "Please enter 2 or more characters"
			    },
			    lname: {
			    	required: "Please specify your last name",
			    	minlength: "Please enter 2 or more characters"
			    },
			    email: {
					required: "We need your email address to get in touch.",
					email: "Please enter a valid email address."
				},
				age: {
					required: "Please select your age range"
				},
				city: {
					required: "Please enter your town/city",
					minlegnth: "Please enter more than 2 characters"
				}
			},
			submitHandler: function() {
				$('#volunteerForm').ajaxSubmit({
					url: 'http://www.thebivouac.co.uk/scripts/volunteerProcess.php',
					success: function(response) {
	                    $('#volunteerFormResponse').html("<h2>" + response + "</h2>");
	                }            	
	           	});
			}
		}); 
	}
	// VOLUNTEER FORM VALIDATION END
});

Cufon.replace('h2, h3', {hover: true});
Cufon.replace('h4, label.newsletter, .mc-field-group label');
