jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){
	
	
	var divContainerHeight = $("#page-wrap").height();
	divContainerHeight = divContainerHeight - 69 - 348 - 96;
	var divContentPadding = Math.round(divContainerHeight / 2);
	if (divContentPadding > 0) {
		$("#main-content").css("padding-top", divContentPadding);
	} else {
		$("#main-content").css("padding-top", 0);
	}
	
	//If the User resizes the window, adjust the #container height
	$(window).bind("resize", resizeWindow);
	function resizeWindow( e ) {
		divContainerHeight = $("#page-wrap").height();
		divContainerHeight = divContainerHeight - 69 - 348 - 96;
		var divContentPadding = Math.round(divContainerHeight / 2);
		if (divContentPadding > 0) {
			$("#main-content").css("padding-top", divContentPadding);
		} else {
			$("#main-content").css("padding-top", 0);
		}
	} 
	
	//Check what browser is being used.
	var browser=navigator.appName;
	
	//If not IE, use JQuery Blend
	if(browser != 'Microsoft Internet Explorer') {
	
		//partners logos (Jamie McMurray Foundation & Jamie McMurray Karting)
		$(".jmf_logo a").blend();
		$(".jmk_logo a").blend();
		
		//Social Media Links
		$(".twitter_btn a").blend();
		$(".facebook_btn a").blend();
		$(".rss_btn a").blend();
		
		//Header Menu Links
		$("#main-menu-profile a").blend();
		$("#main-menu-team a").blend();
		$("#main-menu-news a").blend();
		$("#main-menu-gallery a").blend();
		$("#main-menu-store a").blend();
			
	}
	
	var child;
	
	//$("#page-left-nav > div").children().each(function() {
	$("#page-left-nav").children().each(function() {
		child = $(this); 
		var elem = child.find("a");
		if(elem.attr("href") == window.location.pathname) {
			elem.addClass("hover");	
		} 
	});
	
	if (child == undefined) {
		if(browser != 'Microsoft Internet Explorer') $("#menu-bio a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-career a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-foundation a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-sm a").blend();
		if(browser != 'Microsoft Internet Explorer') $("#menu-team a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-schedule a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-results a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-sponsors a").blend();
		if(browser != 'Microsoft Internet Explorer') $("#menu-news-archive a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-news-links a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-photos a").blend();
		if(browser != 'Microsoft Internet Explorer')$("#menu-videos a").blend();
	} else {
		if(child.attr("id") != 'menu-bio' && browser != 'Microsoft Internet Explorer') $("#menu-bio a").blend();
		if(child.attr("id") != "menu-career" && browser != 'Microsoft Internet Explorer')$("#menu-career a").blend();
		if(child.attr("id") != "menu-foundation" && browser != 'Microsoft Internet Explorer')$("#menu-foundation a").blend();
		if(child.attr("id") != "menu-sm" && browser != 'Microsoft Internet Explorer')$("#menu-sm a").blend();
		if(child.attr("id") != 'menu-team' && browser != 'Microsoft Internet Explorer') $("#menu-team a").blend();
		if(child.attr("id") != "menu-schedule" && browser != 'Microsoft Internet Explorer')$("#menu-schedule a").blend();
		if(child.attr("id") != "menu-results" && browser != 'Microsoft Internet Explorer')$("#menu-results a").blend();
		if(child.attr("id") != "menu-sponsors" && browser != 'Microsoft Internet Explorer')$("#menu-sponsors a").blend();
		if(child.attr("id") != 'menu-news-archive' && browser != 'Microsoft Internet Explorer') $("#menu-news-archive a").blend();
		if(child.attr("id") != "menu-news-links" && browser != 'Microsoft Internet Explorer')$("#menu-news-links a").blend();
		if(child.attr("id") != "menu-photos" && browser != 'Microsoft Internet Explorer')$("#menu-photos a").blend();
		if(child.attr("id") != "menu-videos" && browser != 'Microsoft Internet Explorer')$("#menu-videos a").blend();
	}
		
	//Video Colorbox
	$(".jmvideo").colorbox({iframe:true, innerWidth:320, innerHeight:240});
	
	//Photo Colorbox
	$(".jmphoto").colorbox();

	//Schedule Toggle (Show/Hide extra content)
	$(".schedule_extra").hide();

	$("#item_more").toggle(function(){
		$(this).text("[-]");
		}, function () {
		$(this).text("[+]"); 
	});
	
	$(".schedule_container").click(function(){
		$(this).next(".schedule_extra").slideToggle("slow");
	});
	
	//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");
	});
	
	//EGR Slider from right
	$('#slider a').stop().animate({'marginLeft':'194px'},1000);

	$('#slider').hover(
		function(){
			$('a',$(this)).stop().animate({'marginLeft':'0px'},500);
		}, function(){
			$('a',$(this)).stop().animate({'marginLeft':'194px'},500);
		}
	);
	
	/**
	 * Rotates sponsors logos in bottom right corner of page
	 * Loops through sponsors for continuous flow
	 */
	
	var $sponsors = $('#sponsor-rotator'),
	    $rotator = $sponsors.find("ul"),
		$count = $rotator.find("li").size(),
		$pos = 0,
		$rotatorSize = 3;
	var $sponsorCount = $rotatorSize - Math.round(($count/$rotatorSize)%1*$rotatorSize);
	if(jQuery.browser.msie&&jQuery.browser.version.substr(0,3)=="6.0"){
	  $rotator.find("img").css('width','106px');
	}else{
		$rotator.find("li:lt("+($sponsorCount+1)+")").clone().appendTo($rotator);
	}
	var $step = function(){
	  if($pos==$count){ // rewind
		$pos = 0;
		$rotator.css("marginLeft", 0); }
	  $pos += 1;
	  $rotator.animate({marginLeft:(-$pos*136)+"px"}, 800, 'easeOutQuart', function(){
	      setTimeout($step, 2500);
	  });
	  
	}; setTimeout($step, 2500);
	
});


// ------------------ RSS Feed Reader --------------------//
var xmlhttp;

function showRSS(type)
  {
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
    {
    alert ("Your browser does not support XML HTTP Request");
    return;
    }
  if(type == "photos") {
  	var url="/getrss.php";
	divID = "twitter_photo_list";
  }
  else if(type == "news") {
  	var url="/jmnews.php";
	divID = "news_list";
  }
  url=url+"?sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }

function stateChanged()
  {
  if (xmlhttp.readyState==4)
    {
    document.getElementById(divID).innerHTML=xmlhttp.responseText;
    }
  }

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}  
