jQuery(document).ready(function($){

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	TABS ON THE PROGRAMME PAGE
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	
	// hide all the other panels
	$(".tabs_panel").not(".active").hide();
	
	// UPDATE: maybe we already have a hash in the URL?
	if(window.location.hash){
		var eHash = window.location.hash;
		
		// update the tabs
		$("#programme-tabs a.active").removeClass("active");
		$("#programme-tabs a[href='"+eHash+"']").addClass("active");
		
		// update the panels
		$(".tabs_panel.active").fadeOut(100, function(){
			$(this).removeClass('active');
			$(eHash).addClass('active').fadeIn(100);
		});
	}
	
	// handle the click
	$("#programme-tabs a").click(function(){
		// remove any actives on tab selectors
		$("#programme-tabs a.active").removeClass("active");
		$(this).addClass("active");
		
		// find the tab we should show
		var tabHash = $(this).attr('href');
		
		window.location.hash = tabHash;
		
		$(".tabs_panel.active").fadeOut(300, function(){
			$(this).removeClass('active');
			$(tabHash).addClass('active').fadeIn(300);
		});
		
		return false;
	});
});
