$(document).ready(function(){
	
	$(".homeFeatureItem:first").show();
	$("nav ul.globalNav li:last").addClass('noMargin');
	$(".subnavWrap ul li:first").addClass('subnavLanding');
	$(".countNumberWrap span:nth-child(3)").addClass('count_mid');
	$(".countNumberWrap span:nth-child(4)").addClass('count_right');
	$("ul.footerNav li:last").addClass('noMargin');
	$("ul.footerNav li:last").addClass('noMargin');
	$(".directorBox:nth-child(odd)").addClass('noRightMargin');
	$(".headBox:nth-child(3n+1)").addClass('noRightMargin');
	$("nav ul li ul li:nth-child(even)").addClass('altBk');
	$("nav ul li ul li:first-child").addClass('noBorder');

	$(".application .row .col:nth-child(2)").addClass('midCol');	
	$(".application .row .col_3input input:nth-child(2)").addClass('midInput');	
	
	$("nav ul.globalNav li").hoverIntent(
	  function () {
	    $(this).children("ul").fadeIn('fast');
	  },
	  function () {
	    $(this).children("ul").fadeOut('fast');
	  }
	);

	$('#homeFeatureInside').before('<ul id="featureNav">').cycle({ 
	    fx:     	'fade', 
	    speed:  	300, 
	    timeout: 	4000,
	    pause:		1,
	    pager:  	'#featureNav', 
	     
	    // callback fn that creates a thumbnail to use as pager anchor 
	    pagerAnchorBuilder: function(idx, slide) { 
    	var img = $(slide).children().eq(0).attr("src");
		
	        return '<li><a href="#"><img src="' + img + '" width="76" height="27" /></a></li>'; 
	    } 
	});

	$(".subnavWrap ul li").click(function() {
	    $(this).siblings().children("a.subActive").removeClass('subActive');
	    $(this).siblings().children("ul").slideUp('fast');
	    $(this).children(":first").addClass('subActive');
	    $(this).children("ul").slideDown('fast');
	});

	$('.mainMap .pin')
		.hoverIntent(function() {
			$(this).children('.mapTip').fadeIn('fast');
		}, function() {
			$(this).children('.mapTip').fadeOut('fast');
		});
		
	$(".scrollable").scrollable();

	$('.directorBox')
		.hover(function() {
			$(this).children(".profileHoverBox").stop().animate({ top: 108 }, 200);
		}, function() {
			$(this).children(".profileHoverBox").stop().animate({ top: 163 }, 200);
		});

	$('.headBox')
		.hover(function() {
			$(this).children(".profileHoverBox").stop().animate({ top: 57 }, 200);
		}, function() {
			$(this).children(".profileHoverBox").stop().animate({ top: 112 }, 200);
		});

	$('.sideLightbox').lightbox();

	$("#twitter_update_list a").attr("target","_blank");

	$(".testimonialItem:first-child").addClass('testItemFirst');
	$(".testimonialItem:last-child").addClass('testItemLast');
	
	$(".testimonialItem").click(function(){
		all_testimonial_items = $('.testimonialItem');
		others = $($.grep(all_testimonial_items, function(testimonialItem,i){ return testimonialItem != $(this)}));

		// hide copy text
		others.children(".test_copy").slideUp();
		
		//remove background colour
		others.removeClass("test_active");
		
		//remove minus signs
		others.children(".test_close").removeClass("test_open");
		
		children = $(this).children(".test_copy");
		// if I'm already open, close me like everyone else
		if(children.is(":visible")) {
			$(this).children(".test_close").removeClass("test_open");
			$(this).removeClass("test_active");						
			children.slideUp();
		} else { // otherwise, open me
			$(this).children(".test_close").addClass("test_open");
			$(this).addClass("test_active");
			children.slideDown();
		}
	});
	
});
