var carouselUl = $('ul.featured');
var shadow = $('.shadow');
var step = 1;
var totalSteps = $('ul.featured li').length;
var numSlide = 0;

$(document).ready(function(){

	// Navigation Drop Down
	
	$('header nav li.drop-down').hoverIntent(function(){
			$(this).addClass('current_page_item');
			$(this).children('.sub-menu').slideDown('fast', 'easeInOutCirc');
		}, function(){
			$(this).removeClass('current_page_item');
			$(this).find('.sub-menu').slideUp('fast', 'easeInOutCirc');
	});
	
	$('header nav li.inner-drop-down').hoverIntent(function(){
			$(this).addClass('current_page_item');
			$(this).children('.sub-menu').slideDown('fast', 'easeInOutCirc');
		}, function(){
			
	});
		
	// Home page Carousel
		
	var carousel = requestInterval(carouselStep, 8000);

	function carouselStep() {
		if (step < totalSteps){
			carouselUl.children('li').animate({scale: '0.97'}, 500);
			shadow.fadeIn('slow', function(){
				carouselUl.animate({left:'-=940px'}, 500, 'easeInOutCirc', function(){
					carouselUl.children('li').animate({scale: '1.0'}, 500);
					shadow.fadeOut('slow');		
				});
			});
			numSlide = step+1;
			$('.carousel-nav a').removeClass('current-carousel');
			$('.carousel-nav li:nth-child('+numSlide+')').find('a').addClass('current-carousel');
			step++;
		} else if (step == totalSteps){
			carouselUl.children('li').animate({scale: '0.97'}, 500);
			shadow.fadeIn('slow', function(){
				carouselUl.animate({left:'0px'}, 500, 'easeInOutCirc', function(){
					carouselUl.children('li').animate({scale: '1.0'}, 500);
					shadow.fadeOut('slow');		
				});
			});
			numSlide = 1;
			$('.carousel-nav a').removeClass('current-carousel');
			$('.carousel-nav li:nth-child('+numSlide+')').find('a').addClass('current-carousel');
			step = 1;
		}
	}
	
	// Carousel Navigation
	
	$('.carousel-nav a').click(function(){
		if (carouselUl.is(':animated')){
			// Don't do shit while it's movin'
		} else {
			clearRequestInterval(carousel);
			$('.carousel-nav a').removeClass('current-carousel');
			$(this).addClass('current-carousel');
			var whichOne = $(this).attr('data-step');
			var minusOne = whichOne-1;
			var destination = -940*minusOne;
			carouselUl.children('li').animate({scale: '0.97'}, 500);
			shadow.fadeIn('slow', function(){
				carouselUl.animate({left:destination+'px'}, 500, 'easeInOutCirc', function(){
					carouselUl.children('li').animate({scale: '1.0'}, 500);
					shadow.fadeOut('slow');		
				});
			});
		}
		return false;
	});
	
	
	// Center Client Images Correctly
	
	$('.clients li').each(function(){ 
		var imgHeight = $(this).find('img').height();
		if (imgHeight < 135){
			var imgPad = 135 - imgHeight;
			$(this).find('img').css({'padding-top':imgPad/2+'px','padding-bottom':imgPad/2+'px'});
			imgHeight = 0;
			imgPad = 0;
		}
	});

	// Related List Hovers
	
	$('.related-list a').hoverIntent(function(){
			$(this).animate({left:'12px'}, 'fast');
			$(this).find('.related-arrow').animate({left:'-20px'}, 'fast');
		}, function(){
			$(this).animate({left:'0px'}, 'fast');
			$(this).find('.related-arrow').animate({left:'-27px'}, 'fast');
	});

	// Contact Overlay
	
	var theH = $(document).height();
	
	$('.contact-overlay').height(theH);
	
	/**
	$('.contact-link').click(function(){
		$('.contact-overlay').fadeIn('fast');
		return false;
	});

	$('.contact-close').click(function(){
		$('.contact-overlay').fadeOut('fast');
		return false;
	});
	**/

});




















