function switch_popular_links_scope(scope) {
	if (scope == 'today') {
		$('links_today').show();
		$('links_past_week').hide();
		$('links_past_month').hide();
		
		$('popular_links_today').addClassName('selected');
		$('popular_links_past_week').removeClassName('selected');
		$('popular_links_past_month').removeClassName('selected');
	}
	else if (scope == 'past_week') {
		$('links_today').hide();
		$('links_past_week').show();
		$('links_past_month').hide();
		
		$('popular_links_today').removeClassName('selected');
		$('popular_links_past_week').addClassName('selected');
		$('popular_links_past_month').removeClassName('selected');
	}
	else if (scope == 'past_month') {
		$('links_today').hide();
		$('links_past_week').hide();
		$('links_past_month').show();
		
		$('popular_links_today').removeClassName('selected');
		$('popular_links_past_week').removeClassName('selected');
		$('popular_links_past_month').addClassName('selected');
	}
}

var clicks_timeout;

function show_traffic(link_id) {
	var view;
	if ($('traffic_tab_referrers').selected)
		view = 'referrers';
	else
		view = 'clicks';
	
	var scope = $F('traffic_scope');
	
	if (scope != 'now')
		clearTimeout(traffic_timeout);	
	
	new Req.ajax({
		url: '/ajax/link/view_'+view,
		options: {
			parameters: 'link_id='+link_id+'&scope='+$F('traffic_scope')
		}
	});
}

function view_clicks(link_id, scope) {
	if (scope != 'now')
		clearTimeout(clicks_timeout);
	
	$('clicks_tab_now').removeClassName('selected');	
	$('clicks_tab_past_week').removeClassName('selected');	
	$('clicks_tab_past_month').removeClassName('selected');	
	$('clicks_tab_total').removeClassName('selected');
		
	$('clicks_tab_'+scope).addClassName('selected');
	
	new Req.ajax({
		url: '/ajax/link/view_clicks',
		options: {
			parameters: 'link_id='+link_id+'&scope='+scope
		}
	});
}

function view_referrers(link_id, scope) {	
	$('referrers_tab_today').removeClassName('selected');	
	$('referrers_tab_past_week').removeClassName('selected');	
	$('referrers_tab_past_month').removeClassName('selected');	
	$('referrers_tab_total').removeClassName('selected');
		
	$('referrers_tab_'+scope).addClassName('selected');
	
	new Req.ajax({
		url: '/ajax/link/view_referrers',
		options: {
			parameters: 'link_id='+link_id+'&scope='+scope
		}
	});
}