jQuery(document).ready(function(){ 
	
	//alert(window.location.pathname);
	var path_name = window.location.pathname;
	var path_array = path_name.split("/");
	var page_category = path_array[1];
	
	//Set the heights of the content background and fade
	var divContentHeight = $(".content-box-content").height();
	if(divContentHeight == null) {
		divContentHeight = $(".page-box-content").height();
	}
	if(page_category == "drivers") {
		divContentHeight = $("#bio_box").height() + 275;
	}
	var totalHeight = divContentHeight + 32;
	$("#content-box-middle").css("height", divContentHeight);
	$(".content-box-fade").css("height", totalHeight);
	
	//Check what browser is being used.
	var browser=navigator.appName;
	
	//If not IE, use JQuery Blend
	if(browser != 'Microsoft Internet Explorer') {
	
		//Sponsor Logos
		$(".sponsor-chevy a").blend();
		$(".sponsor-armorall a").blend();
		$(".sponsor-basspro a").blend();
		
		$(".partner-ts a").blend();
		$(".partner-tsf a").blend();
		$(".partner-shr a").blend();
		$(".partner-woo a").blend();
		$(".partner-usac a").blend();
			
	}
	
	//Set the heights of the drivers content area
	$("#bio_btn").click(function(){
		divContentHeight = $("#bio_box").height() + 275;
		totalHeight = divContentHeight + 32;
		$("#content-box-middle").css("height", divContentHeight);
		$(".content-box-fade").css("height", totalHeight);
	});
	
	$("#career_btn").click(function(){
		divContentHeight = $("#career_box").height() + 275;
		totalHeight = divContentHeight + 32;
		$("#content-box-middle").css("height", divContentHeight);
		$(".content-box-fade").css("height", totalHeight);
	});
	
	$("#photos_btn").click(function(){
		divContentHeight = $("#photos_box").height() + 275;
		totalHeight = divContentHeight + 32;
		$("#content-box-middle").css("height", divContentHeight);
		$(".content-box-fade").css("height", totalHeight);
	});
	
	$("#results_btn").click(function(){
		divContentHeight = $("#results_box").height() + 275;
		totalHeight = divContentHeight + 32;
		$("#content-box-middle").css("height", divContentHeight);
		$(".content-box-fade").css("height", totalHeight);
	});
	
	$("div.secondary_sponsor").vAlign();
	
	//Video Colorbox
	$(".tsrvideo").colorbox({iframe:true, innerWidth:600, innerHeight:400});
	
	
	//Photo Colorbox
	$("a[rel='tsrphoto']").colorbox();
	
	/**
	 * Tabs on Drivers Pages
	 */
	jQuery("ul.tabs").tabs("div.tabs_box > div");
	
	/**
	 * Rotates sponsors logos in bottom right corner of page
	 * Loops through sponsors for continuous flow
	 */
	$(".sponsor-rotator").jCarouselLite({
		auto: 2500,
		speed: 1500,
		easing: "backinout"
	});
	
	$("ul.video_thumbs").ytplaylist({addThumbs:false, autoPlay: false, holderId: 'main_video'});
	
	$(".side_videos").jCarouselLite({
		btnNext: ".arrow_down",
        btnPrev: ".arrow_up",
		vertical: true,
		speed: 1500,
		easing: "backinout"
	});
	
	//Results Toggle (Show/Hide extra content)
	$(".results_extra").hide();

	$("#results_more").toggle(function(){
		$(this).text("[-]"); 
		}, function () {
		$(this).text("[+]"); 
	});
	
	$(".results_container").click(function(){
		$(this).next(".results_extra").slideToggle("slow");
	});
	
});

(function ($) {
	$.fn.vAlign = function(container) {
		return this.each(function(i){
			if(container == null) {
				container = 'div';
			}
			$(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
			var el = $(this).children(container + ":first");
			var elh = $(el).height(); //new element height
			var ph = $(this).height(); //parent height
			var nh = (ph - elh) / 2; //new height to apply
			$(el).css('margin-top', nh);
		});
	};
})(jQuery);
