//Site.js
 
$(document).ready(function() {		

	
	//DOM events 
	$(".news_tabs li").click(function() {
		var tabID = $(this).attr("id");
		tabID = tabID.replace("_tab", "_feed");
		
		//Show right tab
		$(".news_feed").hide();
		$("#"+tabID).show();
		
		//Active class on tab
		$(".news_tabs li").removeClass("tab_active");
		$(this).addClass("tab_active");
	});
	
	
	//Setup a content array for the tooltips
	$(document).mousemove(function(e) {
		if($(".tooltip")) {
			$(".tooltip").css({
				"top":e.pageY + 10 + "px",
				"left": e.pageX + 10 + "px"
			});
		}
	});
	
	$(".athlete").hover(
		function() {
			$("#"+$(this).attr("data-tooltip")).show()
		},
		function() {
			$("#"+$(this).attr("data-tooltip")).hide()
		}
	);
	
	
});


/* reOrderTweets() 
*/
function reOrderTweets() {
	var months = ["Janruary", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	for (var x=0; x<months.length; x++) {
		$('<div class="month_wrap"><h3>'+months[x]+'</h3><ul id="'+months[x]+'"></ul></div>').appendTo('#twitter_events');
		testMonth(months[x]);
	}
	$("#twitter_update_list").remove(); //Remove standard twitter list
	$("#twitter_events ul").each(function() {
		if($(this).html()=="") $(this).parent(".month_wrap").remove();		  
	});
}

/* testMonth() 
 * @month = string
*/
function testMonth(month) {

	$("#twitter_update_list li").each(function() {
		var content = $(this).html();
		$(this).find("span").next("a").remove();
		if($(this).html().search(month) != -1)
		{
			$("#"+month).append("<li>"+content+"</li>");
		}
	});
	
}


