$(document).ready(function() {
	$('.socialShareWidget').socialShare();

	$('#teamGrid').animatedTab();
	
	// Bio
	$(".athleteBioOff").click(function () {
		$(".athleteBio").addClass("active");
		$(".bioPopup").animate({ opacity: 1.0 }, 200);
	});
	
	$(".athleteBioClose").click(function () {
		$(".athleteBio").removeClass("active");
		$(".bioPopup").animate({ opacity: 0.0 }, 200);
	});
	
	//if on athlete page by default have the bio box open
	if($(".athleteBioOff").length >= 1){
		$(".athleteBio").addClass("active");
		$(".bioPopup").animate({ opacity: 1.0 }, 200);	
	}

	// Bio - Click outside DIV
	var mouse_is_inside = false;
	
	$('.bioPopup').hover(function(){ 
		mouse_is_inside=true; 
	}, function(){ 
		mouse_is_inside=false; 
	});
  
	$("body").mouseup(function(){ 
		if(! mouse_is_inside) $('.athleteBio').removeClass("active");
	});

	// append scrollbar to all DOM nodes with class="css-scrollbar"
		$('.css-scrollbar').scrollbar();
		$('.fff').scrollbar();

	// toggles the classes for the currently clicked bio section
	// also shows and hides the corresponding content
		$('.bioSelector').delegate('.bioNav', 'click', function() {
			var listItem = $('.bioNav'),
				details = $('.bioDetails');

				if ($(this).hasClass('on')) {
					return;
				}

				listItem.toggleClass('on');
				details.toggleClass('hidden');

			return false;
		});

		// the bio content needs to be visible on page load
		// in order for the scroll.js function to work properly
		$('.athleteStatsBody').addClass('hidden');

		// check for amateurs team section in sub nav
		if($('#amateurs').length === 0) {
			$('#pros').css('width', '100%');
		}

});


(function($){
	$.fn.animatedTab = function(options){
		var opts = $.extend({}, $.fn.animatedTab.defaults, options);

		return this.each(function(){
			var widget = $(this),
				navContainer = widget.find('.nav'),
				tabs = widget.find('.grid'),
				tabContainer = widget.find('.tabContainer');
			
			navContainer.delegate('a', 'click', function() {
				var clickedItem = $(this),
					selectedTab = clickedItem.attr('href'),
					selectedTabPosition = $(selectedTab).position(),
					tabChunk = selectedTab.split('#'),
					newHeight = $('#' + tabChunk[1]).height();
					
				navContainer.find('.active').removeClass('active');
				clickedItem.addClass('active');
				
				tabContainer.animate({
				    left: '-' + selectedTabPosition.left
				  }, 400);

				tabContainer.parent('.body').animate({
					'height': newHeight
				});
				
				Cufon.refresh();
				return false;
			});
		});
	};

	$.fn.animatedTab.defaults = {
		// add tab selector, tabcontainer selector and nav selector
	};
	
})(jQuery);	

