$(document).ready(function() {
  // Add a magic margin to the first case study thumbnails
  $('#latestNewsHeadlines li').filter(function(index){
    return (index%2 == 0);
  }).addClass('alt');

  // Setup Slider
    $(window).load(function() {
        $('#slider').nivoSlider({
        effect:'boxRandom',
        });
    });
  
});

jQuery(document).ready(function() {

	$(".video").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});

		return false;
	});
	
	
	  var $contactForm = $("#contact");
	
	  // Send the contact form async.
	  function sendContactForm(form) {
	    $("input:submit", form).val('Please wait...').attr('disabled', 'disabled');
	    var values = $(form).serialize();
	
	    $("p.message", form).remove();
	
	    $.post(form.action, values, function(body, res) {
	      $("input:submit", form).removeAttr('disabled').val('Send Enquiry');
	      $('fieldset', form).append('<p class="message">' + body.message + '</p>');
	
	      if (body.status === 200) {
	        $('input:text, textarea', form).val('');
	      }
	    }, 'json');
	
	    return false;
	  };
	
	  // Validate the contact form
	  $("#contact").validate({
	    submitHandler: sendContactForm
	  });
	  
	
});
