function convertBio()
{
	$('#people-nav a').removeClass();
	var visibleprofile = $('.bio-employee:visible').attr('id');
	var idnumber = visibleprofile.substring(3);
	var profilenum = ('#profile' + idnumber);
	$(profilenum).addClass('active');
}
function convertBiolast()
{
	$('#people-nav a').removeClass();
	$('#people-nav li:first-child a').addClass('active');
}
function convertBiofirst()
{
	$('#people-nav a').removeClass();
	$('#people-nav li:last-child a').addClass('active');
}
$(document).ready(function(){
	
	
	
	/* About/People Tabs */
	$('#header-people').click(function(){
		$('#copy').hide();
		$('#banner').show();
		$('#header-about').removeClass();
		$(this).addClass('active');	
		convertBio();	
		return false;
	});
	
	$('#header-about').click(function(){
		$('#banner').hide();
		$('#copy').show();
		$('#header-people').removeClass();
		$(this).addClass('active');
		return false;
	});
	
	// Floorplan
	$('#generic').show();
	
	$('.reset').click(function(){
		$('.floorplan').hide();
		$('#generic').show();
		$('.reset').css('background-position', '0 0');
		return false
	});
	
	
	
	$(".design").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '0 -118px');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.design').click(function(){
		$('.floorplan').hide();
		$('#design').show();
		return false
	});
			
	$(".client-services").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '0 -236px');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.client-services').click(function(){
		$('.floorplan').hide();
		$('#client-services').show();
		return false
	});
	
	$(".audio-video").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '0 -354px');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.audio-video').click(function(){
		$('.floorplan').hide();
		$('#audio-video').show();
		return false
	});
	
	$(".mobile-operations").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '-217px 0');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.mobile-operations').click(function(){
		$('.floorplan').hide();
		$('#mobile-operations').show();
		return false
	});
	
	$(".experiential-production").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '-217px -118px');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.experiential-production').click(function(){
		$('.floorplan').hide();
		$('#experiential-production').show();
		return false
	});
	
	$(".print-shop").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '-217px -236px');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.print-shop').click(function(){
		$('.floorplan').hide();
		$('#print-shop').show();
		return false
	});
	
	$(".fabrication-studio").hover(
	  function () {
		$('#floorplan .nav').css('background-position', '-217px -354px');
	  }, 
	  function () {
		$('#floorplan .nav').css('background-position', '0 0');
	  }
	);
	$('.fabrication-studio').click(function(){
		$('.floorplan').hide();
		$('#fabrication-studio').show();
		return false
	});
	
	/* People Nav - Forward/Backward */
	
	$('.activeBio').show();
	
	$('#nextBio a').click(function(){
		if ($('#people-nav li:last-child a').hasClass('active') == true)
		{
			$('.activeBio').hide().removeClass('activeBio');
			$('#bio-list div:first-child').show();
			$('.bio-employee:visible').addClass('activeBio');
			convertBiolast();	
			return false;
		}
		else {	
		
			$('.activeBio').next().show().removeClass('activeBio');
			$('.bio-employee:visible').addClass('activeBio');
			$('.activeBio').prev().removeClass('activeBio').hide();
			convertBio();	
			return false;	
		}
	});
	$('#prevBio a').click(function(){
		if ($('#people-nav li:first-child a').hasClass('active') == true)
		{
			$('.activeBio').hide().removeClass('activeBio');
			$('#bio-list div:last-child').show();
			$('.bio-employee:visible').addClass('activeBio');
			convertBiofirst();	
			return false;
		}
		else 
		{
			$('.activeBio').prev().show().removeClass('activeBio');
			$('.bio-employee:visible').addClass('activeBio');
			$('.activeBio').next().removeClass('activeBio').hide();
			convertBio();
			return false;
		}
	});
	
	/* People Nav - Thumbnails */
	
	$('#people-nav a').click(function(){
		var currentId = $(this).attr('id');		
		var idnumber = currentId.substring(7);
		var profilenum = ('#bio' + idnumber);	
		$('#people-nav a').removeClass();
		$(this).addClass('active');		
		$('.activeBio').hide().removeClass('activeBio');
		$(profilenum).show().addClass('activeBio');
		return false
	});
	
	/* Rotating copy banner */
	var copynumber = Math.floor(Math.random()*3);
	var copynumberid = ('#' + copynumber);
	$(copynumberid).show();
	
	
	$('.entry h2').first().addClass('post-title');
	
	
	
	
		
	
  // Setup the main rotater on the home page___________________________(*
	
  $("#slider .belt").carouFredSel({
    auto : {
      duration: 1000,
      delay: 3000,
      pauseOnHover: "resume",
      onBefore : 
        function(oldItems,newItems) 
        { 
          moveWave();
          oldItems.removeClass('slider-active');
          newItems.addClass('slider-active');
        },
      easing: "easeOutQuint"
      },
    pagination : {
      pauseOnHover: "resume",
      container: '#banner-pages',
      anchorBuilder : 
        function(nr, item) {
          return '<a href=""><span class="logo'+ nr +'"></span></a>';
        },
      onAfter : 
        function(oldItems,newItems)
        {
          oldItems.removeClass('slider-active');
          newItems.addClass('slider-active');
        }
      }
      
  });
    // add animation class to first panel on load.
    $('#slider .belt div:first-child').addClass('slider-active');
  
  
    // homepage features navigation - wave animation____________________(*
  	
  	$('#banner-pages a').mouseover(function(){
  		var position = $(this).position();
  		var margin   = parseInt($(this).css('margin-left').replace( / px/i, ""));
  		var center   = ($(this).width() - $('#wave img').width()) / 2;
  		$('#wave img').stop().animate({left: (position.left + center + margin - 5)}, 1000, "easeOutQuint");
  	});
}); 

    function moveWave(init) // automated wave via carousel
    {
      var object   = $('#banner-pages a.selected').next();
        if( !object.css('margin-left') || init )
        {
          object = $('#banner-pages a:first-child');
        }
      var position = object.position();
  		var margin   = parseInt(object.css('margin-left').replace( / px/i, ""));
    	var center   = (object.width() - $('#wave img').width()) / 2;
      $('#wave img').stop().animate({ left: (position.left + center + margin - 5)}, 1000, "easeOutQuint");
    }
	
	
$('document').ready(function(){	
	
	
	// Carousels ____________________________________________________________(*
    	
    	// jCarouselLite doesn't accomodate for scrollers that do not have
    	// a number of images that are not evenly divisible by the number visible.
    	// carouselFix corrects this.
    	var visible = 4;
    	//var news_blogs_count = $('#makeMeScrollable .scrollableArea').children('li').length % visible;
    	//var case_study_count = $('#caseStudyGallery').children('li').length % visible;
    	
    	//carouselFix( news_blogs_count, $('#makeMeScrollable .scrollableArea') );
    	//carouselFix( case_study_count, $('#caseStudyGallery') );
    	
    	function carouselFix( carousel_length, carousel )
    	{
      	if( carousel_length != 0 ){
      	 var x = visible - carousel_length;
      	 for( i=0; i < x; i++ ){ carousel.append('<li></li>'); }
      	}
      }
      //----------------------------------------------------------
	
	$('#makeMeScrollable .scrollWrapper .scrollableArea').carouFredSel({
	   next: "#makeMeScrollable .scrollingHotSpotRight",
	   prev: "#makeMeScrollable .scrollingHotSpotLeft",
	   auto : {
	       play: false,
	       duration: 500
	     },
	   items: 4
  });
  
  $('#caseStudyGallery').carouFredSel({
    prev: '#foo3_prev',
    next: '#foo3_next',
    items: 4,
    auto: {
        play: false,
        duration: 1000
      }
  });
  
  $('div.services-banner-carousel').jCarouselLite({
    scroll: 1,
    visible: 1,
    speed: 1000,
    auto: 4000
  });
	
	// reveals hidden carousel images when the code is finished loading
	// eliminating their unseemly appearance on load >.>
	$('.services-banner-carousel ul li').show();
	$('#slider .belt .panel').show();
	
	
	
	
	
	// Verticle Menu on homepage____________________________________________________(*
	$('#wrapper').mouseover(function(e){
	   if( $(this).height() < 270 ) 
	   {
		  
	      e.preventDefault();
		  $('#wrapper').stop().animate({height: '238px',top: '-95px'},500, "easeOutBack");
		  $('#wrapper .caroufredsel_wrapper').stop().animate({ height: '238px', top: '0'}, 500, "easeOutBack");
		  $('#scroll_controls div.up').stop().animate({opacity: '0'}, 500, "easeOutQuint");
		  $('#scroll_controls div.down').stop().animate({opacity: '0'}, 500, "easeOutQuint");
		  $('#carusel_1').trigger('pause');
		  $(this).addClass('open');
	   }
	});
	
	$('#wrapper').mouseleave(function(){
		
		$('#wrapper').stop().animate({height: '30px',top: '0px'},700, "easeOutQuint");
		$('#scroll_controls div.up').stop().animate({opacity: '1'}, 500, "easeOutQuint");
		$('#scroll_controls div.down').stop().animate({opacity: '1'}, 500, "easeOutQuint");
		$('#wrapper').removeClass('open');
		$('#carusel_1').trigger('play');
		
	});
	
	$('#carusel_1').carouFredSel({
		direction: 'up',
		duration: 500
	});
	
	//$('#wrapper').mouseleave(function(){
	//	$(this).animate({height: '30px'});								 
	//});
	
  	$('#scroll_controls .up').click(function()
  	{
      $('#carusel_1').trigger("prev");
  	});
  	
  	$('#scroll_controls .down').click(function()
  	{
      $('#carusel_1').trigger("next");
  	});
	
	
	
	
	// Lightbox calls ____________________________________________________(*
	$('.colorbox-iframe').fancybox({
    'type': 'iframe',
    'width': '60%',
    'height': '80%',
    'centerOnScroll': true,
    'overlayColor': "#fefefe"
	}); 
	
	$('#caseStudyGallery a[rel="gallery"], #caseStudyGallery a[rel="group1"]').fancybox({
    'overlayColor': "#fefefe",
    'centerOnScroll': true
	});
	
	
	
	// About page: In The News Sidebar_______________________________________________(*
  var x = 0;
  var sidebar_widget_open = 0;
  var sidebar_widget_closed = 0;
  var sidebar_widget = $('div.in-the-news ul');
  
  sidebar_widget.find('li').each(function(){
    if( x < 4 ){
      sidebar_widget_closed += $(this).find('span.description').height() + 12;
      x++;
    }
    sidebar_widget_open += $(this).find('span.description').height() + 12; // 12 = bottom margin of span.description
  });
  sidebar_widget.addClass('close').animate({height: sidebar_widget_closed});
	
	
	$('div.in-the-news .more').click(function(e){
		$('#in-the-news').fadeIn();
	});
	
	
	
	
	// Contact Form Validation__________________________________________*(
	$('.wpcf7-form').validate({
    rules : {
        
        Email: {
            email: true
          }
        
      },
    messages : {
        
        Email: 'Please fill the required field.'
        
      },
    onkeyup: false
	});
	
	$('.wpcf7-form label.error').live('mouseover', function()
	{
    $(this).animate({opacity:'0'}, 500, "easeOutQuint", function(){ $(this).css('display', 'none').css('opacity', '1')});
	});
	
});

