////Greg Adler Block Hide on Team Page
//$('#authorlist h2').each(function(){
//	if ( $(this).text() == 'Greg Adler' ) {
//		$(this).parent().hide();
//	};
//});

//Nivo Slider
$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
      controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});





/******************************************** 
     #Carousel
********************************************/
/////Carousel Function + Smart Columns
$.fn.carousel = function(){ 
	
								  
	var rotatorLi = $(this).find("ul.rotator li").width();
	var rotatorSum = $(this).find("ul.rotator li").size();
	var carousel = $(".carousel").width();

	var rotatorMaxLi = Math.floor(carousel / rotatorLi); //See how many lists can fit in the carousel viewport
	var rotatorSlideSum =  Math.ceil(rotatorSum / rotatorMaxLi); //See how many slides (sections viewable in carousel viewport) we will need

	var adjustLi = (carousel / rotatorMaxLi); //Perfect width that would fit in carousel viewport
	var adjustRotator = (adjustLi * rotatorSum); //Get width of adjusted rotator
	
	var lastSlideSum = Math.floor(adjustRotator / carousel); //Get the whole number of slides that can fit in carousel (for remainder of slides)
	var lastSlide = (carousel * lastSlideSum) - adjustRotator; //Get the distance of the remaining slides

	//Get tallest list item in carousel (prevents truncation)
	var tallest = 0;
	$(this).find("ul.rotator li").each(function() {									
		var rotatorLiHeight = $(this).height();
		if (rotatorLiHeight > tallest) {
			tallest = rotatorLiHeight + 20; //20 takes in consideration of padding 10px 0;
		}
	});
	$(this).find(".carousel").css({ 'height' : tallest}); //Adjust Height of Carousel
	$(this).find("ul.rotator li").css({ 'width' : adjustLi}); //Adjust width
	$(this).find("ul.rotator").css({ 'width' : adjustRotator}); //Adjust width
	
		
	var sum = 0; //Set Count for clicks
			
	if (carousel < adjustRotator) { //If the list is bigger than the carousel viewport
		$(this).find("a.right-scroll").click(function() { 				   
			if(sum < (rotatorSlideSum-1)) {	
				sum++;
				$(this).parent().find("a.left-scroll").removeClass("deactive");
				switch(sum){
					case rotatorSlideSum: //on the last slide...
						$(this).addClass("deactive");
						break;
					case rotatorSlideSum-1: //second to last slide...
						$(this).addClass("deactive");
						if (lastSlide < -1) {
							$(this).parent().parent().find("ul.rotator").animate({ marginLeft: "+=" + lastSlide }, 250);
						}
						else {
							$(this).parent().parent().find("ul.rotator").animate({ marginLeft: "-=" + carousel }, 250);
						}
						break;
					default: //on click else
						$(this).parent().parent().find("ul.rotator").animate({ marginLeft: "-=" + carousel }, 250);
						break;
				}
			}
			return false;
		}); //end switch case
	
		$(this).find("a.left-scroll").addClass("deactive");
		$(this).find("a.left-scroll").click(function() { 
			if(sum > 0) {	
				sum--;
				$(this).parent().find("a.right-scroll").removeClass("deactive");
				switch(sum){
					case 0: //if back to original slide...
						if (lastSlide < -1 && rotatorSlideSum == 2 ) { 
							$(this).parent().find("ul.rotator").animate({ marginLeft: "-=" + lastSlide }, 250);
						}
						else {
							$(this).parent().find("ul.rotator").animate({ marginLeft: "+=" + carousel }, 250);
						}
						$(this).addClass("deactive");
						break;
					case rotatorSlideSum-2: //1st click back from the last slide...
						if (lastSlide < -1) {
							$(this).parent().find("ul.rotator").animate({ marginLeft: "-=" + lastSlide }, 250);
						}
						else {
							$(this).parent().find("ul.rotator").animate({ marginLeft: "+=" + carousel }, 250);
						}
						break;
					default:
						$(this).parent().find("ul.rotator").animate({ marginLeft: "+=" + carousel }, 250);
						break;
				}
				
			}
			return false;
		}); //end switch case
	} else { //if there is only one slide...
		$(this).find("a.right-scroll, a.left-scroll").addClass("deactive");
	}//end if carasouel statement

};//end function




	
$(document).ready(function() {

	
	////Trigger Carousel + Component Functions
	if( $('.tab_content').find('.carousel').length > 0  ) { //If Carousel exists within a tab content...
		$('.carousel_placement').each(function() { //for each carousel run the following code...
			 tabID = $(this).parent().attr('id'); //get the ID of the tab content
			$('#' + tabID).carousel();	//run the carousel function on that ID						 
		});
	}


	//Authors Tab Function
	$('.tab_content').hide();
	$('.tab_content:first, ul.authortabs li:first').show().addClass('active');
	$('ul.authortabs li').click(function(){
		$('ul.authortabs li').removeClass('active');								 
		$(this).addClass('active');
		$('.tab_content').hide();
		$(this).parent().parent().find($(this).find('a').attr('href')).show();
		return false;
	});
	
	//Accordion
	$('.acc_container').hide();
	$('.acc_container:first').show();
	$('.acc_trigger:first').addClass('active');
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) {
			$('.acc_trigger').removeClass('active');
			$(this).toggleClass('active');
			$('.acc_container').slideUp();	
			$(this).next().slideDown();	
		}
	});
	
	//Select Option Link Jump
	$('.vehicle_select select, #sidebar-search select').change(function() {
		 window.location=$(this).attr('value');									
	});
	
	//Filters on Side Column
	$(".toggle_container").hide(); 
	
	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".toggle_trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false;
	});	
	
	
	/******************************************** 
		 #Carousel Image Gallery Switch
	********************************************/
	$('.carousel ul').each(function(){
		$(this).find('li:first').addClass('active');								
	});
	
	$('.carousel ul li').click(function(){
		var imgSrc = $(this).find('a').attr('href');
		if ($(this).is(".active")) {  
		} else { 
			$(this).parent().parent().parent().parent().parent().parent().find('img.full').attr({ src: imgSrc}); 
		}
		$(this).parent().find('li').removeClass('active');
		$(this).addClass('active');
		return false; 
	});

	$('a[href*=.jpg], a[href*=.gif], a[href*=.png]').prettyPhoto({theme:'facebook'});

	
});

