$(document).ready(function(){

	// progressive enhancement
	// $("body").addClass("js-enabled");
	
	if ((nav_focus = $('.nav-focus')).length) nav_focus.bgiframe();

	// disable anchor default behaviour
	$(".section-staff h2 a").click(function() {
		return false;
	});

	// form label interaction
	$("label").inFieldLabels();
	
	// async form submit
	$("#contact").submit(function() {
		var errors = false;

		
		if ($('#contact #name').val() === '') {
			errors = true;
			$('label[for="name"]').text('please enter your name').addClass('error');
		}
		if ($('#contact #email').val() === '') {
			errors = true;
			$('label[for="email"]').text('please enter your email address').addClass('error');
		} else if (!$('#contact #email').val().match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)) {
			errors = true;
			$('#email').val('');
			$('label[for="email"]').stop().css({'display':'block','opacity':'1'}).text('please enter a valid email address').addClass('error').inFieldLabels();
		}
		if ($('#contact #comment').val() === '') {
			errors = true;
			$('label[for="comment"]').text('please enter your message').addClass('error');
		}
		if (errors == false) {
			$('button[name="submit"]').attr('disabled', 'true').text('sending message...');
			$.ajax({
			    type: 'POST',
			    url: '/site/custom_scripts/templates/staff_website/scripts/faq_submit.php',
			    data: $("#contact").serialize(),
			    success: function() {
					$('button[name="submit"]').attr('disabled', 'false').text('Send message');
					$('#contact').fadeOut('slow', function() {
						$(this).parent().html('<h3>Thank you for submitting your feedback.</h3>').fadeIn('slow');
					});
			  	}
			});
		}
		return false;
	});

	// jQuery SmoothScroll | Version 10-04-30
	$('a[href=#popularlinks], a[href=#leeds-ac-uk-staff], a[href=#pages]').click(function() {

	   // duration in ms
	   var duration=1000;

	   // easing values: swing | linear
	   var easing='swing';

	   // get / set parameters
	   var newHash=this.hash;
	   var target=$(this.hash).offset().top;
	   var oldLocation=window.location.href.replace(window.location.hash, '');
	   var newLocation=this;

	   // make sure it's the same location      
	   if(oldLocation+newHash==newLocation)
	   {
	      // animate to target and set the hash to the window.location after the animation
	      $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {

	         // add new hash to the browser location
	         window.location.href=newLocation;
	      });

	      // cancel default click action
	      return false;
	   }
	});

	// navigation tooltip interaction
	$("a[href='/forstaff/news']").tooltip( {
		position: ['bottom', 'center'],
		offset: [0, 374],
		effect: 'fade',
		opacity: 0.97,
		fadeInSpeed: "fast",
		fadeOutSpeed: "fast",
		predelay: 0,
		delay: 200,
		tipClass: 'nav-focus'
	});
	
	$("a[href='#popularlinks']").tooltip( {
	 		position: ['bottom', 'center'],
	 		offset: [0, 20],
	 		effect: 'fade',
	 		opacity: 0.97,
	 		fadeInSpeed: "fast",
	 		fadeOutSpeed: "fast",
	 		predelay: 0,
	 		delay: 200,
	 		tipClass: 'nav-popular-focus'
	});

	// tab interaction
	$("ul.tabs").tabs("div.content-sub > div");
	//$("ul.tabs").tabs("div.content-sub > div", {
	//effect: 'fade'
	//});
});

