//Function will equalize the heights of a group of elements
	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}


// Search form
var active_color = '#616161'; // Colour of user provided text
var inactive_color = '#CCC'; // Colour of default text
$("#searchform #s").css("color", inactive_color);
var default_values = new Array();
$("#searchform #s").focus(function() {
	if (!default_values[this.id]) {
	default_values[this.id] = this.value;
}
	if (this.value == default_values[this.id]) {
	this.value = '';
	this.style.color = active_color;
}
	$(this).blur(function() {
		if (this.value == '') {
		this.style.color = inactive_color;
		this.value = default_values[this.id];
		}
	});
});


// Most Recent & Tweets & Comments WIdget	

$('#Sidebar #MostPopular').hide();
$('#Sidebar .recent ul.twitter').hide();

$('.recent .popular-header a').click(function() {
	$('#Sidebar #RecentComments').hide();	
	$('#Sidebar .recent ul.twitter').hide();
	$('#Sidebar #MostPopular').show();
	$('.recent .comments-header a').removeClass('active');
	$('.recent .tweets-header a').removeClass('active');
	$(this).addClass('active');
	return false;
});
$('.recent .comments-header a').click(function() {
	$('#Sidebar #MostPopular').hide();	
	$('#Sidebar .recent ul.twitter').hide();
	$('#Sidebar #RecentComments').show();
	$('.recent .popular-header a').removeClass('active');
	$('.recent .tweets-header a').removeClass('active');
	$(this).addClass('active');
	return false;
});
$('.recent .tweets-header a').click(function() {
	$('#Sidebar #RecentComments').hide();	
	$('#Sidebar #MostPopular').hide();
	$('#Sidebar .recent ul.twitter').show();
	$('.recent .comments-header a').removeClass('active');
	$('.recent .popular-header a').removeClass('active');
	$(this).addClass('active');
	return false;
});

//Insert the "TwitterWidgetFollow" element after the list of tweets
$('#Sidebar .recent ul.twitter').append($('#TwitterWidgetFollow'));
$('#TwitterWidgetFollow').wrap('<li class="TwitterWidgetFollow" />');
$('#TwitterWidgetFollow').removeClass('hide').addClass('show');

//equalize the height
equalHeight($('#Sidebar .recent ul'));

// Nerds Widget
var nerds = $('#Sidebar .nerds div.nerd-info');
var nerdOptions;
var activeNerd = false;
	
//Get a Random "Nerd"
randomNerd = jQuery(nerds).get().sort(function(){ 
	return Math.round(Math.random())-0.5
}).slice(0,1);


$('#Sidebar .nerds div.nerd-info').removeClass('active').hide();

$.each(nerds, function(index) {
	if ($(this).attr('id') == pubCurrentAuthor) {
		$(this).addClass('active').fadeIn('fast');
		activeNerd = true;
	}
	nerdOptions += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
});

if(!activeNerd) {
	$(randomNerd).addClass('active').fadeIn('fast');
}

$('#nerdSelect').append(nerdOptions);
$('#Sidebar .nerds div.nerd-info').removeAttr('title');

$('#nerdSelect').change(function() {
	if ($(this).attr('value') == null || $(this).attr('value') == '') return false;
	if ($(this).attr('value') == $('#Sidebar .nerds div.nerd-info.active').attr('id')) return false;
	$('#' + $(this).attr('id') + ' .default').remove();
	$('#Sidebar .nerds div.nerd-info.active').removeClass('active').hide();
	$('#' + $(this).attr('value')).addClass('active').fadeIn('fast');			
});
