var $ = jQuery;
$.fn.setAllToMaxHeight = function(){
	return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
};

$(window).load(function(){
	
	if ($("button").length > 0){
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		
		if(is_chrome){
			$('button').addClass('normal');
		}
	};
	$('.stats .stats-details ul li').setAllToMaxHeight();
	$('.featured-partnerships .col').setAllToMaxHeight();
});
$(document).ready(function() {
	$('.coaches ul li:nth-child(3n+3), .coaches ul li:last-child').addClass('last-col');
	$('.coaches ul li:nth-child(1), .coaches ul li:nth-child(2), .coaches ul li:nth-child(3)').addClass('first-row');
});


$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'sliceUp', //Specify sets like: 'sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random, slideInRight, slideInLeft'
		slices:3,
		animSpeed:500, //Slide transition speed
		pauseTime:10000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //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:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:1, //Universal caption opacity
		beforeChange: function(){
			$('#slider').data('nivo:vars').stop = true; 
		},
		afterChange: function(){
		},
		slideshowEnd: function(){}, //Triggers after all slides have been shown
		lastSlide: function(){}, //Triggers when last slide is shown
		afterLoad: function(){
			$('.nivo-controlNav a[rel="0"]').text('Coaches');
			$('.nivo-controlNav a[rel="0"]').addClass('coaches');

			$('.nivo-controlNav a[rel="1"]').text('Athletes');
			$('.nivo-controlNav a[rel="1"]').addClass('athletes');

			$('.nivo-controlNav a[rel="2"]').text('Fans & the Media');
			$('.nivo-controlNav a[rel="2"]').addClass('fans');
			
			$('#slider').data('nivo:vars').stop = true;
			$('.slide-nav').show();

			$('.nivo-controlNav a').click(function() {
				//$('#slider').data('nivoslider').start();
				$('#slider').data('nivo:vars').stop = false;
			});
		} //Triggers when slider has loaded
	});
});

//testimonials - What coaches are saying
$(document).ready(function(){

	$('.saying li').hide().eq(0).addClass('hover').show();
	$('.coaches li').eq(0).addClass('hover');
	
	var interval;
	
	function interval_init() {
		interval = setInterval('showNextTestimonial()', 18000);
	}
	function interval_clear() {
		window.clearInterval(interval);
		$('.saying li').stop();
		$('.saying li').hide();
		$('.saying li').removeClass('hover');
	}

	interval_init();


	$(".coaches li a").click(function() {
		interval_clear();
		$(".coaches li.hover").removeClass('hover');
		$(this).parent('li').addClass('hover');
		var index = $(this).parent('li').prevAll().length;
		
		$('.saying li').eq(index).addClass('hover');
		$('.saying li.hover').fadeIn('slow');
		interval_init();

		return false;
	});

});
function showNextTestimonial() {
	$('.saying li').css('opacity','1');
	$('.saying li.hover').fadeOut('slow',function(){
		$('.saying li.hover').removeClass('hover');
		var sChildren = $(this).parent().children().length-1;
		var index = $(this).prevAll().length;
		var $curr = $(this);
		$curr = $curr.next();

		if (index==sChildren){
			$curr = $('.saying li:first');
			$('.coaches li').removeClass('hover');
			$('.coaches li').eq(0).addClass('hover');
		}
		else {
			$('.coaches li').removeClass('hover');
			$('.coaches li').eq(index+1).addClass('hover');
		}

		$curr.fadeIn('slow',function(){
			$(this).addClass('hover');
		});
	});
}
//Sports we support fancybox
$(document).ready(function(){
	$(".sports-support-list .see-example a").fancybox({
	});
});
//fancybox for Use the product home page
$(document).ready(function(){
	$(".slide-nav .use-the-product a").fancybox({
		'hideOnContentClick': true,
		'centerOnScroll': false,
	});
});
//fancybox for Use Krossover link
$(document).ready(function(){
	$(".box .last a").fancybox({
		'hideOnContentClick': true,
		'centerOnScroll': false,
	});
});

//fancybox for what We Index
$(document).ready(function(){
	$("a.whatWeIndex").fancybox({
		'hideOnContentClick': true,
		'centerOnScroll': false,
	});
});
/*
//use these for custimising the fansybox

'frameWidth':fWidth,
'frameHeight':fHeight,
'hideOnContentClick': false,
'overlayOpacity': .7,
'overlayColor': '#000',
'centerOnScroll': false
*/

