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

//Nivo Slider
$(window).load(function() {
	var slide_size = $('#slider').size();
	if(slide_size >= 1){		
		$('#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;
		}
	});
	var timelineExist = $("#timeline ul").size();
	if(timelineExist == 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;
	});*/
	
	
	/*--------------------------------------------- Tabbed Navigation -------------------------------------------------*/
	function tabbedNavigation(){
		var tabItems = [];
		var locationHash = location.hash;
		$("ul.authortabs li a").each(function(){ 
			var items = $(this).attr("href");
			tabItems.push(items);
		});
		if(locationHash === "") {
			$(".tab_content").hide(); //Hide all content
			$("ul.authortabs").each(function(){
				$("li:first", this).addClass("active").show(); //Activate first tab
			});
			
			$(".tab_content:first").show(); //Show first tab content
		}
		else{
			var tabItemsIndex = jQuery.inArray(locationHash, tabItems);
			if(tabItemsIndex != -1){
				var targetedTab = $("ul.authortabs li a[href="+locationHash+"]");
				var targetedTabContent = $(".tab_content"+locationHash);				
				targetedTabContent.parent().find(".tab_content").each(function(){
					$(this).hide();
				}); //Hide all content
				targetedTab.parent().siblings().removeClass("active");
				targetedTab.parent().addClass("active");
				targetedTabContent.fadeIn();				
				$('html, body').animate({ scrollTop: 0 }, 0); //We send the user to the top of the page		
			}
			else{//We need to find the active tab... if any. Show active tab or if there is no active then show the first tab.
				$(".tab_content").hide(); //Hide all content
				$("ul.authortabs").each(function(){
					$("li:first", this).addClass("active").show(); //Activate first tab
				});
				$(".tab_container").each(function(){
					$(".tab_content:first",this).show(); //Show first tab content
				});
			}
		}
		//On Click Event
		$("ul.authortabs li").click(function() {
			/*$("ul.authortabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab*/
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			/*$(".tab_content").hide(); //Hide all tab content
			$(activeTab).fadeIn(); //Fade in the active ID content*/
			location.href = activeTab;
			return false;
		});
	};
	var hasTabs = $("ul.authortabs").size();
	if(hasTabs >= 1){
		var lastHash = '';
		function pollHash() {
			if(lastHash !== location.hash) {
				lastHash = location.hash;
				// hash has changed, so do stuff:
				tabbedNavigation();//We look at the URL to see if we need to show a specific slide.
				//playSlideshow = setInterval(slideSwitchTimed, sliderTimer);
			}
		}
		setInterval(pollHash, 300);
		tabbedNavigation();
	}
	
	//Accordion
	$('.acc_container').hide();
	$('.acc_container:first').show();
	$('.acc_trigger:first').addClass('active');
	var tabContentSize = $(".tab_content").size();
	if(tabContentSize >= 1){
		$(".tab_content").each(function (){
			$('.acc_container:first',this).show();
			$('.acc_trigger:first',this).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).parents().find('img.full').hide().attr({ src: imgSrc}).fadeIn();
			}
		$(this).parent().find('li').removeClass('active');
		$(this).addClass('active');
		
		return false; 
	});
	
});

//Launch Pretty Photo
$(document).ready (function() {
		
							
	$('a[href*=".jpg"], a[href*=".png"], a[href*=".gif"], a[href*=".jpeg"], a[href*=".JPG"]').not('.carousel ul li a').prettyPhoto();
 });

