$('document').ready( function() {
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('h4:not("#tooltip h4")', { hover: true });
	Cufon.replace('h5', {hover: true});
	
	// Get rid of empty p tags
	$('p:empty').remove();
	
	// create custom animation algorithm for jQuery called "bouncy" 
	$.easing.bouncy = function (x, t, b, c, d) { 
	    var s = 1.70158; 
	    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
	    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	} 
	
	// create custom tooltip effect for jQuery Tooltip 
	$.tools.tooltip.addEffect("bouncy", 
	 
	    // opening animation 
	    function(done) { 
	        this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show(); 
	    }, 
	 
	    // closing animation 
	    function(done) { 
	        this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  { 
	            $(this).hide(); 
	            done.call(); 
	        }); 
	    } 
	);
	
	
	$(".casestudy img").each(function() {
		var el = $(this);  
		var thisid = el.attr("id"); 
		var thisid = ("#tt-" + thisid); 
		 
		el.tooltip({      
		   tip: thisid,
		   effect: 'bouncy'
		});  
	
	});
	
	// Fix margins on nav ul
	$('.nav ul').children().eq(0).css({'margin-left': '-1px'});
	$('#casestudies ul li.casestudy:last').css({'margin-right': '0'});
	
	if ($("body.leadership").length) {
		$(".leaderbio a").overlay({
			close: '#overlay-close',
			expose: {
				color: '#111111',
				opacity: 0.9,
				speed: 200
			},
			onBeforeLoad: function() { 
	            // grab wrapper element inside content 
	            var wrap = this.getContent().find(".overlaycontent"); 
	            // load the page specified in the trigger 
	            wrap.load(this.getTrigger().attr("href"));
	            Cufon.replace('.overlaycontent h2');
	            Cufon.replace('.overlaycontent h3');
	        },
	        onLoad: function() {
	        	Cufon.refresh();
	        },
	        onBeforeClose: function() {
	        	var wrap=this.getContent().find(".overlaycontent");
	        	wrap.html("");
	        }
		});
	}
	
	$('.nav ul li:has(ul)').each(function() {
		$(this).children('a').click( function() { return false; });
	});
	
	$('.nav ul li ul').each( function() {
		$(this).children('li:last a').css("margin-bottom", "10px");
	});
	
	$('.nav ul li').hover(
		function() {
			$(this).children('ul').stop(true, true).slideDown('slow');
		},
		function() {
			$(this).children('ul').slideUp('slow');
		}
	);
	
	if ($('#clientsinthenews').length) {
		$('ul.tabbuttons').tabs('div.tabpanes > ul');
	}
	
	if ($('#coda-slider-1').length) {
		$('#coda-slider-1').codaSlider();
	}
	
		if ($('#coda-slider-2').length) {
		$('#coda-slider-2').codaSlider();
	}
	
	if ($('#coda-slider-travel').length) {
		$('.casestudies:first').css('border-top', 'none');
		$('.coda-slider').codaSlider();
	}
});
